Appendix D. List of Default Environment Variables

Environment variables are useful when working with the CMD shell or when automating tasks. To use an environment variable, enclose the variable name with percent signs (%). For example, this command prints the SystemRoot environment variable:

> echo %systemroot%

You can generally use environment variables with most commands. This makes them very useful in batch scripts. This command changes the working directory to the system32 directory:

> cd %systemroot%\system32

For more on environment variables, see Recipe 2.11.

The following are the default environment variables available with Windows 2000 and Windows Server 2003:


The path to the All Users Profile.

Example: C:\Documents and Settings\All Users\Desktop


User-specific path where applications store data by default.

Example: C:\Documents and Settings\Administrator\Application Data


Current working directory.

Example: C:\


The path to the CMD executable.

Example: C:\WINDOWS\system32\cmd.exe


The version number of the Command Processor Extensions.

Example: 2


The name of the computer.

Example: SRV01


The path to the CMD executable.

Example: C:\WINDOWS\system32\cmd.exe


The current date.

Example: Fri 01/16/2004


The error code returned from the most recently used command. A value other than 0 indicates an error condition.

Example: 0


The drive where the currently logged on user's home directory is located.

Example: C:


Get Windows Server Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.