setx.exe
is a program that sets user/system environment variables in the registry, which is used for future process creation. set
is a command that shows the process environment variables in the environment in the parameter block in the PEB of the current process (which show the user /and system variables inherited directly from the registry, and theas well as variables defined by (usingthe current or parent processes using set
) and inherited from the parent), as well as allowing more variables to be defined in it by the current process, and the changes to the environment can be viewed from process explorer.
cmd /c set variable=value
will set variables for the child process cmd.exe
that it creates (which attaches itself to the parent cmd.exe
console window and does not allocate its own, and inherits the parent's environment as well as the environment variables in the registry) so it won't take effect when you perform set
after that from within the same window, because it be referring to the parent process cmd.exe
. Top level processes inherit their environment directly from the registry and explorer.exe
dynamically updates its environment variables (unlike most other apps), so when you setx
it won't even update the current process environment, only the registry, which is either read by explorer.exe
, or the explorer.exe
process is updated by the windows API function that sets the environment variable (less likely), such that future opened cmd.exe
s inherit explorer.exe
's environment, as they are children.