How do I bypass restrictions on the length of the PATH variable
Solution 1:
Microsoft's documentation says that an environment variable on Windows is limited to only 32,767 characters (link), but does not say how to create such a long variable.
The problem here is that the tools that Windows provides all have their limits :
The set and setx commands truncate values to 1023 characters.
Setting directly in the registry at
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
fails since regedit truncates entered strings after 2047 characters.
So you must use workarounds.
Use short folder names
You may see such names by using dir /x /ad
.
The following example shows that on my computer the folder Program Files (x86)
may be replaced by PROGRA~2
:
Use embedded environmental variables
If you have:
C:\this_is_a\long_path\that_appears\in_multiple_places\subdir1
C:\this_is_a\long_path\that_appears\in_multiple_places\subdir2
then you can create a new environment variable such as:
SET P1=C:\this_is_a\long_path\that_appears\in_multiple_places
after which your original paths become
%P1%\subdir1
%P1%\subdir2
You may also split PATH into two by creating a new variable, say NEWPATH
,
containing the excess paths and append ;%NEWPATH%
to the PATH variable.
Avoid using the setx command because it will directly resolve embedded environmental variables and the resulting string will be once again too long.
Use a PowerShell script to set the PATH
PowerShell calls Windows API directly and so can approach the theoretical limit of 32,767 characters for an environmental variable.
The script may contain commands such as:
[Environment]::SetEnvironmentVariable("Path", $longpath, "Machine")
Solution 2:
While the dialog that you used limits the length that environment variables to 2047 characters, the registry editor does not have that limitation. The registry editor can be opened with the run dialog which can be opened with the Win+R keyboard shortcut. Typing regedit
and pressing enter will open the registry editor. Environment variables are listed under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Control\Session Manager\Environment
and Path
can be found among them. Right-clicking Path
will open a menu, of which Modify... can be selected to modify the value of the variable. As always, when working with the registry editor, make sure that you only change what you intend to, as some changes may have less than desirable side effects.
Solution 3:
I tried this. It is working for me after following @harrymc’s answer even if you are facing this issue try this.
Make a new path2
with all contents from path
.
Now place %path2%
inside path
So now %path2%; %path3%; %path4%; ...
and so on.