June 15, 2002

Retrieving special system paths

The GetFolderPath method of the Environment class lets you retrieve the path of several important system directories. For example, here’s how you determine the path of the Desktop directory for the current user: Console.WriteLine(Environment.GetFolderPath _ (Environment.SpecialFolder.DesktopDirectory))’ displays C:Documents and SettingsAdministratorDesktop Here’s a list of other useful constants you can pass

Retrieve Windows and System directories

In VB.NET you don’t need to call the GetWindowsDirectory and GetSystemDirectory API functions to retrieve the path the Windows and System directories. Retrieving the System directory is as simple as calling the Environment.SystemDirectory property: Dim sysDir As String = Environment.SystemDirectory() The Environment class doesn’t expose any property that returns the

Retrieve information about the current user

You can easily retrieve information about the current user by means of a few properties of the Environment class. The Environment.UserName returns the name of the user; the Environment.UserInteractive property returns True if the user is an interactive user; the UserDomainName returns the user’s domain name: Console.WriteLine(“UserName: {0}”, Environment.UserName)Console.WriteLine(“User is

Determine the Windows version

You don’t need to call any Windows API function in VB.NET to determine which version of Windows your application is running on, because this information is exposed by the Environment.OSVersion property. For example, if you run this code under Windows 2000: Console.WriteLine(Environment.OSVersion.ToString) then this is what appears in the console

Determine type and number of CPUs

There is no method call that directly retuns information about the number and type of installed CPU(s). However, this information is stored in a few environment variables, so it’s just a matter of extracting it with the Environment.GetEnvironmentVariable method: ‘ this code is meant to run under Windows NT, 2000,