Q:

C# program to get the environment variables using Environment class

belongs to collection: C# Environment Class Programs

0

Syntax:

IDictionary Environment.GetEnvironmentVariables();

Parameter(s):

This method returns the object of IDictionary class.

Return value:

This method returns an array of strings that contains the name of logical drives of the computer system.

To use IDictionary class we need to include System.Collections namespace.

Exception(s):

  • System.Security.SecurityException
  • System.OutOfMemoryException
  •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to get the environment variables using Environment class is given below. The given program is compiled and executed successfully.

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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Environment Class Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to get the Operating System version of ... >>
<< C# program to get the logical drives of computer s...