Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Limit on WScript.Shell .Run method command length?

1,076 views
Skip to first unread message

Craig Schofield

unread,
Jun 23, 2000, 3:00:00 AM6/23/00
to
I am using the .Run method of the WScript.Shell object to execute a number
of commands, and I am having huge problems with the length of the command
line. If the command exceeds a certain length, I get an error #70
Permission Denied.

The command being executed actually uses a couple of Environment variables,
which are expanded when passed to the command line (%comspec% and
%CLASSPATH% in particular). Due to the length of the expanded values of
these variables, the .Run method fails.

Limiting the length of these variables or changing the command line to be
shorter removes the error.

Is there a way to remove this limit, or is it purely a limitation of the
WScript object.

Thanks,
Craig


Philip

unread,
Jun 23, 2000, 3:00:00 AM6/23/00
to
there is a certain limitation about length of Env variables but this only
applies to Win9x.
you shouldn't get this problem with Win NT...

ph.

"Craig Schofield" <c...@connexus.net.au> wrote in message
news:3953428b$1...@news.internex.net.au...

Michael Harris

unread,
Jun 23, 2000, 3:00:00 AM6/23/00
to
There is a limit on the command line length. Using the example script below (on NT4), Shell.Run
fails when the total length exceeds 516...

if wscript.arguments.count > 0 then msgbox "ok":wscript.quit
set shell = createobject("wscript.shell")
scmd = wscript.fullname & " " _
& wscript.scriptfullname & " " & string(1024, "A")
cmd = left(scmd,516) ' works...
shell.run cmd,,true
cmd = left(scmd,517) ' fails...
shell.run cmd,,true

Oddly enough, enclosing the first 2 strings in quotes changes the threshold to 517.

scmd = """" & wscript.fullname & """ """ _
& wscript.scriptfullname & """ " & string(1024, "A")
cmd = left(scmd,517) ' works...
shell.run cmd,,true
cmd = left(scmd,518) ' fails...
shell.run cmd,,true

If you are executing a DOS program, the limit is smaller...

Q198429 - PRB: Executing a 16-Bit Process with a Large Command Line on NT
http://support.microsoft.com/support/kb/articles/Q198/4/29.ASP

--
Michael Harris
MVP Scripting

Bill James

unread,
Jun 23, 2000, 3:00:00 AM6/23/00
to
You might be able to work around the problem by using the FSO ShortPath Property. Also, if the executable is in the Path or registered in HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths, consider not using it's path at all. You might even want to add to the App Paths key for the executable you are using.

--

Bill James
Microsoft MVP·DTS

»Free Win9x VBScript Utilities«
»»New Address - Change your links!««
http://www.svvi.net/wgjames/vbspage/

Craig Schofield

unread,
Jun 25, 2000, 3:00:00 AM6/25/00
to
All,

Thanks for the pointers and suggestions. It looks like I will have to work
around this another way (I am considering writing the command line out to a
temporary batch file and executing it instead). The same command line works
fine from an NT command prompt, so the batch file approach should work.

The actual command line is the execution of a Java class, with a very long
CLASSPATH, hence the problems with length.

Thanks
Craig


0 new messages