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:

ALLUSERSPROFILE

The path to the All Users Profile.

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

APPDATA

User-specific path where applications store data by default.

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

CD

Current working directory.

Example: C:\

CMDCMDLINE

The path to the CMD executable.

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

CMDEXTVERSION

The version number of the Command Processor Extensions.

Example: 2

COMPUTERNAME

The name of the computer.

Example: SRV01

COMSPEC

The path to the CMD executable.

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

DATE

The current date.

Example: Fri 01/16/2004

ERRORLEVEL

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

Example: 0

HOMEDRIVE

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

Example: C:

HOMEPATH ...

Get Windows Server Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.