WshShell.Exec

Run an external Command, returning an object.

Syntax 
      WshShell.Exec (strCommand) 

Parameters 
   strCommand  :  The Command to be executed
   

Unlike .Run method, .Exec returns an object which returns additional information about the process started.

Example - run the calculator (calc.exe) and display the exit code:

Dim WshShell,oExec

Set WshShell = wscript.createobject("wscript.shell")
Set oExec = WshShell.Exec("calc.exe")

WScript.Echo oExec.Status
WScript.Echo oExec.ProcessID
WScript.Echo oExec.ExitCode 

The .ExitCode property returns the exit code set by the program (calc.exe) when it exits.

.Exec gives the ability to access the standard streams of the executable and allows read/writes to the process's stdout/stderr in real-time while the process executes.

while(!Pipe.StdOut.AtEndOfStream)
WScript.StdOut.WriteLine(Pipe.StdOut.ReadLine())

------------
.Terminate
Instructs the script engine to end the process.

note - this type of process kill does not clean up properly
and may cause memory leaks - use only as a last resort!

“First rate people hire other first rate people. Second rate people hire third rate people. Third rate people hire fifth rate people. - André Weil”

Related:

.Run command
cscript - Run a VB Script .vbs file
Equivalent Windows CMD command: START - Start a specified program or command
Equivalent Powershell command: Run - Run a command



Back to the Top

© Copyright SS64.com 1999-2012
Some rights reserved