I know this is strange and I have spent almost 3 days searching for the solution online without getting a useful one. So I have decided to come here.
I have recentl
There are few ways to clean up your path variable. The easiest is to use Rapid Environment Editor. This free utility will,
I do above steps in order and use 3rd step only for longest paths until Path variable size is in control again.
If you want to go more advanced, here's little C# tool that you can modify to whatever other logic you want to implement.
In addition to other methods (e.g. Powershell), I found a nice GUI, "Rapid Environment Editor" that can handle larger text values.
https://www.rapidee.com/en/download
Workaround:
Please restart the system. After restarting the system, PATH is no longer empty, but may get truncated to 2047 (4095) characters If the system restart does not help please:
Launch c:\windows\system32\regedit.exe Go to the registry hive "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Clean up unnecessary directories from the “Path” key Restart the system
Note: In some exceptional cases if the system is not able to start please:
Login in the safe mode Open the command prompt shell and type: reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d ^%SystemRoot^%\system32;^%SystemRoot^% /f
For more details: https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable
When PATH variable gets overloaded with too many values it reaches a point where you cannot add values anymore. Trying the following should solve your problem.
Solution 1:
If this still doesn't work then try to copy some part of PATH variable already existing values to the 'NEWPATH' and then append the 'NEWPATH'
Solution 2:
Check the value of PATH variable if you can group and shorten the paths. For example,
C:\Program Files\Microsoft SQL Server\102\Tools\Binn\;C:\Program Files\Microsoft SQL Server\102\DTS\Bin\;
can be combined to
C:\Program Files\Microsoft SQL Server;
In this way you can build more space into your fixed length PATH variable and finally adjust your bin directory location into PATH.
Hope this helps you!
You can also try going through your variables to see if there are any irrelevant paths you could delete. This would free up some space for you to add another or more variables.
Another solution or more a workaround to bypass the Environment PATH variable length limit is to manage your path (add, remove or update) using a PowerShell
script;
Capture the current PATH variable by clicking "Edit Text" (see above screenshot) and copy it to your clipboard and save it in a text file as a backup too to avoid bad surprises. This is not mandatory but will allow you to recover should something go wrong.
Now that it is backed up, add the following to a new PowerShell (.ps1) file (amending the first line below with the folder path(s) you want to add (the part after the + sign):
$newPath = $env:Path + '; C:\Users....\FirstFolderToAddToPath; C:\Users....\SecondFolderToAddToPath;'
[Environment]::SetEnvironmentVariable("Path", $newPath, "Machine")
$env:Path = $newPath
This is how I managed to get my (long) PATH variable back after playing with the Windows 10 UI, being caught by the length limitation and loosing most of my path. I hope it helps.