Exec Method (Windows Script Host) Home
This page is specific to:.NET Framework Version:2.03.0
Windows Script Host
Exec Method (Windows Script Host)

Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.

object.Exec(strCommand)
Arguments

object

WshShell object.

strCommand

String value indicating the command line used to run the script. The command line should appear exactly as it would if you typed it at the command prompt.

Remarks

The Exec method returns a WshScriptExec object, which provides status and error information about a script run with Exec along with access to the StdIn, StdOut, and StdErr channels. The Exec method allows the execution of command line applications only. The Exec method cannot be used to run remote scripts. Do not confuse the Exec method with the Execute method (of the WshRemote object).

Example

The following example demonstrates the basics of the Exec method.

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("calc")

Do While oExec.Status = 0
     WScript.Sleep 100
Loop

WScript.Echo oExec.Status
var WshShell = new ActiveXObject("WScript.Shell");
var oExec = WshShell.Exec("calc");

while (oExec.Status == 0)
{
     WScript.Sleep(100);
}

WScript.Echo(oExec.Status);


Applies To:

See Also

Reference

Community Content

The example is wrong
Added by:Thomas Lee

CALC is not a command-line application.

[tfl - actually it's calc.exe, calculator, which is indeed an application]. This article is not in error.
© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View