Friday, May 29, 2009

PATH variables not resolving

Just recently I had the problem that I couldn't execute most of the commands in the Windows Command Prompt.

When I tried to ping, ipconfig or similar, the prompt just said something like ""ipconfig" is not recognized as an internal or external command, operable system program or batch file.".


 I checked the path variable under the "Environment Variables" ([WIN] + [Pause] Advanced Environment Variables): %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM


Okay, this looks good. So tried "echo %systemroot%" in the Command Prompt ([WIN] + [R] cmd) and the variable got correctly resolved: "C:\WINDOWS".

But when I tried "path" in the Command Prompt I got "PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;…". Correctly it should be "PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32\WBEM;…". Apparently the path variables didn't get resolved for some reason.

Not knowing what the problem was I played around a bit with the "path variable" and suddenly it worked again. But not for long, next time I restarted the same problem reappeared. So decided to do a little research through Google and found this helpful blog post.

Solution

The problem is that the path key in the registry should be of the type "Reg_Expand_SZ" and mysteriously it was of type "Reg_SZ".

Here the step-by-step solution:

  1. Go to: Start > Run > Regedit (alt.: [WIN] +[R] > regedit)
  2. Check: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
  3. Make sure that the registry key holding the path is of Reg_Expand_SZ type rather Reg_SZ type
  4. If the holding key is Reg_SZ change it into Reg_Expand_SZ by:
  • Double Click "Path" and copy it's Data Value "…%SystemRoot%\system32;%SystemRoot%; …" to avoid to rewrite it again
  • Delete the "Path"
  • Create New > Expandable String Value
  • Give "Path" as the name, double click it, and Paste the value copied in the previous step to the "Value Data" field
  1. Close the Regedit window and restart your system or just log-off and on

Another step-by-step solution without using the registry and which should do the same:

  1. Go to the "Environment Variables"
  • [WIN] + [Pause] > Advanced > Environment Variables
  1. Under "System variables" double click on "Path"
  2. Copy the the whole path (%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\system32\WBEM;…)
  3. Click Cancel
  4. Delete the "Path" variable
  5. Click New and use the same name "Path" and paste now the old Path variable values
  6. Click OK and OK
  7. Now restart or just log-off and on

2 comments:

  1. Hello,
    I had the same symptom, but the path entry in the registry was of type Reg_Expand_SZ.
    Then I added a manual entry of c:\windows\system32 in the path variable before the unresolved %systemroot%\system32. Then opened a command prompt and it worked. Then I took the manually added entry out again and it still resolved correctly and kept on working.
    Cheers
    Andy

    ReplyDelete
  2. I had the same symptom, but only in the user path section. The HKEY_LOCAL_MACHINE\... key was set to Reg_Expand_SZ, but the user path under HKEY_CURRENT_USER\Environment was not. Changed it, worked. Thanks a lot.

    ReplyDelete