Windows Environment Variables - Windows CMD
Windows Environment Variables - Windows CMD
Array variables
Unlike PowerShell, which fully supports arrays, there is no built in support for array variables within the CMD shell.
However with some effort you can replicate this functionality using a series of separate variables, named to represent
the array:
To perform array indexing operations with these, use EnableDelayedExpansion and a reference like !elem[%var%]!
this is explained fully in this StackOverflow Q/A.
C:\ProgramData
ALLUSERSPROFILE Y
Predefined machine-wide system varia
APPDATA Y Y C:\Users\{username}\AppData\Roami
Y
HighestNumaNodeNumber Y The highest NUMA node number on th
(hidden)
HOMEDRIVE Y Y C:
HOMEPATH Y Y \Users\{username}
HOMESHARE Y Network home folder.
LOCALAPPDATA Y Y C:\Users\{username}\AppData\Local
LOGONSERVER Y Y \\{domain_logon_server}
C:\Windows\System32\;C:\Windows\
PATH Y Y
program paths}
ProgramData Y C:\ProgramData
ProgramFiles Y C:\Program Files or C:\Program Files (
PSModulePath Y %SystemRoot%\system32\WindowsP
Public Y C:\Users\Public
C:\Users\{Username}\AppData\Local\
TEMP and TMP Y Y
Under XP this was \{username}\Local
%SystemDrive%\Users\{username}
USERPROFILE Y Y
This is equivalent to the $HOME enviro
By default, files stored under Local Settings do not roam with a roaming profile.
Dynamic environment variables are computed each time the variable is expanded, this makes them inherently read-
only.
When all variables are listed with SET, these will not appear in the list.
Precedence
When a new process is started, the variables will be loaded in the following order:
After the process has started, additional shell variables can be defined with SET, these will be available only to the
current CMD shell session, but they will take precedence over any environment variables with the same name.
For example, if the SET command is used to modify the PATH, or if it is removed completely with PATH ; that will
affect the current process, but not any other programs or CMD sessions opened before or after the current one.
This precedence is important to understand because if you try to set a System Environment variable PATH =
%APPDATA%;C:\Windows, it will fail because the %APPDATA% Shell variable is not created until after the System
environment variables are imported to the session.
However, you can use %APPDATA% to build a User environment variable PATH.
Running the SET command with no options will display all Shell variables plus all User and System Environment
variables, in other words every variable available to be read by that session. In PowerShell the same list is available via
the env: drive
It is impossible to use SET to define or alter these variables because SET does not allow '=' in a variable name.
More detail on these undocumented variables can be found in this stackoverflow answer from Dave Benham.
A child process by default inherits a copy of all environment variables from its parent, this makes environment
variables unsuitable for storing secret information such as API keys or user passwords, especially in rare occasions
like crashes where a crash log will often include the full OS environment at the time of the crash. PowerShell/Get-
Credential is a more secure approach.
If Command Extensions are disabled, the following dynamic variables will be not accessible:
%CD% %DATE% %TIME% %RANDOM% %ERRORLEVEL% %CMDEXTVERSION% %CMDCMDLINE%
%HIGHESTNUMANODENUMBER%
“Men may be convinced, but they cannot be pleased against their will. But though taste is obstinate, it is very
variable, and time often prevails when arguments have failed” ~ Samuel Johnson
Related commands: