Windows 10 - How do I recover my user path environmental variable?

0

"I feel like an idiot" is of course obligatory and accurate as an introduction. Anyway, instead of adding to the user path, I accidentally overwrote it, and lost everything in it. I haven't restarted the system yet. How can I find that information and put it back where it belongs before it's lost forever?

Sword of Spirit

Posted 2016-10-13T08:54:54.933

Reputation: 3

Answers

0

Open Regedit.exe and check HKEY_CURRENT_USER\Environment\Path if that doesn't have the old value anymore, you can try to look at a backup of your user profile.

You need the file C:\Users\username\NTUSER.DAT from a backup,

In Registry editor, select HKEY_Users, in the File menu choose Load Hive... and pick the file mentioned above, give it a name. Look in Environment\Path. When done you should unload the hive using File menu Unload Hive... while the loaded hive is selected.

If you have any programs open which you started before you changed the variable you may want to check the environment variables for those processes in Process Explorer. Explorer.exe would be an option.

Peter Hahndorf

Posted 2016-10-13T08:54:54.933

Reputation: 10 677

Thank you. The current HKEY_CURRENT_USER\Environment\Path has nothing, and there isn't an NTUSER.dat under my username, but there is one under the Default user. It looks like it was created when I shut down my computer last night (is that when they do that?) – Sword of Spirit – 2016-10-13T10:10:01.113

Okay, so that's not when you press ENTER in here. Continued...I found '%USERPROFILE%\AppData\Local\Microsoft\WindowsApps` stored in it. So that might be all that is there. I'm going to put an answer to my own question below so I can give some other important info that needs line breaks. – Sword of Spirit – 2016-10-13T10:12:02.050

Scratch that--I'm going to edit my question to give that info. – Sword of Spirit – 2016-10-13T10:13:11.827

Sigh. These text boxes today...Firefox has been running the whole time, and Process Explorer showed the variable I listed above, plus C:\Program Files (x86)\Mozilla Firefox. So does that mean both the WindowsApps and Firefox entries should be there, or is the Firefox one just coming from its currently running status? – Sword of Spirit – 2016-10-13T10:20:14.233

I checked a couple other background files that let me see an environment, and they had the same info (minus Firefox), so that answers my question on that. One final question and then I think it's crisis averted. Should I start it with %USERPROFILE% or with C:\Users... The latter is how it actually showed up in the running environments. – Sword of Spirit – 2016-10-13T10:33:53.420

You should use %USERPROFILE% which is expanded automatically to C:\users\username. So if you ever change your username in the future it still works. – Peter Hahndorf – 2016-10-13T10:47:19.567

NTUSER.dat is a hidden system file, that's why you may not see it. There should be one. The default user one is not yours, it is used as a template when creating new users. Most programs change the local machine path, not the user path. – Peter Hahndorf – 2016-10-13T10:49:42.713

Thanks. I have it set to show hidden and system files, but there doesn't appear to be one under my folder. I am the sole current user profile, if that makes any difference. Neither mine nor Public has anything, just the one in Default. Is there are reason it isn't showing up? – Sword of Spirit – 2016-10-13T10:54:01.693

Ah wait, you're right. It is there now. I'm not sure how I missed it. Maybe it's because I've been up all night. It says the file is in use and won't let me load the hive. – Sword of Spirit – 2016-10-13T10:58:21.640

The NTUSER.DAT in your user directory is the currently loaded one and has the same data as HKEY_CURRENT_USER I wrote you need to get one from a backup of your user directory (if you have one). But it seems there was not much in your user path anyways, so you may not bother. By default you only have %USERPROFILE%\AppData\Local\Microsoft\WindowsApps; – Peter Hahndorf – 2016-10-13T11:09:22.577

0

I know this is an old question. But I did the same thing. The security policy on my workstation restricts regedit so I did the following.

  • Open PowerShell.
  • %env = Get-ItemProperty -Path "HKCU:\Environment"
  • %env.path
  • If this returns the previous value then save a copy of it in notepad (just in case) and replace your local path variable with that.
  • if you want to stick to powershell, you should be able to use Set-ItemProperty -Path "HKCU:\Environment" -Name Path -Value %env.path

Chris McCowan

Posted 2016-10-13T08:54:54.933

Reputation: 11