Missing environment variables in Windows 7 [duplicate]

When I fresh boot my computer everything is dandy. Then after a few hours applications like Visual Studio, Notepad++, Games, iTunes, Windows components (Cmd prompt, Explorer, etc.), etc. stop working with errors about missing files or not being installed correctly.

I found that if I browse out to Cmd.exe and run it directly (instead of from the menu link) then I can run it, and the WinDir environment variable and others are missing (which explains why I can't run Cmd.exe from the shortcut since it uses %WinDir%\System32 for the path) and the system path is set to (NULL).

When I go to Advanced System Settings (again manually exploring to SystemPropertiesAdvanced.exe) all the environment variables are still there. I checked my memory utilization and I have 1 of 6 Gig free, with my Commit Charge peak well bellow the limit (like 30%).

The clipboard also stops working too.

Not running anything to exotic, although I do have a lot of Chrome tabs open. Running Backblaze for backup, Microsoft Security Essentials, and various other utilities. Closing things one at a time hasn't seemed to fix it.

It has been getting progressively worse (happening sooner and sooner). Would like to know what is causing it without reinstalling.

Running Windows 7 Ultimate 64-Bit


Solution 1:

Been fighting with the same problem. Symptoms:

  • reboot: all OK
  • after a while: programs seem to lose %windir% environment variable and therefore things start to break

In my case, I had a somewhat big %PATH%, so I trimmed down a lot of entries from PATH and it got fixed. Not sure how a big PATH can clean WINDIR but it seemed to have fixed it.

The effect of the fix isn't immediate (you have to reboot or restart explorer), but I can verify it by using task manager to kill explorer.exe and open it again (thus avoiding a reboot). Task Manager inherits environment variables from winlogon whereas process explorer seems to inherit them from whatever process started it, so it may keep your big environments problem even though you changed them.

Solution 2:

I also had a very long %PATH% environment variable. As a software engineer, I typically have several applications installed and removed from my computer on a regular basis. It is common for some applications to insert a semi-colon delimited entry into the %PATH% environment variable, typically if there is a potential that the installed application will execute from the command line (cmd.exe) because I am not too concerned with which applications will execute from the standard command line, I backed out all entries from the %PATH% variable except for C:\Windows\System32 (the place where most of your "cmdlets" are going to run from. A bit more information can be found on the topic on wiki-pedia @ http://en.wikipedia.org/wiki/PATH_(variable) For a quick fix (Windows 7) do the following:

1.) Click Start, in the search box at the bottom of the menu, copy and paste or type the following to open the System Advanced Properties Window C:\Windows\System32\SystemPropertiesAdvanced.exe (press enter)

2.) Click the Environment Variables button near the bottom of the window just slightly above the ok, cancel and apply cluster.

3.) The Environment variables window should be displayed now. In the second list box on the screen with the header text (System Variables) look for the word Path under the column Variable and Double Click it.

4.) You should be looking at what appears to be a list of directories on your computer that are separated by the ; delimiter. Take close attention, some you may want and some you may wonder why they are present, clear as many of the paths as your heart desires, the idea here is to shorten the path as much as you feel comfortable doing, again I shortened mine to C:\WINDOWS\system32 and have had no issues since.

5.) Once you have completed editing the Path variable, click "Ok" on all of the open dialog windows.

6.) Once again, click on start, in the bottom search bar, type taskmgr and press enter on your keyboard.

7.) Click on the "Processes" Tab and locate the process "Explorer.exe" under the "Image Name" column of the process grid. Click the process once to highlight it, then click the "End Process" button.

8.) Click File (if you do not see it, press the alt key first), click the sub menu item under file "New Task (Run)"

9.) In the input box displayed type explorer and press enter or click ok.

Test your broken links / shortcuts to see if they now work.

Solution 3:

Per Lasse V. Karlsen's suggestion I looked for a really high Handle count next time it happened. Audacity had 41K of them, and it has been rather unstable lately too. Unfortunately I have the latest version (1.3.12), and closing it doesn't seem to reclaim all of the handles. I'll file a bug report.

NOTE: While Audacity was leaking handles, this does not appear to have been the only cause of my headache. Still having troubles and haven't used Audacity since reboot. May be time for a reinstall.

I ended up reinstalling before finding a fix.