Microsoft's documentation says that an environment variable on Windows is limited to
only 32,767 characters
but does not say how to create such a long variable.
The problem here is that the tools that Windows provides all have their
The set and setx commands truncate values to 1023 characters.
Setting directly in the registry at
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
Use embedded environmental variables
If you have:
then you can create a new environment variable such as:
after which your original paths become
You may also split PATH into two by creating a new variable, say
containing the excess paths and append
;%NEWPATH% to the PATH variable.
Avoid using the
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")