String length limit on Windows Scripting Host Run method 
Author Message
 String length limit on Windows Scripting Host Run method

Does anyone know if there is a string length limit to the command line
you pass into the Windows Scripting Host .Run method?

Our app dynamically builds the string to pass in but sometimes (when
the string is quite long) it generates an error.



Wed, 20 Jul 2005 04:14:50 GMT  
 String length limit on Windows Scripting Host Run method

Quote:

> Does anyone know if there is a string length limit to the command line
> you pass into the Windows Scripting Host .Run method?

> Our app dynamically builds the string to pass in but sometimes (when
> the string is quite long) it generates an error.

It's a limitation of the OS, not the Run method.  I've never been able to
find any official documentation, but past posts and personal observation
indicates that it's somewhere around 1K.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Wed, 20 Jul 2005 10:42:11 GMT  
 String length limit on Windows Scripting Host Run method

Quote:

>Does anyone know if there is a string length limit to the command line
>you pass into the Windows Scripting Host .Run method?

>Our app dynamically builds the string to pass in but sometimes (when
>the string is quite long) it generates an error.

This test case generates errors when the argument length is
greater than 2001 characters:

<html>
<head>
<script type="text/javascript">
  function launch(count){
    var arg="X";
    while(arg.length<count) arg+=arg;
    arg=arg.substr(0,count);
    var Shell=new ActiveXObject("WScript.Shell");
    Shell.Run("myHTA.hta "+arg);
  }
</script>
</head>
<body>
<form>
<input name="count" value="1000">
<input type="button" value="launch" onclick="launch(this.form.count.value)">
</form>
</body>
</html>

myHTA.hta is simply:

<html>
<head>
<HTA:application id="myHTA">
</head>
<body>
<script type="text/javascript">
var arg=myHTA.commandLine.replace(/^.* X/,"X");
document.write("I see "+arg.length+" characters.");
</script>
</body>
</html>



Wed, 20 Jul 2005 06:43:27 GMT  
 String length limit on Windows Scripting Host Run method

Quote:

> Does anyone know if there is a string length limit to the command line
> you pass into the Windows Scripting Host .Run method?

> Our app dynamically builds the string to pass in but sometimes (when
> the string is quite long) it generates an error.

Generally, I would think 512 chars, but the command line limit is 32767

I dunno



Wed, 20 Jul 2005 11:45:53 GMT  
 String length limit on Windows Scripting Host Run method
2046 characters, but in practice you have to account for quoting and full paths
with everything used if you are using drag-drop...

--
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



Quote:

> > Does anyone know if there is a string length limit to the command line
> > you pass into the Windows Scripting Host .Run method?

> > Our app dynamically builds the string to pass in but sometimes (when
> > the string is quite long) it generates an error.

> It's a limitation of the OS, not the Run method.  I've never been able to
> find any official documentation, but past posts and personal observation
> indicates that it's somewhere around 1K.

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US



Fri, 22 Jul 2005 00:19:41 GMT  
 String length limit on Windows Scripting Host Run method
That length (32767) is the upper limit to the buffer length I think.  In other
words, the command line _should_ be able to take that many characters; the
problem is that only 2K or so gets passed on to an app via the shell.

--
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



Quote:
> > Does anyone know if there is a string length limit to the command line
> > you pass into the Windows Scripting Host .Run method?

> > Our app dynamically builds the string to pass in but sometimes (when
> > the string is quite long) it generates an error.

> Generally, I would think 512 chars, but the command line limit is 32767

> I dunno



Fri, 22 Jul 2005 00:22:49 GMT  
 String length limit on Windows Scripting Host Run method
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.

Regards,
Joe Earnest



| That length (32767) is the upper limit to the buffer length I think.  In
other
| words, the command line _should_ be able to take that many characters; the
| problem is that only 2K or so gets passed on to an app via the shell.

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02



Fri, 22 Jul 2005 01:17:22 GMT  
 String length limit on Windows Scripting Host Run method
Hi,

Do you have a reference for the 2046.  I've looked but never found a precise
statement.  (I probably overlooked something obvious, as usual.;-)

Regards,
Joe Earnest



| 2046 characters, but in practice you have to account for quoting and full
paths
| with everything used if you are using drag-drop...

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02



Fri, 22 Jul 2005 01:19:39 GMT  
 String length limit on Windows Scripting Host Run method
Two or three arguments/discussions in win2000.cmdprompt.admin, and checking it
out myself.  There seems to be something different which happens with tools such
as the exec method, and drag-drop onto an open object is exempt as well.

For prior discussions, look for the following type of info.

+ Heaviest group os microsoft.public.win2000.cmdprompt.admin

+ "Magic numbers" which show up for different OSs and different shells are 127,
260, 2046, 2047, 2048.

+ Hot terms are "command tail", "command tail length", "console buffer".

Phil Robyn, Marty List, Joe Richards, Dean Wells, Jonathan deBoyne Pollard, and
myself have participated in some of the past discussions.

--
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


Quote:
> Hi,

> Do you have a reference for the 2046.  I've looked but never found a precise
> statement.  (I probably overlooked something obvious, as usual.;-)

> Regards,
> Joe Earnest



> | 2046 characters, but in practice you have to account for quoting and full
> paths
> | with everything used if you are using drag-drop...

> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.410 / Virus Database: 231 - Release Date: 10-31-02



Fri, 22 Jul 2005 01:36:35 GMT  
 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



Fri, 22 Jul 2005 02:08:05 GMT  
 String length limit on Windows Scripting Host Run method

Quote:
> 2046 characters, but in practice you have to account for quoting and
> full paths with everything used if you are using drag-drop...

It can also be limited by personal firewall software.  My working limit
(with {*filter*}Armor) is 1023.

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US



Fri, 22 Jul 2005 05:09:27 GMT  
 String length limit on Windows Scripting Host Run method
What the{*filter*}ens causes _that_ to limit it?

This is something I don't get. ;)

--
Please respond in the newsgroup so everyone may benefit.
  http://www.*-*-*.com/
(email requests for support contract information welcomed)
 ----------
 Subscribe to Microsoft's Security Bulletins:
  http://www.*-*-*.com/



Quote:

> > 2046 characters, but in practice you have to account for quoting and
> > full paths with everything used if you are using drag-drop...

> It can also be limited by personal firewall software.  My working limit
> (with {*filter*}Armor) is 1023.

> --
> Michael Harris
> Microsoft.MVP.Scripting
> Seattle WA US



Fri, 22 Jul 2005 07:08:37 GMT  
 String length limit on Windows Scripting Host Run method

Quote:
> What the{*filter*}ens causes _that_ to limit it?

> This is something I don't get. ;)

Note that I use {*filter*}Armor only because it is a corporate requirement in
order to make VPN connections to work from home.  I used to use ZoneAlarm
when I had a choice ;-).

{*filter*}Armor apparently monitors process creation.  It must consider a large
command line to be virus-like.  I've never had it cause a problem with
anything real.

You and I actually had an NG exchange on this subject where I mentioned this
back in Feb 2002 ;-)...

Google Groups: View Thread "buffer limits with StdOut when passing a lot of
info..."
http://www.*-*-*.com/

Quote:




>>> 2046 characters, but in practice you have to account for quoting and
>>> full paths with everything used if you are using drag-drop...

>> It can also be limited by personal firewall software.  My working
>> limit (with {*filter*}Armor) is 1023.

>> --
>> Michael Harris
>> Microsoft.MVP.Scripting
>> Seattle WA US

--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US


Fri, 22 Jul 2005 07:52:00 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. WshShell.Run command string length limit?

2. Windows Scripting Host Run method fails - HELP!

3. Research: Windows Script Host or Windows Scripting Host

4. Limit to length of Strings

5. Limiting decimal/string length

6. Problems Installing Windows Script 5.0 and Windows Script Host 2.0 Beta on Windows NT 4.0

7. Running programs from a HTA (without Windows Scripting Host)

8. Windows scripting host - Checking a service in Windows NT 4

9. Windows Scripting Host on Windows 95 OSR2

10. Windows 95 OSR1 and Windows Scripting Host

11. Windows Scripting Host for Windows 98 Book

12. Windows Script Host to Execute Remote Script Q311269

 

 
Powered by phpBB® Forum Software