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?
3 Answers
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).
-
8+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– Mokubai2012-08-03 13:55:16 +00:00Commented Aug 3, 2012 at 13:55
-
1+1 for the "roll forward" suggestion. Very good idea.Fran– Fran2012-08-03 14:03:08 +00:00Commented Aug 3, 2012 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– user4777992017-03-17 09:44:38 +00:00Commented Mar 17, 2017 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.
- DO NOT REBOOT YOUR MACHINE
- Download Process Explorer by Microsoft
- Extract it somewhere and run it
- Double-click one of the processes which was up before PATH was lost
- Select the “Environment” tab
- Find PATH and copy it (it will also copy the variable name, so you need to take it out)
- 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.
-
3Smart 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– user4777992017-03-17 08:41:34 +00:00Commented Mar 17, 2017 at 8:41
-
2Why doesn't this answer get more upvotes?!Arndt Bieberstein– Arndt Bieberstein2022-12-23 20:16:18 +00:00Commented Dec 23, 2022 at 20:16
-
1This saved my ass today yeeesh. Thank you!Kamek– Kamek2023-09-18 19:48:44 +00:00Commented Sep 18, 2023 at 19:48
-
I already rebooted my machine (Windows-11), what do I do now to restore my empty path?dacfer– dacfer2023-11-09 12:19:18 +00:00Commented Nov 9, 2023 at 12:19
-
You'll have to revert to a previous system restore point, unfortunately.dosaki– dosaki2023-11-13 11:21:07 +00:00Commented Nov 13, 2023 at 11:21
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:
- 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. - Right-click on
SYSTEMfile. DO NOT mistakenly right-click on SYSTEM.LOG1 or SYSTEM.LOG2 - Click Properties.
- Go to Previous Versions tab.
- Restore a previous version of this file as well as SYSTEM.LOG1 and SYSTEM.LOG2 somewhere else in your computer.
- Now open
regeditand goHKEY_LOCAL_MACHINE. - Select File->Load Hive...
- Give the address of the extracted
SYSTEMfile and then give a hive name, likeSYSTEM-old. Now, find your
PATHvariable within this new hive.You can find it in
HKEY_LOCAL_MACHINE\SYSTEM-old\ControlSet00x\Control\Session Manager\Environment- Once you are done, unmount the hive and delete
SYSTEM,SYSTEM.LOG1,SYSTEM.LOG2and several.BLFand.REGTRANS-MSfiles that Windows has made for these files.