Global vs User Windows Environment Variables

I need to understand how Global vs User variables works in windows.

Case 1: If the same variable is defined at user and global section what is the behaviour? E.g. I have defined a %PATH% variable either in user and global sections and I see only global value; is there a way to 'append" user PATH to global PATH?

Case 2: The variables defined in user section are not 'resolved' in global section. If I use SET command I see a list of all defined variables (user and global) but 'cross references' are not resolved.

E.g.

in user section I define:

VAR1=test-user 

in global section I define:

VAR2=%VAR1%-more;%VAR3%-more
VAR3=test-global 

with SET I see:

...
VAR1=test-user
VAR2=%VAR1%-more;test-global-more
VAR3=test-global
...

I'm on a Windows 7 x64 box.

So, based on the tests above, my conclusions are:

  • global variables override user variables (if the name is the same only global is valid)
  • no cross reference is admitted between user and global variables

Am I right?


Solution 1:

Your conclusions aren't quite right, at least according to my testing.

  • User variables can reference system (global) ones.

    System variables cannot reference user variables.

  • User variables will override system (global) ones.

    Just in the default set, TEMP (and TMP) are defined as the user variable as %USERPROFILE%\AppData\Local\Temp and at the same time as the system variable as C:\Windows\TEMP.

    PATH appears to be a special case, where the user variable PATH (if defined) is always appended to the system variable rather than overriding it.