Friday, March 8, 2019

windows 7 - Overcoming the 1024 character limit with setx



I am trying to set environment variables using the setx command, such as follows




setx PATH "f:\common tools\git\bin;f:\common
tools\python\app;f:\common tools\python\app\scripts;f:\common
tools\ruby\bin;f:\masm32\bin;F:\Borland\BCC55\Bin;%PATH%"





However, I get the following error if the value is more then 1024 characters long:




WARNING: The data being saved is truncated to 1024 characters.



SUCCESS: Specified value was saved.




But some of the paths in the end are not saved in variable, I guess due to character limit as the error suggests.


Answer




Your best bet is to edit the registry directly.



Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and edit the Path value (then reboot to activate the new value).



Note however that while you can enter a very long path, (up to the maximum environment variable length; 2,048 or 32,768 bytes depending on the source), not all software will be able to read and handle it correctly if it is too long.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...