System.Environment.GetEnvironmentVariable Method

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

Syntax

public static string GetEnvironmentVariable (string variable)

Parameters

variable
The name of the environment variable.

Returns

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

Exceptions

TypeReason
ArgumentNullException variable is a null reference.
System.Security.SecurityExceptionThe caller does not have the required permission.

Remarks

Environment variable names are not case-sensitive.

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

Permissions

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0