https://winsourcecode.blogspot.com/2019/05/listenvironmentexe-list-system-user.html is a program that lists System, User, and Volatile variables, and the resulting process environment variables. It also lists the Dynamic variables detailed in help.
--------
System
--------
ComSpec=%SystemRoot%\system32\cmd.exe
DriverData=C:\Windows\System32\Drivers\DriverData
Link=/pdb:none /MAPINFO:LINES
NUMBER_OF_PROCESSORS=4
Etc
--------
Volatile - These are set at logon
--------
LOGONSERVER=\\DESKTOP-UCDGI39
USERDOMAIN=DESKTOP-UCDGI39
HOMEDRIVE=C:
USERDOMAIN_ROAMINGPROFILE=DESKTOP-UCDGI39
Etc
--------
User - These override system variables, and in the case of PATH are added to the system PATH
--------
MSDevDir=C:\Program Files (x86)\Microsoft Visual Studio\Common\MSDev98
Etc
--------
Process - This is the combined environment from the above for the program
Variables starting with an equals sign, such as =C:=C:\Windows are internal CMD variables
CMD simulates a default directory per drive like MSDos. This is how it keeps track
--------
=C:=C:\Windows\System32
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=DESKTOP-UCDGI39
ComSpec=C:\WINDOWS\system32\cmd.exe
DriverData=C:\Windows\System32\Drivers\DriverData
HOMEDRIVE=C:
HOMEPATH=\Users\David Candy
Etc
--------
Dynamic - These are updated each time they are used
--------
CD
DATE
TIME
RANDOM
ERRORLEVEL
CMDEXTVERSION
CMDCMDLINE
HIGHESTNUMANODENUMBER
Environment variables are created at logon and passed to the shell Explorer.exe. From now on they are only in memory. Any program Explorer starts, incl cmd.exe gets a copy of explorer's environment memory. If you start a program from cmd.exe it gets a copy of CMD's environment memory. Programs cannot access other program's memory so it is ONLY one way. If a program changes a variable only that program can see, or programs that it starts after changing it. The program's memory block is thrown away when the program exits.
SetX notifies all programs if the environment is changed. However the ONLY well known program that listens for this is Explorer.exe. CMD does not listen for this message. See https://learn.microsoft.com/en-us/windows/desktop/winmsg/wm-settingchange for how it does this. So after using SetX or your program sending the message, new programs, incl CMD.exe, started by Explorer will have the changes. Existing programs won't. Existing will start other programs with a copy of their now old environment block.
A common question is how to run setx
and also have it take effect immediately. The answer is you can't. So you run Setx
for the future and Set
for the current CMD.exe instance.