Overcoming the 1024 character limit with setx

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.


if you are using windows vista or higher, you can make a symbolic link to the folder. for example:

mklink /d C:\pf "C:\Program Files"
mklink /d C:\pf86 "C:\Program Files (x86)"

would make a link so c:\pf would be your program files folder. I shaved off 300 characters from my path by using this trick.

(I know it's not related to setx but it is useful for people which are searching overcomming on 1024 char limit)


You could use a PowerShell script similar to the following:

$newPath = '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'
$oldPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine');
[Environment]::SetEnvironmentVariable('PATH', "$newPath;$oldPath",'Machine');

The Environment.SetEnvironmentVariable() API call will broadcast WM_SETTINGCHANGE so you do not need to reboot.