Limitation to the length of the System PATH variable

Limitation to the length of the System PATH variable

Summary: This article discusses the limitation to the length of the strings that you use in the System PATH variable; overflow symptoms; and possible workarounds

Details: On computers running Microsoft Windows*, the PATH environment variable size that you can use is 2047 characters. On computers running Microsoft Windows* 7 and later, the maximum PATH environment variable size that you can use is 4095 characters (but the system restart is required).

This limitation applies to the command line, individual environment variables (such as the PATH variable) that are inherited by other processes, and all environment variable expansions. If you use Command Prompt to run batch files, this limitation also applies to batch file processing.

Symptoms of the system PATH variable overflow:

PATH size

Windows XP, Windows Server 2003

Windows 7, Windows 8, Windows Server 2008

< 2048 bytes

Everything  works fine

Everything  works fine

>= 2048 and
< 4096 bytes

  1. PATH is empty in the command prompt (echo %PATH%)
  1. PATH is empty in the command prompt (echo %PATH%)
  1. Can’t start applications from the command prompt without the full path (notepad.exe)
  1. Can’t start applications from the command prompt without the full path (notepad.exe)
  1. Able to start applications from the command prompt with full path (c:\windows\system32\notepad.exe)
  1. Able to start applications from the command prompt with full path (c:\windows\system32\notepad.exe)
  1. Windows Explorer works fine
  1. Windows Explorer works fine
  1. Able to launch “Control Panel\System\Advanced system settings”
  1. Can’t launch “Control Panel\System\Advanced system settings”
  1. Able to get “Advanced system settings” from command prompt:
    %WinDir%\System32\SystemPropertiesAdvanced.exe
  1. Able to get “Advanced system settings” from command prompt:
    %WinDir%\System32\SystemPropertiesAdvanced.exe
  1. “Advanced system settings” is able to display all environment variables, including PATH
  1. “Advanced system settings” is able to display all environment variables, including PATH
  1. After restarting the system, PATH is no longer empty, but is truncated to 2048 characters
  1. After restarting the system, PATH is no longer empty and behaves normally

>= 4096 bytes

  • 1, 2, 3, 4, 5 and 6 same as above
  • 1, 2, 3, 4, 5 and 6 same as above
  • “Advanced system settings” fails to display most environment variables, including PATH
  • “Advanced system settings” fails to display most environment variables, including PATH
  • After restarting the system, PATH is no longer empty, but is truncated to 2048 characters
  • After restarting the system, PATH is no longer empty, but is truncated to 4096 characters

Workaround:

  1. Please restart the system. After restarting the system, PATH is no longer empty, but may get truncated to 2047 (4095) characters
  2. If the system restart does not help please:
    1. Launch c:\windows\system32\regedit.exe
    2. Go to the registry hive "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
    3. Clean up unnecessary directories from the “Path” key
    4. Restart the system

Note: In some exceptional cases if the system is not able to start please:

  1. Login in the safe mode
  2. Open the command prompt shell and type:

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d ^%SystemRoot^%\system32;^%SystemRoot^% /f

 

 

For more complete information about compiler optimizations, see our Optimization Notice.

2 comments

Top
Ronald C.'s picture

The errors regarding path length are pretty common, I searched certain forums and I found one recommendation useful the Long Path Tool.

Michael M.'s picture

This is very helpful information, however there is some ambiguity in what you've provided because It is unclear what the grey-background sections are meant to indicate.

The text is not identical left to right, so if the white background means "the issue exists" and the grey means "the issue does not exist" then it implies that < 2048 characters does not work on early Windows but does on later versions, but it also implies that problems related to > 4096 characters do not exist on early Windows versions but do exist on later ones, which is a clear contradiction. Ultimately and without explanation the grey background does not currently communicate useful information, but without it the matrix of issues appears to imply that all problems exist on all versions of Windows, with only the truncation limit changing between the two columns.

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.