C# Program to Get the Environment Variables Using Environment Class

You are currently viewing C# Program to Get the Environment Variables Using Environment Class

C# program to get the environment variables using Environment class

using System;
using System.Collections;

class Sample
{
    //Entry point of Program
    static public void Main()
    {
        IDictionary evVars = Environment.GetEnvironmentVariables();
        foreach (DictionaryEntry eVar in evVars)
        {
            Console.WriteLine("{0}:{1}", eVar.Key, eVar.Value);
        }
    }
}

Output

Path:C:\Program Files\Dell\DW WLAN Card;;;C:\Windows\system32;C:\Windows;C:\Wind
ows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\M
icrosoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DT
S\Binn\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\Skype\Phon
e\
TEMP:C:\Users\Arvind\AppData\Local\Temp
SESSIONNAME:Console
PATHEXT:.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PSModulePath:C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
USERDOMAIN:Arvind-PC
PROCESSOR_ARCHITECTURE:x86
SystemDrive:C:
VS100COMNTOOLS:C:\Program Files\Microsoft Visual Studio 10.0\Common7\Tools\
APPDATA:C:\Users\Arvind\AppData\Roaming
windir:C:\Windows
LOCALAPPDATA:C:\Users\Arvind\AppData\Local
TMP:C:\Users\Arvind\AppData\Local\Temp
USERPROFILE:C:\Users\Arvind
ProgramFiles:C:\Program Files
FP_NO_HOST_CHECK:NO
HOMEPATH:\Users\Arvind
COMPUTERNAME:ARVIND-PC
USERNAME:Arvind
NUMBER_OF_PROCESSORS:4
PROCESSOR_IDENTIFIER:x86 Family 6 Model 42 Stepping 7, GenuineIntel
VBOX_INSTALL_PATH:C:\Program Files\Oracle\VirtualBox\
SystemRoot:C:\Windows
ComSpec:C:\Windows\system32\cmd.exe
LOGONSERVER:\\ARVIND-PC
VisualStudioDir:C:\Users\Arvind\Documents\Visual Studio 2010
CommonProgramFiles:C:\Program Files\Common Files
PROCESSOR_LEVEL:6
PROCESSOR_REVISION:2a07
PROMPT:$P$G
ALLUSERSPROFILE:C:\ProgramData
PUBLIC:C:\Users\Public
ProgramData:C:\ProgramData
OS:Windows_NT
HOMEDRIVE:C:
Press any key to continue . . .

Ranjith Kumar

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply