Runs a program in a new process.
|
---|
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) |
Arguments
- object
WshShell object.
- strCommand
String value indicating the command line you want to run. You must include any parameters you want to pass to the executable file.
- intWindowStyle
Optional. Integer value indicating the appearance of the program's window. Note that not all programs make use of this information.
- bWaitOnReturn
Optional. Boolean value indicating whether the script should wait for the program to finish executing before continuing to the next statement in your script. If set to true, script execution halts until the program finishes, and Run returns any error code returned by the program. If set to false (the default), the Run method returns immediately after starting the program, automatically returning 0 (not to be interpreted as an error code).
Remarks
Example 1
The following VBScript code opens a copy of the currently running script with Notepad.
| Copy Code |
---|
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad " & WScript.ScriptFullName |
The following VBScript code does the same thing, except it specifies the window type, waits for Notepad to be shut down by the user, and saves the error code returned from Notepad when it is shut down.
| Copy Code |
---|
Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true) |
Example 2
The following VBScript code opens a command window, changes to the path to C:\ , and executes the DIR command.
| Copy Code |
---|
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:\ & Dir"
Set oShell = Nothing |
See Also