Windows 7's PATH and environment variables are corrupted

96

39

I have no clue, but lately I've been having this problem. After running my workstation suddenly something destroys PATH and lots of stuff stops working. Initially, my path had MANY directories listed (I use Windows 7 as a development box) and after some time, I only had 3-4 directories listed in my path left.

I can't even open the System Properties dialog where I can see environment variables (because it uses shell variables to start it and it doesn't work). In short, I reboot every time.

Any ideas what might cause that problem? I didn't run anything new/unusual lately. Only VmWare (but I've been using it in the past and didn't have that problem back then).

I just checked, even %WINDIR% is not defined. WTF?!

Pavel P

Posted 2011-11-09T17:48:54.500

Reputation: 1 558

2I've recently had the same problem on my 64-bit Vista box. With no obvious cause, if I open a new command prompt, then the path variable is set to the part of the path defined in "User variables". The "System variables" part of the path is missing. Some, but not all system variables are undefined. The registry looks OK, and everything looks OK in the System Properties dialog (using "c:\windows\system32\systempropertiesadvanced.exe"). After reboot, the system functions normally. Problem reoccurs every few days. A full virus scan found nothing. – Lee – 2012-01-10T14:35:07.117

I had the same problem. I found a few different things that triggered it (running certain programs, running installers, etc.) but no reason those would cause it (they work fine on other machines or in a VM.) Eventually I had other problems compounding the need to reinstall which fixed everything. – Jim McKeeth – 2012-01-17T02:27:42.063

4my path was too long. I removed duplicates, removed useless entries and problem is gone. – Pavel P – 2012-02-13T00:48:36.720

Answers

126

From my blog

Bottom line, if your PATH environment variable is more than 2048 characters it (and WINDIR) stop being visible in many contexts.

I fixed it by manually running c:\windows\system32\systempropertiesadvanced.exe and deleting one entry from my PATH to put me under 2048 chars. New cmd windows work just fine.

Update: This similar question claims 2047 is the max, and elaborates on expansion rules

Raven

Posted 2011-11-09T17:48:54.500

Reputation: 1 388

3As others mentioned, after fixing your PATH, just restart explorer.exe in the task manager if you don't want to reboot. Please make sure you DO NOT launch task manager by right clicking the task bar! Doing that will initialize task manager with the jacked up path (and hence your new explorer.exe process). Launch it by doing ctrl + shift + escape – C. Tewalt – 2015-06-08T15:06:32.670

1Thank you for this. I was fighting this for the last month or so when a Sony product increased my path by around 200 chars. – Michael Dorgan – 2015-10-15T17:36:32.133

1What I did in addition to what Raven proposed: replace common base dirs like c:\program files (86) in the path variable with another variables like for example PRGX86 pointing to the program files dir. That way you can save some additional characters. – ovm – 2016-04-01T10:45:35.190

@ovm Where would you set those variables? To my knowledge, PRGX86 isn't a default variable. – Hashim – 2019-04-16T06:28:21.293

That's how I fixed the problem. I manually checked path, made it shorter and problem was gone. – Pavel P – 2012-02-13T00:49:08.703

Just happened to me a couple days ago and I couldn't figure out why anything with %windir% just went bonkers. Fixed, thank you! – Jesse Slicer – 2013-07-15T15:25:32.370

2I just fixed the problem by restarting the computer... That's really a stupid limit of Windows! – Edwin Yip – 2013-10-22T12:38:09.327

3Just ran into this problem. What a joke. Thanks – SwimBikeRun – 2014-05-02T17:37:35.347

23

The 2048 character limitation is real. What I did is split the path in two separate variables and include the second variable in the PATH variable:

PATH=C:\;%PATHEXTENDED%
PATHEXTENDED=E:\

Like that I did not have to delete any PATH directories but got the PATH variable under 2048 characters.

Darth Vader

Posted 2011-11-09T17:48:54.500

Reputation: 331

2ok that's pretty genius – kenwarner – 2014-09-13T20:51:41.207

1Very clever, but apps that dynamically add PATH entries will likely be operating on the fully expanded path and will still go nuts. But at least the pain will be scoped to that process. – Raven – 2014-10-27T17:05:55.550

Thank you for this great Idea, but it unfortunatly did not work under Win7: the variable "extpath" -- or in your case "pathextended" -- was not parsed..... – unknown6656 – 2015-12-02T18:43:24.917

2This solution didn't work for me in Win 7. The contents of the 2 variables were concatenated, but any characters after the 2048th(?) were truncated from the resulting combined PATH variable. So I had to remove entries from PATH in the end, as per @Raven, to get my icons and %windir%, etc to come back. – snark – 2017-01-06T14:07:51.180

12

A workaround fix for anyone trying to resolve this problem, either due to excessive path or for any other reason: just restart Explorer. The new shell picks up a new environment. This fixes the corruption for the time being, without having to reboot, even if you haven't yet been able to identify and permanently resolve the underlying cause.

1.

enter image description here

2.

enter image description here

3.

enter image description here

EDIT: update for newer versions of Windows.

Task Manager now does it in one step:

enter image description here

Reg Edit

Posted 2011-11-09T17:48:54.500

Reputation: 1 930

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post - you can always comment on your own posts, and once you have sufficient reputation you will be able to comment on any post.

– Michael K – 2014-07-11T09:28:41.160

With respect, I disagree. The question is, Windows 7's PATH and environment variables are corrupted. My response provides a way to remove that corruption. This is a relevant answer both in its own right, and in conjunction with other fixes after which a reboot would otherwise be needed. – Reg Edit – 2014-07-11T09:36:50.257

I would suggest to edit Ravens answer and add your part to it. Most people will only read the accepted answer and if I understand correctly, your answer is mostly an addition to that. – Michael K – 2014-07-11T09:41:02.000

Ah, I see. No, it's relevant to any solution being tried. I've edited my answer to make that clearer. – Reg Edit – 2014-07-11T10:21:11.460

1this was probably more worthwhile as a comment than an answer. That rather than restart he should end task explorer.exe and restart explorer.exe. Your answer addresses part of his problem - this part "I can't even open the System Properties dialog where I can see environment variables (because it uses shell variables to start it and it doesn't work). In short, I reboot every time." But notice that since he has a path problem after a restart, this wouldn't fix his problem anymore than he has by restarting. – barlop – 2014-07-11T18:32:24.523

This did not work for me, but shortening the path did take care of things :) – Michael Dorgan – 2015-10-15T17:37:37.813

3

you should get a program to monitor the registry keys

user variables

HKCU\Environment

and

machine variables

HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

you might catch the moment they get destroyed and narrow it down.

also, time how long it takes..after bootup. if you can at least know when it'll happen it'll help in narrowing things down.

try safe mode too. incase it's process related, and check event viewer.

barlop

Posted 2011-11-09T17:48:54.500

Reputation: 18 677