This example calls various static methods contained in the MyServices namespace. For this code to compile, a reference to Microsoft.VisualBasic.DLL must be added to the project.
using System;
using Microsoft.VisualBasic.Devices;
class TestMyServices
{
static void Main()
{
// Play a sound with the Audio class:
Audio myAudio = new Audio();
Console.WriteLine("Playing sound...");
myAudio.Play(@"c:\WINDOWS\Media\chimes.wav");
// Display time information with the Clock class:
Clock myClock = new Clock();
Console.Write("Current day of the week: ");
Console.WriteLine(myClock.LocalTime.DayOfWeek);
Console.Write("Current date and time: ");
Console.WriteLine(myClock.LocalTime);
// Display machine information with the Computer class:
Computer myComputer = new Computer();
Console.WriteLine("Computer name: " + myComputer.Name);
if (myComputer.Network.IsAvailable)
{
Console.WriteLine("Computer is connected to network.");
}
else
{
Console.WriteLine("Computer is not connected to network.");
}
}
}
Not all the classes in the MyServices namespace can be called from a C# application: for example, the FileSystemProxy class is not compatible. In this particular case, the static methods that are part of FileSystem, which are also contained in VisualBasic.dll, can be used instead. For example, here is how to use one such method to duplicate a directory:
// Duplicate a directory
Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(
@"C:\original_directory",
@"C:\copy_of_original_directory");