
String length limit on Windows Scripting Host Run method
Quote:
> Hi Alex,
> I think you're right. I believe that the 32K is a settable buffer for DOS
> 7.1 (Win9x) and otherwise for the command processor, not for the handling of
> files within the main Windows GUI itself. I have always assumed that the
> same limits apply as apply to running files variously in the Run box or
> shortcuts and, more particularly, from the registry shell commands (which I
> have also assumed to be the same handler as used by Shell and
> Shell.Application to run files). My best guess anyway.
I tried this out with one script calling another script using an arbitrary
command line length with the Exec method. The calling script, Tweedledum.vbs,
used the exec method to explicitly call
"c:\windows\system32\cscript.exe C:\tmp\tweedledee.vbs "
adding a string of "x" characters. Tweedledee then wrote the argument length to
a text file. The last length it got before I errored out was 32710; when you add
that to the 55-character length of the base string above, you get 32765.
Arguments appear to get explicit quotes wrapped around them when passed in, so
this comes to 32767. Since strings are usually terminated with a null character
in API methods, this gives us our 32768-character limit for direct transfer.
Note that when I switched to using Sh.Run and dropped the command to just
"tweedledee.vbs", it choked at 2048 characters consistently for the full command
line length.
' === tweedledum.vbs ===
Set Sh = CreateObject("WScript.Shell")
basepath = "c:\windows\system32\cscript.exe C:\tmp\tweedledee.vbs "
baseLen = Len(basePath)
for i = 32755 - baseLen to 33000 - baseLen
'wscript.echo i + baseLen
set exec = Sh.Exec(basepath & String(i, "x"))
Do While Not Exec.StdOut.AtEndOfStream
wscript.sleep 10
Loop
wscript.echo exec.stdout.readall
wscript.echo exec.stderr.readall
next
' === tweedledee.vbs ===
v = len(WScript.Arguments(0))
AppendLine "c:\tmp\tweedle.log", v
Sub AppendLine(FilePath, sData)
'Given the path to a file, will append line sData to it
With CreateObject("Scripting.FileSystemObject")._
OpenTextFile(FilePath, 8, True, TristateUseDefault)
.WriteLine sData: .Close
End With
End Sub
--
Please respond in the newsgroup so everyone may benefit.
http://dev.remotenetworktechnology.com
(email requests for support contract information welcomed)
----------
Subscribe to Microsoft's Security Bulletins:
http://www.microsoft.com/technet/security/bulletin/notify.asp