I recently installed openssh on my Windows 7 machine. The install overwrote my Path variable and blew away all of the other paths I use in the command line. I probably have 50 paths in there and it is going to take me forever to remember them all. Is there anyway to recover this variable from before the install?


Your environment is in the Registry, and may be saved as part of a system restore point. You could try reverting to the previous restore point, but it may revert more than just your install of OpenSSH (i.e., you may have to re-install other software).

  • 7
    +1 For System Restore being the only sensible tool to use for this. Additionally I believe with System restore you can "roll forward" to a restore point after copying out the information you need so the best process may be to create a new restore point, roll back, copy the path and then roll forward again which should result in little real change to your system. – Mokubai Aug 3 '12 at 13:55
  • 1
    +1 for the "roll forward" suggestion. Very good idea. – Fran Aug 3 '12 at 14:03
  • @Fran I am giving you an upvote because I am also writing an answer based on extracting the PATH from Registry and I don't want you to feel I stole your answer. (Although, if I may brag, my answer is superior!) – user477799 Mar 17 '17 at 9:44

In case you don't have any restore point or you don't want to go through that process, Microsoft provides a tool called Process Explorer with which you can inspect the path at the time a process was created.

This method won't work if you've restarted your machine as it depends on the processes running before your PATH variable was changed.

  2. Download Process Explorer by Microsoft
  3. Extract it somewhere and run it
  4. Double-click one of the processes which was up before PATH was lost
  5. Select the “Environment” tab
  6. Find PATH and copy it (it will also copy the variable name, so you need to take it out)
  7. Paste it onto your PATH variable.

That should do it. Keep in mind that these PATH variables are resolved, i.e., you won't have any %VARIABLE_HERE% in the path value.

  • 1
    Smart response! It relies on the fact that once an app is launched, it makes a copy of the PATH variable and keeps it until the app is closed. – user477799 Mar 17 '17 at 8:41

The PATH environment variable is stored in Windows Registry under:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet00x\Control\Session Manager\Environment

...in Path parameter. ("x" in "ControlSet00x" is a digit.)

If the Registry is backed up as part of one of your System Restore checkpoints, you can extract the backed up copy without restoring your system to a previous checkpoint! To do this:

  1. Navigate to C:\Windows\System32\Config. I prefer to do this in an app like Multi Commander, so as not to disturb its NTFS permissions.
  2. Right-click on SYSTEM file. DO NOT mistakenly right-click on SYSTEM.LOG1 or SYSTEM.LOG2
  3. Click Properties.
  4. Go to Previous Versions tab.
  5. Restore a previous version of this file as well as SYSTEM.LOG1 and SYSTEM.LOG2 somewhere else in your computer.
  6. Now open regedit and go HKEY_LOCAL_MACHINE.
  7. Select File->Load Hive...
  8. Give the address of the extracted SYSTEM file and then give a hive name, like SYSTEM-old.
  9. Now, find your PATH variable within this new hive.

    You can find it in HKEY_LOCAL_MACHINE\SYSTEM-old\ControlSet00x\Control\Session Manager\Environment

  10. Once you are done, unmount the hive and delete SYSTEM, SYSTEM.LOG1, SYSTEM.LOG2 and several .BLF and .REGTRANS-MS files that Windows has made for these files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.