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!