Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Environment.GetEnvironmentVariables Method

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

Namespace:  System
Assemblies:   mscorlib (in mscorlib.dll)
  System.Runtime.Extensions (in System.Runtime.Extensions.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.


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


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("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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

© 2015 Microsoft