How to restore the Path environment variable I deleted?

I accidentally deleted the Path environment variable by creating a new one with Path name. How can I restore my old Path environment variable?

1

8 Answers

I lost my PATH with a program install earlier today, but with all the existing programs already running, it was easy to get it back. If you have a command window open, run:

echo %PATH%

If you don't, you can look at the environment variables of currently-running programs with Process Explorer (procexp).

4

I followed the advice in the answer to a related question here and recovered my previous path setting as of this morning using regedit. Expanding a bit on that answer, here's how I did it. (Read the linked answer to get the full instructions, I don't provide all the details here.)

I selected my earliest backup from today (11:43 AM timestamp in 'Today' section)

Example of previous versions of RegBack

and examined the earliest ControlSet within the HKEY_LOCAL_MACHINE/System node of that copy of the registry file, ControlSet002:

enter image description here

and copied out the previous value of my path variable from the key Control\Session Manager\Environment\Path within that level.

enter image description here

Your mileage may vary, as I don't know exactly what triggers the backup of the registry.

3
  • From the start menu, open Run (or press ⊞ Win+R).
  • Type regedit
    • Find HKEY_LOCAL_MACHINE folder
    • Go to the SYSTEM folder
    • Go to the ControlSet002 folder
    • Go to Control folder
    • Go to Session Manager
    • Go to Environment folder
    • Then, inside Environment folder, double click Path

The previous Path should be there.

4

You could do a system restore.

To restore your PC using System Restore

Swipe in from the right edge of the screen, and then tap Search. (If you're using a mouse, point to the upper-right corner of the screen, move the mouse pointer down, and then click Search.) Enter Recovery in the search box, tap or click Settings, and then tap or click Recovery.

Tap or click Open System Restore, and follow the prompts.

"Restoring" from a default set is another option, with the risk of some installed apps complaining until fixed.
Background: Happened when launching WLM after a reboot. The only thread with information regarding the missing WLDcore.dll suggested a missing PATH environment variable.
Before the said reboot, there was an admin PS console open in the attempt to make Curl accept commands. Must have knocked out the PATH variable with it somehow.

Fortunately, and unfortunately, Brink's default PATH values were copied toSystem Properties\Environment Variables before accessing the values from ControlSet001 (no ControlSet002 here) referred to in other answers in this thread. So the only option to recover the original values was with the system restore also mentioned in this thread. A good thing is the apps that use PATH on this machine document their requirements of it, so easy to repair.

For those who experienced similar, here's Brink's Windows 10 values:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared

And his bare minimum for previous OSes:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

I only discovered the problem with the environment variables days after they got ruined by the installation of an outdated app. But I still had a full registry backup. There one can find all the system environment variables as off the date of the backup. These can then be compared with the current situation as per System / Advanced system settings / Environment variables. Depending upon how recent the backup is, and assuming no environment variable changes since then, you are ok. Worst case is that you'll have to reinstall the apps that you had installed after the registry backup and before losing your path data, which is typically less work than a restore. Below I'll explain how this can be done.

  1. Open the backup.reg file with Notepad++ (free and excellent editor). Find HKEY_LOCAL_MACHINE/SYSTEM/ControlSet001/Control/Session Manager/Environment. If that does not work try ControlSet002 or higher.

  2. Copy paste the hex(2) hash data for the PATH into a new Notepad++ window. Find/replace all ',' (commas w/o the quotes) with ' ' and all '00' with '', and all double spaces ' ' with a single space ' '. You should now be left with "pure hex" without commas or zeros as separator.

  3. Open . This is a hex to ascii converter. Copy paste the "pure hex" data into the hex window and click convert. You can now see your path data, and copy paste them into Notepad, compare with the current version, and add the missing data. You're back in business!

  4. As a bonus you might also want to check on the other environment variables by comparing the data in the Notepad++ backup.reg with the current values. Missing data can be retrieved in the same way as explained above.

I accidentally deleted the Path environment variable


So did I, and many commands that used to work suddenly produced an error:

The term '<command>' is not recognized as the name of a cmdlet, function, script file, or operable program. 


The other answers to this problem didn't work for me, so

I had to recover the Path environment variable a little at a time:

  1. From a plain command prompt, not PowerShell, enter where <command>, e.g., where npm.
  2. Enter "environment variables" in Cortana to edit the system environment variables.
  3. Under System variables, find the Path variable and click Edit.
  4. Add each file path from step 1.
  5. Restart your computer.
  6. Repeat for each command that produces the error.
  7. Enjoy using commands that work. :-)

enter image description here

I have just retrieved it by doing as follows: My previous Path settings was still on the dos cmd prompt screen. So right click on it with your mouse. Take 'Select All'. This copies your screen. Open Notepad, and paste. Now highlight the Path definition in notepad, right click and copy. Go back to dos cmd prompt screen. right click and paste This has worked for me so Good Luck!

1

You Might Also Like