I just messed up my Windows 7 Enterprise 64-bit.

I tried to install CMake - and during installation i got an error saying something like it can't set the path variable, because it is too long (I can't reproduce the exact error message as the installer won't start now anymore).

So - what I did then was to open control panel -> sytem and security -> system -> advanced system settings -> environment variables

and i added the cmake bin folder manually to the end of the PATH system variable and saved.

But well - now nothing works anymore. If i try to open 'Advanced system settings' again, i get the error

The filename or extension is too long.

if I try to open regedit

The filename or extension is too long.

I still can open a cmd prompt, but not elevated. If i try to start cmd as administrator, i'll get the same error.

I don't want to restart my computer as i think it will not be able to boot up in the current state. I don't know how to change my Path variable back to what it was before


I see now a bit better what i did wrong.

beside extending the path variable, i also set a new system Envrionment variable called


but unfortunately i had the System Path in the clipboard when copy pasting it. so, what i have now is something like this:

OPENCV_ROOT = .....;%OPENCV_ROOT%\bin;....

PATH = .....;%OPENCV_ROOT%\bin;....

this is obviously very bad. I try to delete the OPENCV_ROOT variable, but without being able to start any elevated application, it seems impossible


  • Have you tried recreating the original registry key in a .reg text file and then overwriting your current key with it? support.microsoft.com/kb/310516#appliesto – Tog Mar 9 '12 at 10:20
  • i didn't try yet, but doesn't a reg file just execute regedit? – Mat Mar 9 '12 at 10:24
  • Regedit may be used to do the merge but it doesn't open the front end. I don't know if it will produce the same error or not but it can't hurt. – Tog Mar 9 '12 at 10:34
  • just tried, produces the same error :( – Mat Mar 9 '12 at 11:09
  • Just looking at free utilities but most of them depend on regedit to work. There is one called reg scanner that can delete the values in entries but I've never used it so I can't vouch for it. – Tog Mar 9 '12 at 15:37

I'm not sure if Safe Mode does anything with the PATH var, but it might be worth a try. Failing that, you could try booting into BartPE or WinPE, and running regedit that way.

Once booted into *PE, launch regedit, click on HKLM, and go File → Load Hive.

#include <stdregistrywarning.h>

Navigate to \WindowsDIR\system32\config and select the file 'SYSTEM'. You might want to make a copy of this file, first. Just in case. Give the Hive a name to be loaded as. Eg: OfflineSYS. I say WindowsDIR, meaning where Windows is installed on your laptop's hard disk – not where Windows PE is running from.

Then navigate to HKLM\OFFLINESYS\CurrentControlSet\Control\Session Manager\Environment

Now find the REG_SZ value path (if that's the one that's too long), and edit it so it's shorter.

Navigate back to HKLM, and unload the hive. Exit regedit, reboot into Windows 7.


So you can open cmd, then there is a set command can be used to set variable, try to set PATH and OPENCV_ROOT to empty and inside the cmd execute C:\Windows\system32\system32\systempropertiesadvanced.exe.

  • good idea, but gives the same error when i try to launch systempropertiesadvanced.exe – Mat Mar 9 '12 at 12:40

You can use 3rd party registry editing application like TuneUp Utilities. Though I am not sure if it will work for you, but you may try.

  • Can you give a more detailed description of the linked content, and explain how it relates to the question? This will help ensure that this answer remains useful in the event the linked page goes offline. In addition, please be careful posting links in answers of this nature—they could be seen by the community as spam, correctly or otherwise. See the help center for more information. (This link looks legit, but please be mindful here.) – bwDraco Dec 25 '14 at 19:55
  • The application Tune-Up Utilities has an extension called Registry Editor. Using that you could possibly get access to system registry even when it is otherwise inaccessible. (I am not sure of it but it is at least worth a shot, as that application comes with a full functional 30-days trial). Then navigating to this: "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" the required changes can be made to the path variable – Sнаđошƒаӽ Dec 27 '14 at 2:52

Try running REGEDIT as Administrator while logged on normally. Type REGEDIT into the start menu search box. REGEDIT appears at the top of the list SHIFT + RightClick it and choose Run as Administrator. Supply an admin password if needed.

Go here:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment Path = EDIT THIS VALUE

Not the answer you're looking for? Browse other questions tagged or ask your own question.