Windows 7 / Getting Started

Predefined and Virtual Environment Variables

Environment variables can be set in any of six places. If a given variable name is set in more than one place, the last definition is used.The sources are processed in the following order:

  1. Predefined, built-in system variables (for example, APPDATA).
  2. System-wide variables defined in the System Properties dialog box.
  3. User-specific variables defined in the System Properties dialog box (as mentioned in the previous section). However, a user-specific PATH definition does not replace the system-wide definition. Instead, it's added to the end of whatever is in the system PATH definition.Windows does this so that you can easily add more directories to the PATH for your own account without any risk of messing up the required system-wide PATH directories.
  4. Variables defined in logon scripts (batch or WSH-type).
    These first four sources are processed when a user logs on, and they form the user's default environment; the remaining sources are processed each time a new CMD process is started, and any changes are lost when CMD is closed.
  5. Variables defined in AUTOEXEC.NT, if a DOS program is run.
  6. Variables defined on the command line, in batch files, or in WSH scripts through WshShell.Environment("Process").

The following variables are defined by default for all users (systemwide):

Variable Name		Usual Value on Windows 7
APPDATA 		C:\Users\username\AppData\Roaming
CommonProgramFiles 	C:\Program Files\Common Files
COMPUTERNAME 		computername
ComSpec 		C:\WINDOWS\system32\cmd.exe
HOMEPATH 		\Users\username
LOCALAPPDATA * 		c:\Users\username\AppData\Local
OS 			Windows_NT
Path 			C:\WINDOWS\system32;?C:\WINDOWS;
                        but this varies depending on the location
                        of Windows
ProgramFiles 		C:\Program Files
ProgramData * 		C:\ProgramData
PSModulePath * 	C:\Windows\system32\windowsPowerShell\v1.0\Modules\
PUBLIC * 		c:\Users\Public
SystemDrive 		C:
SystemRoot 		C:\WINDOWS
TEMP 			C:\Users\username\AppData\Local\Temp
TMP 			C:\Users\username\AppData\Local\Temp
USERDOMAIN 		computername or domainname
USERNAME 		username
USERPROFILE 		C:\Documents and Settings\username
windir 			C:\WINDOWS

Entries marked with an asterisk (*) are not defined by default on Windows XP.

In addition, when command extensions are enabled, several "virtual" environment variables are available.The following environment variable names are computed dynamically if used on a command line or in a batch file:

Name 		Value
CD 		The current directory drive and path
DATE 		The current date, formatted as by the DATE command
TIME 		The current time, formatted as by TIME command
RANDOM 		A random number between 0 and 32,767
ERRORLEVEL 	The exit status of the previous program
CMDEXTVERSION 	The version number of command extensions
CMDCMDLINE 	The command line used to start CMD itself

However, if you define a variable with one of these names, your defined value always supercedes the dynamic value.

The maximum size for an individual environment variable (name, equals sign, and value) is 8,192 bytes.The total size of all environment variables must be smaller than 65,536KB.

[Previous] [Contents] [Next]