How to Recover PATH Variable After Deleting it Accidentally

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.

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 PATH.

  • %SystemRoot%\system32
  • %SystemRoot%
  • %SystemRoot%\System32\Wbem
  • %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
  • %SYSTEMROOT%\System32\OpenSSH\

And the following folder is included in the User PATH:

  • %USERPROFILE%\AppData\Local\Microsoft\WindowsApps

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

  1. Launch the System Properties dialog. To do so, right-click Start, and click Run. Type “sysdm.cpl” and click OK.
  2. Select the “Advanced” tab, and click “Environment Variables..”
  3. Under “System variables,” double-click “Path.”
  4. In the “Edit environment variable” dialog, add each of the directories listed above.
    path environment variable - system properties
  5. If you want to add additional folder locations — e.g., “C:\Program Files\Java,” feel free to add them.
  6. Also, if you want, you can configure the user path settings by double-clicking “Path” under “User variables.”
  7. 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.

  1. Open an elevated or admin Command Prompt.
  2. Type the following command and press Enter:
    setx /m PATH "%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\"

    path environment variable - setx command

    The above command sets the system path variable under the HKEY_LOCAL_MACHINE registry hive.

  3. 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 setxThis 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:

HKEY_CURRENT_USER\Environment

System Variables are stored under this registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

To restore the default PATH values using the Registry Editor, follow these steps:

  1. Start the Registry Editor (regedit.exe)
  2. Go to the following location:
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
  3. Double-click “Path” and set its data as follows:
    %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;%SYSTEMROOT%\System32\OpenSSH\;

    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.

    path environment variable - registry

  4. Likewise, if you want to fix the user PATH variable, go to this key:
    HKEY_CURRENT_USER\Environment
  5. Double-click “Path” and set its data as follows:
    %USERPROFILE%\AppData\Local\Microsoft\WindowsApps;
  6. Exit the Registry Editor.
  7. 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.

The recovery of the old PATH variables can be possible by reading the Environment settings of any program started before the PATH deletion event. All the already-running programs will continue running with the Environment they had at their startup. For instance, if a rogue program has deleted the PATH variable at 12:00 PM, you can recover the PATH by reading the Environment settings of a running program that was started before 12:00 PM. Let’s say you have a Command Prompt window that has been running already; you can easily view and recover the PATH by running the SET or PATH command 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.)



  1. Start the Process Explorer utility elevated (run as administrator)
  2. 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 csrss.exe or winlogon.exe as those processes start during Windows startup.)
  3. Click on the Environment tab.
    recover path environment variable - process explorer
    (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.)
  4. Select the Path variable and press Ctrl + C
  5. Open Notepad and paste the contents into it.
  6. Then, manually update the path values using Setx, Regedit, or System Properties dialog, as discussed earlier in this article.

Additional Tips

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.

recover path environment variable - process explorer

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.

  1. Download “RegistryChangesView” from Nirsoft.net.
  2. Configure RegistryChangeView as in the image below.
    recover path environment variable - shadow copy hive
    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.
  3. Go through steps 1-7 in the article Extract Registry Keys from a Restore Point.
  4. During Step 8, once the search results appear, type the following in the Quick Filter box:
    \environment
  5. Double-click the “Session Manager\Environment” entry that contains the value named “Path
    recover path environment variable - shadow copy hive
  6. 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.
    recover path environment variable - shadow copy hive
  7. Exit RegistryChangesView.
  8. 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.

  1. System Restore rollback is a straightforward process. All you need to do is run the file rstrui.exe which brings up the System Restore window.
    create restore point or rollback previous
  2. 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.
  3. Pick a restore point created before the date/time the PATH variable was accidentally deleted.
  4. Complete the System Restore rollback process.

One of these articles can help:


Closing Words

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!
So thank you so much for your support, my reader. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded Winhelponline.com in 2005.

Leave a Comment