Reputation: 105
I am trying to overcome this "environment variable is too large. This dialog allows setting values upto 2047 characters". The reason why I cannot just apply the fix listed here: Environment Variable is too large on Windows 10
is because I can't seem to modify any values in my path system variable. I get the error even when I attempt to delete an existing variable. So what gives?
Any advice on why I can't modify this path at all?
Upvotes: 2
Views: 4963
Reputation: 889
There's currently a bug on Windows 11 (and probably Windows 10).
Let's say you create a new environment variable called ExampleEnvironmentVariable and it contains a few entries:
C:\123
C:\456
C:\789
You then add this to PATH, like this %ExampleEnvironmentVariable%.
When you then run $env:PATH in Powershell, it shows you this:
C:\123;C:\456;C:\789
and that's because PATH has expanded the ExampleEnvironmentVariable to list all its entries.
Why is this useful? Because if you were to add e.g. 1000 entries into PATH directly, it won't work. But if you create a few new environment variables and each contain e.g. 200 entries, and each of those environment variables are added to PATH, then that will work. Your PATH will only have a few entries that reference other environment variables.
The problem here is that once PATH has expanded the environment variables to show their entries, the 2048 limit still kicks in. So it basically renders this trick useless. Even if you set the LongPathName to true in registry or local policy, it doesn't apply to PATH. The best way to check this is to run $env:PATH in Powershell and look at the very end of the entry. If it looks like it's truncated or doesn't look like the path you expect, then it's because the limit has been reached.
Furthermore, it doesn't matter if you add path using the New button or the Edit text button, both will run into the 2048 limit error:
If you use the Edit text option, it may seem like you can modify the path, but you can't actually save it and it will just cut off characters at the very end. It won't necessarily show you an error, but it has basically reached the 2048 character limit.
Others might suggest using solutions such as Autohotkey to add to Path, or use Powershell or even just simply edit the registry key (export and edit .reg file and then import). While the PATH can be edited, the issue is still there because the 2048 character limit will still apply.
The current workaround I'm using is symlinks. By doing that, I keep the path as small as possible. Here's an example of what my PATH looks like:
There is also another bug to be aware of. Firstly, notice how my PATH in the screenshot above doesn't actually expand to the actual symlink target?
For example, let's say D:\Sym\1 has a target that points to C:\ParentFolder\SubFolderA\SubFolderB\SubFolderC\ActualProgramPath. Well, this doesn't show up in PATH and that's great. The actual path is long and the symlink makes it a lot shorter. So the correct output that you should find in Powershell is that it only shows the symlink path.
So what is the bug? Well if you were to add the symlink path (e.g. D:\Sym\1) using the Edit text button (see first screenshot), then that will somehow expand the symlink to the actual target path. When you do $env:PATH in Powershell, it will grab the target path and you'll quickly run into the 2048 character limit again. What you'll need to do is to use the GUI window, i.e the New button.
Upvotes: 1
Reputation: 921
The following solution works on Windows10:
After editing the Variable value, click on the OK button.
Upvotes: 1