Environment::GetEnvironmentVariables Method ()
.NET Framework (current version)
Retrieves all environment variable names and their values from the current process.
Assembly: mscorlib (in mscorlib.dll)
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.
using namespace System; using namespace System::Collections; int main() { Console::WriteLine( "GetEnvironmentVariables: " ); for each (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
Available since 10
.NET Framework
Available since 1.1
Show: