This documentation is archived and is not being maintained.

Environment.GetEnvironmentVariable Method (String)

Retrieves the value of an environment variable from the current process.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

'Declaration
Public Shared Function GetEnvironmentVariable ( _
	variable As String _
) As String
'Usage
Dim variable As String
Dim returnValue As String

returnValue = Environment.GetEnvironmentVariable(variable)
public static String GetEnvironmentVariable (
	String variable
)
public static function GetEnvironmentVariable (
	variable : String
) : String

Parameters

variable

The name of the environment variable.

Return Value

The value of the environment variable specified by variable, or a null reference (Nothing in Visual Basic) if the environment variable is not found.

Exception typeCondition

ArgumentNullException

variable is a null reference (Nothing in Visual Basic).

SecurityException

The caller does not have the required permission to perform this operation.

Environment variable names are not case-sensitive.

The following code example demonstrates the GetEnvironmentVariable method.

' Change the directory to %WINDIR%                            
Environment.CurrentDirectory = Environment.GetEnvironmentVariable("windir")
Dim info As New DirectoryInfo(".")
Console.WriteLine(("Directory Info:   " + info.FullName))        

// Change the directory to %WINDIR%                            
Environment.set_CurrentDirectory(Environment.GetEnvironmentVariable(
    "windir"));

DirectoryInfo info = new DirectoryInfo(".");

synchronized(info) {
    Console.WriteLine(("Directory Info:   " + info.get_FullName()));
}

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Show: