GetEnvironmentVariables Method
Collapse the table of content
Expand the table of content

Environment.GetEnvironmentVariables Method ()

 

Retrieves all environment variable names and their values from the current process.

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

public static IDictionary GetEnvironmentVariables()

Return Value

Type: System.Collections.IDictionary

A dictionary that contains all environment variable names and their values; otherwise, an empty dictionary if no environment variables are found.

Exception Condition
SecurityException

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

OutOfMemoryException

The buffer is out of memory.

The names and values for the environment variables are stored as key-value pairs in the returned IDictionary.

The following example demonstrates the GetEnvironmentVariables method.

// Sample for the Environment.GetEnvironmentVariables method
using System;
using System.Collections;

class Sample 
{
    public static void Main() 
    {
       Console.WriteLine();
       Console.WriteLine("GetEnvironmentVariables: ");
       foreach (DictionaryEntry de in Environment.GetEnvironmentVariables()) 
           Console.WriteLine("  {0} = {1}", de.Key, de.Value);
    }
}
// Output from the example is not shown, since it is:
//    Lengthy.
//    Specific to the machine on which the example is run.
//    May reveal information that should remain secure.

EnvironmentPermission

for the ability to read the names and values of environment variables. Associated enumeration: EnvironmentPermissionAccess.Read

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft