System.Environment.GetEnvironmentVariable Method

Retrieves the value of an environment variable from the current process or from the Windows operating system registry key for the current user or local machine.

Syntax

public static string GetEnvironmentVariable (string variable, EnvironmentVariableTarget target)

Parameters

variable
The name of an environment variable.
target
One of the EnvironmentVariableTarget values.

Returns

The value of the environment variable specified by the variable and target parameters, or null if the environment variable is not found.

Remarks

The target parameter specifies whether the environment variable is retrieved from the current process or from the Windows operating system registry key for the current user or local machine.

Environment variable names are not case-sensitive.

To retrieve all environment variables along with their values, call the Environment.GetEnvironmentVariables method.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0