Jump to content
Sign in to follow this  
CyberAbc

What Are Environment Variables?

Recommended Posts

What Are Environment Variables?

Environment Variables are stored in a small area of memory available to all programs running within or on top of the DOS environment (including Windows). They are called “variables” because they can be changed. In fact, some variables need to be reestablished after every reboot.

  • Variable names are NOT case sensitive within Windows.

 

 

Windows System Environment Variables

These system environment variables are automatically created by Windows upon boot-up in Windows Registry key HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Control\ Session Manager\ Environment

Variable

Sample Typical Value

%SystemDrive%

C:

%SystemRoot%

C:\WINDOWS

C:\WINNT

%WinDir%

C:\WINDOWS

C:\WINNT

%SystemDirectory%

C:\WINDOWS\System32

C:\WINNT\System32

%ComSpec%

C:\WINDOWS\system32\cmd.exe

The path including the command interpreter program.

%programfiles%

C:\WINDOWS\Program Files

%Temp%

C:\Users\W\AppData\Local\Temp on Windows Vista & 2008

C:\DOCUME~1\Usr\LOCALS~1\Temp (compressed form of)

C:\Documents and Settings\Usr\Local Settings\Temp

%Tmp%

%HOMEDRIVE%

C: The drive letter associated with the user's home directory

%HOMEPATH%

The path to the user's home directory as defined in UMD/AD (excluding drive):

\Users\<USERNAME> on Windows Vista & 2008

\Documents and Settings\Guest on Windows XP

%OS%

Windows_NT (even on Windows Vista & XP machines

The operating system the user is running

%USERDOMAIN%

The name of the domain that contains the user's account. On a stand-alone machine, the same as the machine name.

%USERNAME%

The user's name

%USERPROFILE%

C:\Users\<USERNAME> — The user's root folder

%USERPROFILE%\Desktop

The user's desktop folder

Windows resolves commands typed in the start/run box first from files in %SYSTEMDRIVE%, then files in %SYSTEMROOT%. This is regardless of the systemdrive (such as E:) being later in the path. This means that a rogue file can be invoked instead of a good file (such as cmd.exe) if it's in the %SYSTEMDRIVE%.

Below are dynamic environment variables:

 

Variable

Sample Typical Value

%CD%

The current directory.

%DATE%

Current date in the format set by the Date command

%TIME%

Current time in the format set by the Time command

%ERRORLEVEL%

A number defining exit status of a previous command or called executable.

%RANDOM%

A random number between 0 and 32767.

  • Like 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×