Environment Variables in PATH Not Expanded for non-Admin Command Prompt?

I have a Windows 7 machine which, when Command Prompt is run by a normal user, fails to expand environment variables in the %PATH%. If command prompt is instead run as administrator (right click, Run as administrator) then %PATH% is appropriately expanded.

Specifically, %PATH% for cmd.exe run as the user (displayed via set path) is as follows:

Path=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Wbem;%SYSTEMROOT\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft Windows Performance Toolkit\

...whereas %PATH% for cmd.exe run as Administrator is as follows:

Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\Wbem;%SYSTEMROOT\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft Windows Performance Toolkit\

I tried logging in as a new user to create a new profile, and the issue persists on that profile as well. HKEY_CURRENT_USER\Environment\PATH does not exist, and HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\Path matches the defined system-wide path in Computer Properties -> Environment Variables.

Does anyone have any ideas of what this might be, or where I can look?


Solution 1:

Two things I might try.

  1. Run an sfc /scannow to see if that fixes any larger issues at play.
  2. Check the registry for the Path key in HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment. What's the type. It should say REG_EXPAND_SZ

Solution 2:

I had a very similar problem - the simple solution was to add a semi-colon after the alias in the path definition.

Long story:

I'm using node.js so have a NODE_HOME alias defined via a user environment variable. I then append this alias to my PATH environment variable.

What I find is that after a re-boot, the shell has lost the path to NODE_HOME so npm etc. won't work. What's going on?

On inspection, I see that NODE_HOME is set, but that it has magically acquired a semi-colon.

C:\Users\ob>echo %NODE_HOME%
C:\Users\ob\node-8.11.1;

PATH now ends in the literal string %NODE_HOME% instead of the expanded path to the node folder:

C:\Users\ob>echo %PATH%
C:\Program...rams\Git\cmd;%NODE_HOME%

To fix it:

First, delete the errant semi-colon from the end of the definition of NODE_HOME.

Second, add a semi-colon after the NODE_HOME symbol in the definition of PATH:

C:\Program...rams\Git\cmd;%NODE_HOME%;

Now when I start a new shell and expand PATH, it finds NODE_HOME:

C:\Users\ob>echo %PATH%
C:\Program...ams\Git\cmd;C:\Users\tkobo\Installations\node-8.11.1;

And npm works again!