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:
- Predefined, built-in system variables (for example, APPDATA).
- System-wide variables defined in the System Properties dialog box.
- 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.
- 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.
- Variables defined in AUTOEXEC.NT, if a DOS program is run.
- 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 ALLUSERSPROFILE C:\ProgramData APPDATA C:\Users\username\AppData\Roaming CommonProgramFiles C:\Program Files\Common Files COMPUTERNAME computername ComSpec C:\WINDOWS\system32\cmd.exe HOMEDRIVE C: HOMEPATH \Users\username LOCALAPPDATA * c:\Users\username\AppData\Local LOGONSERVER (Varies) NUMBER_OF_PROCESSORS (Varies) OS Windows_NT Path C:\WINDOWS\system32;?C:\WINDOWS; C:\WINDOWS\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\, but this varies depending on the location of Windows PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF; .WSH;.MSC PROCESSOR_ARCHITECTURE (Varies) PROCESSOR_IDENTIFIER (Varies) PROCESSOR_LEVEL (Varies) PROCESSOR_REVISION (Varies) ProgramFiles C:\Program Files ProgramData * C:\ProgramData PROMPT $P$G PSModulePath * C:\Windows\system32\windowsPowerShell\v1.0\Modules\ PUBLIC * c:\Users\Public SESSIONNAME (Varies) 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.
In this tutorial:
- The CMD Command-Line
- CMD Versus COMMAND
- Running CMD
- Opening a Command Prompt Window with Administrator Privileges
- CMD Options
- Disabling Command Extensions
- Command-Line Processing
- Console Program Input and Output
- Using the Console Window
- I/O Redirection and Pipes
- Copy and Paste in Command Prompt Windows
- Command Editing and the History List
- Name Completion
- Enabling Directory Name Completion
- Multiple Commands on One Line
- Grouping Commands with Parentheses
- Arguments, Commas, and Quotes
- Escaping Special Characters
- Configuring the CMD Program
- The Search Path
- Changing the Path
- Predefined and Virtual Environment Variables
- Setting Default Environment Variables
- Built-in Commands
- Extended Commands
- Listing Files with the Dir Command
- Paginating Long Listings
- Printing Directory Listings
- Sorting Listings
- Locating Alternate File Streams
- Setting Variables with the Set Command
- Conditional Processing with the if Command
- Scanning for Files with the for Command
- Using the for Command's Variable
- Processing Directories
- Numerical for Loop
- Getting More Information