Network Administration: Windows Environment Variables

The Windows command shell makes several environment variables available to commands. Environment variables all begin and end with percent signs. You can use an environment variable anywhere in a command. For example,

C:>echo %OS% running on a %PROCESSOR_IDENTIFIER%

displays a line such as this:

Windows_NT running on an x86 Family 15 Model 2 Stepping 8, GenuineIntel

Interestingly, Windows NT, Windows 2000 Server, Windows Server 2003, and Windows Server 2008 all display “Windows_NT” for the operating system name.

If the environment variable represents a path, you may need to enclose it in quotation marks, like this:

C:>dir "%HOMEPATH%"

This command displays the contents of the user’s home directory. The quotation marks are required here because the environment variable expands to a pathname that may include spaces, and the command shell requires that long filenames that include spaces must be enclosed in quotation marks.

The environment variables that are available to you and your commands are listed.

Environment Variables
Variable Description
%ALLUSERSPROFILE% The location of the All Users profile
%APPDATA% The path where applications store data by default
%CD% The path to the current directory
%CMDCMDLINE% The command line that was used to start the command shell
%CMDEXTVERSION% The version number of the command shell
%COMPUTERNAME% The computer’s name
%COMSPEC% The path to the command shell executable (cmd.exe)
%DATE% The current date in the format generated by the date /t
%ERRORLEVEL% The error returned by the most recent command
%HOMEDRIVE% The drive letter of the user’s home directory
%HOMEPATH% The path to the user’s home directory
%HOMESHARE% The network path to the user’s shared home directory
%LOGONSERVER% The name of the domain controller the user logged on to
%NUMBER_OF_PROCESSORS% The number of processors on the computer
%OS% The name of the operating system
%PATH% The current search path
“%PATHEXT%” A list of the extensions the operating system treats as
executable files
%PROCESSOR_ARCHITECTURE% The chip architecture of the processor
%PROCESSOR_IDENTIFIER% A description of the processor
%PROCESSOR_REVISION% The revision level of the processor
%PROMPT% The current prompt string
%RANDOM% A random number between 1 and 32,767
%SYSTEMDRIVE% The drive containing the operating system
%SYSTEMROOT% The path to the operating system
%TEMP% The path to a temporary folder for temporary files
%TMP% Same as %TEMP%
%TIME% The time in the format produced by the time /t
%USERDOMAIN% The name of the user’s domain
%USERNAME% The user’s account name
%USERPROFILE% The path to the user’s profile
%WINDIR% The path to the operating system directory