running DOS commands on NT using WSH 
Author Message
 running DOS commands on NT using WSH

Hello all!

I am trying to run a directory call from within a VBScript, and I tried the
following:
----------------------------------------------------------------------------
---------------------------------------
set WshShell = wscript.createObject("Wscript.Shell")

wscript.echo "starting"
iReturn = WshShell.Run("command.com /K Dir c:\Windows\system32", 1, TRUE)
wscript.echo "Hello"
----------------------------------------------------------------------------
----------------------------------------

I got this script from Ian Morrish's site, but I keep getting the following
error:

Invalid switch
Specified COMMAND search directory bad
Too many parameters
Microsoft(R) Windows NT DOS
(C)Copyright Microsoft Corp 1990-1996.

F>

Any suggestions?



Sun, 20 Jan 2002 03:00:00 GMT  
 running DOS commands on NT using WSH
I saw his example, and it was very helpful.
The following works. I haven't tried it with /K as opposed to /C

  Command = "command.com /C dir " & Trim(DrivePath) & " > " &
"c:\temp\dummy.txt  /ON"
  'run format#1
  objWSH.Run Command, nWindowStyle, bWaitOnReturn

On Wed, 4 Aug 1999 11:18:43 -0400, "Kris Decker"

Quote:

>Hello all!

>I am trying to run a directory call from within a VBScript, and I tried the
>following:
>----------------------------------------------------------------------------
>---------------------------------------
>set WshShell = wscript.createObject("Wscript.Shell")

>wscript.echo "starting"
>iReturn = WshShell.Run("command.com /K Dir c:\Windows\system32", 1, TRUE)
>wscript.echo "Hello"
>----------------------------------------------------------------------------
>----------------------------------------

>I got this script from Ian Morrish's site, but I keep getting the following
>error:

>Invalid switch
>Specified COMMAND search directory bad
>Too many parameters
>Microsoft(R) Windows NT DOS
>(C)Copyright Microsoft Corp 1990-1996.

>F>

>Any suggestions?



Sun, 20 Jan 2002 03:00:00 GMT  
 running DOS commands on NT using WSH

What that error means is that your %path% is bad.

In NT, you should use cmd.exe.:

iReturn = WshShell.Run("cmd.exe /k Dir c:\Windows\system32", 1, TRUE)

If it's important to not have the NT command extensions available in the
prompt, do:

iReturn = WshShell.Run("cmd.exe /y /k Dir c:\Windows\system32", 1, TRUE)

Do 'cmd /?' at a command prompt for more information.


Quote:
> Hello all!

> I am trying to run a directory call from within a VBScript, and I tried
the
> following:
> --------------------------------------------------------------------------
--
> ---------------------------------------
> set WshShell = wscript.createObject("Wscript.Shell")

> wscript.echo "starting"
> iReturn = WshShell.Run("command.com /K Dir c:\Windows\system32", 1, TRUE)
> wscript.echo "Hello"
> --------------------------------------------------------------------------
--
> ----------------------------------------

> I got this script from Ian Morrish's site, but I keep getting the
following
> error:

> Invalid switch
> Specified COMMAND search directory bad
> Too many parameters
> Microsoft(R) Windows NT DOS
> (C)Copyright Microsoft Corp 1990-1996.

> F>

> Any suggestions?



Sun, 20 Jan 2002 03:00:00 GMT  
 running DOS commands on NT using WSH

Quote:

> I have updated the FAQ to include cmd.exe for NT systems.
> Regards,
> Ian
> WSH FAQ http://wsh.glazier.co.nz

I believe it should just be changed to %COMSPEC%.  That works for ALL MS
OS's, whether the command processor is stored in a folder named on the
path or not.  Specifically, ...

iReturn = WshShell.Run("%COMSPEC%/K Dir c:\Windows\system32", 1, TRUE)

In this application, the %Comspec% variable is expanded on use (as would
%systemdir% in place of the literal C:\Windows\system32).

BTW, the /K means that the secondary process will not end until the user
types EXIT <Enter> while the focus is in the console window.  Unless
this is the desired operation, the /C should be used instead.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/

Quote:


> > What that error means is that your %path% is bad.

> > In NT, you should use cmd.exe.:

> > iReturn = WshShell.Run("cmd.exe /k Dir c:\Windows\system32", 1, TRUE)

> > If it's important to not have the NT command extensions available in the
> > prompt, do:

> > iReturn = WshShell.Run("cmd.exe /y /k Dir c:\Windows\system32", 1, TRUE)

> > Do 'cmd /?' at a command prompt for more information.



> > > Hello all!

> > > I am trying to run a directory call from within a VBScript, and I tried
> > the
> > > following:

> > --------------------------------------------------------------------------
> > --
> > > ---------------------------------------
> > > set WshShell = wscript.createObject("Wscript.Shell")

> > > wscript.echo "starting"
> > > iReturn = WshShell.Run("command.com /K Dir c:\Windows\system32", 1,
> TRUE)
> > > wscript.echo "Hello"

> > --------------------------------------------------------------------------
> > --
> > > ----------------------------------------

> > > I got this script from Ian Morrish's site, but I keep getting the
> > following
> > > error:

> > > Invalid switch
> > > Specified COMMAND search directory bad
> > > Too many parameters
> > > Microsoft(R) Windows NT DOS
> > > (C)Copyright Microsoft Corp 1990-1996.

> > > F>

> > > Any suggestions?



Sun, 20 Jan 2002 03:00:00 GMT  
 running DOS commands on NT using WSH
I have updated the FAQ to include cmd.exe for NT systems.
Regards,
Ian
WSH FAQ http://wsh.glazier.co.nz


Quote:

> What that error means is that your %path% is bad.

> In NT, you should use cmd.exe.:

> iReturn = WshShell.Run("cmd.exe /k Dir c:\Windows\system32", 1, TRUE)

> If it's important to not have the NT command extensions available in the
> prompt, do:

> iReturn = WshShell.Run("cmd.exe /y /k Dir c:\Windows\system32", 1, TRUE)

> Do 'cmd /?' at a command prompt for more information.



> > Hello all!

> > I am trying to run a directory call from within a VBScript, and I tried
> the
> > following:

> --------------------------------------------------------------------------
> --
> > ---------------------------------------
> > set WshShell = wscript.createObject("Wscript.Shell")

> > wscript.echo "starting"
> > iReturn = WshShell.Run("command.com /K Dir c:\Windows\system32", 1,
TRUE)
> > wscript.echo "Hello"

> --------------------------------------------------------------------------
> --
> > ----------------------------------------

> > I got this script from Ian Morrish's site, but I keep getting the
> following
> > error:

> > Invalid switch
> > Specified COMMAND search directory bad
> > Too many parameters
> > Microsoft(R) Windows NT DOS
> > (C)Copyright Microsoft Corp 1990-1996.

> > F>

> > Any suggestions?



Mon, 21 Jan 2002 03:00:00 GMT  
 running DOS commands on NT using WSH
Note also that command does exist on NT, but isn't the default console
command interpretter.  The "NT DOS" executable is also not located in the
same directory.  %comspec% will evaluate to cmd.exe.


Fri, 25 Jan 2002 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Running DOS Shell in hidden window, or using vb command instead

2. using internal dos commands with shell.run ?

3. Problem using wsh.run in 95 with really long command

4. Running VB Script code on WSH using cscript on win NT

5. Problem using wsh.run method in 95 with really long command

6. Running DOS commands with JScript

7. the run command in DOS

8. run a dos command from script - how?

9. Running dos commands in vbs file

10. running DOS commands - again

11. Running DOS commands ????

12. Running dos commands, batch files

 

 
Powered by phpBB® Forum Software