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 Prompt → Run 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.
It seem a recent update, eitheir from Microsoft or one program that modify the path directly into the registry is reponsable for this issue. Although I didn’t localized yet the cause of this issue, I have recently encountered it on multiple computer. (WinXp, Win7x86 and Win7x64)
the safest workaround I found was to go to the PATH propertie of Windows, use the modify button, change nothing and save it back. Windows save it back corectly into the right Registry type.
VbNetMatrix: Thanks for the reply, but I can tell you that it was not a Windows application that did it. It was a corporate application packaged by a vendor for a customer of mine. Said vendor very quickly corrected the issue.
I had a very similar problem, but kind of reversed: my PATH variable was of the correct type (REG_EXPAND_SZ), but the variable referenced from the PATH was of the same type. All the symptoms were the same (expanded correctly in the admin cmd, not expanded in the user cmd). Changing the type of the referenced variable to REG_SZ fixed my problem too…