The PATH is a variable that Windows uses to locate needed executables, especially from the command line. Unfortunately, there are situations where users accidentally delete the PATH variable. This can happen when users inadvertently overwrite the PATH data rather than appending them.
There are also cases where some buggy applications or installers have wiped out the entire PATH environment variable data. This article explains the different ways to recover the PATH variable that was accidentally erased.
Table of Contents
- Option 1: Restore default PATH Environment variable
- Option 2: Recover previous PATH Environment variable settings
Recover the PATH Variable After Deleting it Accidentally
Option 1: Restore default PATH Settings
The PATH variable comprises the System PATH and user PATH entries. System PATH is common for all user accounts. And, as the name suggests, the user PATH is different for each user.
By default, in a standard Windows installation, the following folders are included in the System
And the following folder is included in the User
You can restore the default PATH environment values (for System and/or User) using one of the methods below:
Method 1: Using the System Properties dialog
- Launch the System Properties dialog. To do so, right-click Start, and click Run. Type “
sysdm.cpl” and click OK.
- Select the “Advanced” tab, and click “Environment Variables..”
- Under “System variables,” double-click “Path.”
- In the “Edit environment variable” dialog, add each of the directories listed above.
- If you want to add additional folder locations — e.g., “C:\Program Files\Java,” feel free to add them.
- Also, if you want, you can configure the user path settings by double-clicking “Path” under “User variables.”
- Click OK, OK, OK to close the dialog boxes.
Note: Even though you apply the PATH settings, the currently running applications will use the old PATH settings. Therefore, you may need to close those applications and relaunch them if you want those programs to use the new PATH environment settings.
Method 2: Using Command Prompt
You can use the built-in setx command to modify environment variables in Windows.
- Open an elevated or admin Command Prompt.
- Type the following command and press Enter:
setx /m PATH "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\"
The above command sets the system path variable under the
- To set the user path variable, run this command instead:
setx PATH "%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;"
Important: Be aware there’s a limit of 1024 characters when assigning contents to a variable using
setx. This means that the content is cropped if you go over 1024 characters, and that the cropped text is what’s applied to the target variable. If this cropped text is applied to an existing variable, it can result in a loss of data previously held by the target variable. This StackOverflow link has some nice instructions on SetX.
Method 3: Using Registry Editor
User Variables are stored in a value named
PATH, under this registry key:
System Variables are stored under this registry key:
To restore the default PATH values using the Registry Editor, follow these steps:
- Start the Registry Editor (
- Go to the following location:
- Double-click “Path” and set its data as follows:
Important: Since you’re using expandable strings as the value data, make sure that the “
Path” value type is REG_EXPAND_SZ (instead of REG_SZ). If the existing “Path” value is of type REG_SZ, delete it, create a new REG_EXPAND_SZ value and then input the data.
- Likewise, if you want to fix the user PATH variable, go to this key:
- Double-click “Path” and set its data as follows:
- Exit the Registry Editor.
- Restart Windows for the change to take full effect.
Option 2: Recover previous PATH variable settings
There are situations where you had many custom folder locations in the PATH environment variable and accidentally got them erased. To recover or restore the original PATH environment values exactly, use one of the methods below:
Method 1: Using Process Explorer
If you or a third-party program/installer has wiped out the PATH variable totally, you can recover them during the current Windows session — i.e., if you haven’t shutdown/rebooted Windows yet.
PATHcommand from that Command Prompt instance.
If you don’t have an existing Command Prompt window, then you’ll need the excellent Process Explorer utility to recover the PATH variable from some other process.
(Side note: We’ve covered Process Explorer many times on this site.)
- Start the Process Explorer utility elevated (run as administrator)
- Double-click on a process that was started (and currently running) before the Path variable deletion event.
(For instance, I have an AutoHotKey.exe process running since my user account login time. So I double-click that process to extract the Path environment variable values of that process. Hint: You can also pick
winlogon.exeas those processes start during Windows startup.)
- Click on the Environment tab.
(Tip: Since the Path value is very long, the process properties dialog box can’t display the full path even if you expand the columns manually. However, you can use Ctrl + C keyboard shortcut to copy the value to the clipboard and paste it into Notepad to view the contents.)
- Select the Path variable and press Ctrl + C
- Open Notepad and paste the contents into it.
- Then, manually update the path values using Setx, Regedit, or System Properties dialog, as discussed earlier in this article.
You can enable the process “Start time” column in Process Explorer. It can help you quickly pick a process that started (and running) before the PATH deletion event.
And, if you view the process running under the
NT AUTHORITY\LOCAL SERVICE,
NT AUTHORITY\NETWORK SERVICE, or
NT AUTHORITY\SYSTEM, then the PATH environment of those processes would reflect the respective user account’s user PATH (instead of your user account’s) in addition to the System PATH.
So, if you’re looking to recover the user PATH, be sure to pick the process running under your user account context. However, the “System” PATH variable is common for all user accounts. To view the user account context of each process, you can enable the “User Name” column via the “View” → “Select Columns…” menu option.
Method 2: Using Shadow Copy/Restore Point
If you have an existing shadow copy or Restore Point, you can recover the PATH registry settings from the previous “SYSTEM” registry hive. You can either use RegFileExport, ShadowCopyView, or RegistryChangesView portable utility to extract the settings from an earlier restore point or shadow copy registry hive.
Let’s use the RegistryChangesView tool for this task.
- Download “RegistryChangesView” from
- Configure RegistryChangeView as in the image below.
Note: If the “Shadow Copy Path” drop-down box is empty in “Step 2” above, it means that the system doesn’t have any Restore Points or shadow copies. In that case, this method can’t help.
- Go through steps 1-7 in the article Extract Registry Keys from a Restore Point.
- During Step 8, once the search results appear, type the following in the Quick Filter box:
- Double-click the “
Session Manager\Environment” entry that contains the value named “
- You can note down the original PATH data and apply it using Setx, Regedit, or System Properties dialog. Alternatively, you can export the registry key by clicking “Export Selected Items to .Reg file” from the File menu. The exported registry file, which has the original PATH data, can be applied by double-clicking.
- Exit RegistryChangesView.
- Restart Windows for the updated PATH variable values to take effect.
Additional Tip: Alternately, if you regularly backup your registry hives, then you can load the registry hive (from a previous backup) using the Registry Editor and quickly restore any registry setting from that hive.
Method 3: Using a System Restore rollback
A System Restore rollback reverts your computer to a previous state. System Restore restores critical system files, registry hives, and other components to an earlier setting. You might agree that System Restore rollback is overkill for recovering just the PATH data. But, if the above options are tedious for you, then a System Restore rollback is your easiest choice.
- System Restore rollback is a straightforward process. All you need to do is run the file
rstrui.exewhich brings up the System Restore window.
- By default, the dialog might list the most recent restore point(s) only. To see the complete list, click the “Show more restore points” check box to enable it.
- Pick a restore point created before the date/time the PATH variable was accidentally deleted.
- Complete the System Restore rollback process.
One of these articles can help:
- How to Create a Restore Point and Roll-back to a Previous Restore Point
- Perform System Restore Rollback Offline in Windows 10 [Recovery Options]
You may wonder which method/option to use to recover the PATH variable data. Here’s a checklist for you:
- Process Explorer – This method only works if you haven’t rebooted Windows yet since the PATH deletion event.
- Shadow Copy – This method works if your system has a prior shadow copy or Restore Point. If you have got an earlier registry hive backup, you can use that (instead of shadow copy) in ShadowCopyView.
- System Restore – If you find the above methods tedious, then System Restore could be your ideal solution.
Do you know any other method(s) to recover the old PATH variable settings? Let’s know your comments.
One small request: If you liked this post, please share this?One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
- Pin it!
- Share it to your favorite blog + Facebook, Reddit
- Tweet it!