Run an external Command, returning an object.
Syntax objShell.Exec (strCommand) Key objShell A WScript.Shell object 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 objShell,oExec Set objShell = wscript.createobject("wscript.shell") Set oExec = objShell.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
.Run - Run a command
Execute - Execute one or more statements
.ShellExecute - Run an application in the Windows Shell
Run with elevated permissions - Script to run as Admin
cscript - Run a VB Script .vbs file
Equivalent Windows CMD command: START - Start a specified program or command
Equivalent PowerShell cmdlet: Run/Call - Run a command