on this Windows XP-Pro site, below "2nd Note", MicroSoft wrote:• The maximum total environment variable size for all variables, which includes variable names and the equal sign, is 65,536KB.
A tasklist /V dump of a batch program currently running on windows XP.
Code: Select all
cmd.exe 3604 Console 0 75.904 kB Actief ED-work-VM\Administrator 0:13:30 n.v.t.
This is well over 65,536KB. I have not been able to detect any limit. The largest session I ever ran consumed around 300MB. Why this claim is made is a complete mystery to me. I did detect failures to start some installers from such large environments, apparently some programs can't handle it while others can handle it just fine.
on this Windows XP-Pro site, below "2nd Note", MicroSoft wrote:• The maximum individual environment variable size is 8192bytes.
What they do not say is that you won't be able to set those last bytes.
Code: Select all
@echo off
::size=1
set "x=#"&set x
::size=2
set x=%x%%x%&set x
::size=4
set x=%x%%x%&set x
::size=8
set x=%x%%x%
set y=%x:~0,-6%size=8
set y
::size=16
set x=%x%%x%
set y=%x:~0,-7%size=16
set y
::size=32
set x=%x%%x%
set y=%x:~0,-7%size=32
set y
::size=64
set x=%x%%x%
set y=%x:~0,-7%size=64
set y
::size=128
set x=%x%%x%
set y=%x:~0,-8%size=128
set y
::size=256
set x=%x%%x%
set y=%x:~0,-8%size=256
set y
::size=512
set x=%x%%x%
set y=%x:~0,-8%size=512
set y
::size=1024
set x=%x%%x%
set y=%x:~0,-9%size=1024
set y
::size=2048
set x=%x%%x%
set y=%x:~0,-9%size=2048
set y
::size=4096
set x=%x%%x%
set y=%x:~0,-9%size=4096
set y
::size=8185
set x=%x%%x:~0,-7%
set y=%x:~0,-9%size=8185
set y
::size=8192
set y=%x:~0,-2%size=8192
set y
pause
exit
The variable name is part of this size and in this case has a length of one byte. If the complete command for size=8185 is expanded, it makes up a total of 8191 bytes. The set command is shorting the max assignment by at least 6 bytes.