{"id":3638,"date":"2011-08-15T14:43:17","date_gmt":"2011-08-15T18:43:17","guid":{"rendered":"http:\/\/nuxx.net\/blog\/?p=3638"},"modified":"2011-08-15T22:09:03","modified_gmt":"2011-08-16T02:09:03","slug":"shell-variables-not-expanding-in-path-on-windows-7-non-administrator-command-prompt","status":"publish","type":"post","link":"https:\/\/nuxx.net\/blog\/2011\/08\/15\/shell-variables-not-expanding-in-path-on-windows-7-non-administrator-command-prompt\/","title":{"rendered":"Shell Variables Not Expanding in %PATH% on Windows 7 Non-Administrator Command Prompt"},"content":{"rendered":"<p>I recently ran into an interesting issue on Windows 7. Users running a non-Administrative <i>Command Prompt<\/i> on Windows 7 would find that Windows&#8217; programs which are supposed to be in their <tt>%PATH%<\/tt> (eg: <tt>ipconfig.exe<\/tt>, <tt>xcopy.exe<\/tt>, etc) weren&#8217;t. Checking the path showed that shell variables inside of the <tt>PATH<\/tt> variable weren&#8217;t being expanded:<\/p>\n<blockquote><p><tt>Path=%SystemRoot%\\system32;%SystemRoot%;%SystemRoot%\\Wbem;%SYSTEMROOT\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Microsoft Windows Performance Toolkit\\<\/tt><\/p><\/blockquote>\n<p>However, if <i>Command Prompt<\/i> is run as an Administrator (<i>Start<\/i> \u2192 Right Click <i>Command Prompt<\/i> \u2192 <i>Run as administrator<\/i>) <tt>%PATH%<\/tt> will be set correctly:<\/p>\n<blockquote><p><tt>Path=C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\Wbem;%SYSTEMROOT\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Microsoft Windows Performance Toolkit\\<\/tt><\/p><\/blockquote>\n<p>Thanks to a coworker, <a href=\"http:\/\/www.google.com\">online research<\/a>, and the helpful folks over at <a href=\"http:\/\/serverfault.com\">serverfault<\/a> the cause of this was found to be an incorrect value type in the registry (discussion <a href=\"http:\/\/serverfault.com\/questions\/300544\/environment-variables-in-path-not-expanded-for-non-admin-command-prompt\">here<\/a>). Specifically, the <tt>Path<\/tt> value in <tt>HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment<\/tt> must be set to <tt>REG_EXPAND_SZ<\/tt> so that it&#8217;ll expand shell variables that it contains. If (incorrectly) set to <tt>REG_SZ<\/tt> the symptom above will be seen because the variables aren&#8217;t expanded.<\/p>\n<p>What doesn&#8217;t (yet) make sense to me is why this issue is only visible with the incorrect type in a non-administrative <i>Command Prompt<\/i>.<\/p>\n<p>For reference, per <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms724884(v=vs.85).aspx\">this MSDN article entitled <i>Registry Value Types<\/i><\/a> the difference between <tt>REG_SZ<\/tt> and <tt>REG_EXPAND_SZ<\/tt> is that the latter will expand shell variables that it contains; literally <i>&#8220;A null-terminated string that contains unexpanded references to environment variables&#8221;<\/i>. The former (<tt>REG_SZ<\/tt>) is just a string.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently ran into an interesting issue on Windows 7. Users running a non-Administrative Command Prompt on Windows 7 would find that Windows&#8217; programs which&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/nuxx.net\/blog\/2011\/08\/15\/shell-variables-not-expanding-in-path-on-windows-7-non-administrator-command-prompt\/\">Continue reading<span class=\"screen-reader-text\">Shell Variables Not Expanding in %PATH% on Windows 7 Non-Administrator Command Prompt<\/span><\/a><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-3638","post","type-post","status-publish","format-standard","hentry","category-computers","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/3638","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/comments?post=3638"}],"version-history":[{"count":13,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/3638\/revisions"}],"predecessor-version":[{"id":3651,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/3638\/revisions\/3651"}],"wp:attachment":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/media?parent=3638"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/categories?post=3638"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/tags?post=3638"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}