nuxx.net

Shell Variables Not Expanding in %PATH% on Windows 7 Non-Administrator Command Prompt

I recently ran into an interesting issue on Windows 7. Users running a non-Administrative Command Prompt on Windows 7 would find that Windows’ programs which are supposed to be in their %PATH% (eg: ipconfig.exe, xcopy.exe, etc) weren’t. Checking the path showed that shell variables inside of the PATH variable weren’t being expanded:

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

However, if Command Prompt is run as an Administrator (Start → Right Click Command PromptRun as administrator) %PATH% will be set correctly:

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

Thanks to a coworker, online research, and the helpful folks over at serverfault the cause of this was found to be an incorrect value type in the registry (discussion here). Specifically, the Path value in HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment must be set to REG_EXPAND_SZ so that it’ll expand shell variables that it contains. If (incorrectly) set to REG_SZ the symptom above will be seen because the variables aren’t expanded.

What doesn’t (yet) make sense to me is why this issue is only visible with the incorrect type in a non-administrative Command Prompt.

For reference, per this MSDN article entitled Registry Value Types the difference between REG_SZ and REG_EXPAND_SZ is that the latter will expand shell variables that it contains; literally “A null-terminated string that contains unexpanded references to environment variables”. The former (REG_SZ) is just a string.

Exit mobile version