Get Acquainted with the Environment Class

G e t A c q u a i n t e d w i t h t h e E n v i r o n m e n t C l a s s

By Michael McIntyre

mikemc@getdotnetcode.com

Get Acquainted with the Environment Class

The System.Environment class “provides information about, and means to manipulate, the current environment and platform.” This article introduces the Evironment class and through code snippets demonstrates some of its properties and methods including NetBios computer name, OS version, user domain name, CLR version, and path to special folder.

’ Environment.MachineName

Console.WriteLine("Environment.MachineName (NetBios) : " & Environment.MachineName)

Result: Environment.MachineName (NetBios) : AZ1

’ Environment.OSVersion

Console.WriteLine("Environment.OSVersion (Windows) : " & Environment.OSVersion.ToString)

Result: Environment.OSVersion (Windows) : Microsoft Windows NT 5.1.2600.0

’ Environment.UserDomainName

Console.WriteLine("Environment.UserDomainName : " & Environment.UserDomainName)

Result: Environment.UserDomainName : AZ1

’ Environment.Version

Console.WriteLine("Environment.Version (CLR) : " & Environment.Version.ToString)

Result: Environment.Version (CLR) : 1.0.3705.288

’ Environment.GetFolderPath

Console.WriteLine("Environment.GetFolderPath : " & Environment.GetFolderPath(Environment.SpecialFolder.Favorites))

Result: Environment.GetFolderPath : C:\Documents and Settings\Mike McIntyre\Favorites

This class can also be used to retrieve the following information:

Command line arguments
Exit codes
Contents of the call stack
Time since last system boot
Stack Trace

To learn more about the Environment class click here -> Environment Class