- Understanding Windows Script Host
- Introducing Script Files
- Running Script Files Directly
- Using WScript for Windows-Based Scripts
- Using CScript for Command-Line Scripts
- Script Properties and .wsh Files
Using WScript for Windows-Based Scripts
The .vbs and .js file types have an open method that's associated with WScript (WScript.exe), which is the Windows-based front-end for the Windows Script Host. In other words, launching a script file named, for example, MyScript.vbs is equivalent to entering the following command in the Run dialog box:
wscript myscript.vbs
The WScript host also defines several parameters that you can use to control the way the script executes. Here's the full syntax:
WSCRIPT [filename] [arguments] [//B] [//D] [//E:engine] [//H:host] [//I] [//Job:xxxx] [//S] [//T:ss] [//X]
filename |
Specifies the filename, including the path of the script file, if necessary. |
arguments |
Specifies optional arguments required by the script. An argument is a data value that the script uses as part of its procedures or calculations. |
//B |
Runs the script in batch mode, which means script errors and Echo method output lines are suppressed. |
//D |
Enables Active Debugging. If an error occurs, the script is loaded into the Microsoft Script Debugger (if it's installed), and the offending statement is highlighted. |
//E:engine |
Executes the script using the specified scripting engine, which is the scripting language to use when running the script. |
//H:host |
Specifies the default scripting host. For host, use either CScript or WScript. |
//I |
Runs the script in interactive mode, which displays script errors and Echo method output lines. |
//Job:id |
In a script file that contains multiple jobs, executes only the job with id attribute equal to id. |
//S |
Saves the specified WScript arguments as the default for the current user; uses the following Registry key to save the settings: |
HKCU\Software\Microsoft\Windows Script Host\Settings |
|
//TT:ss |
Specifies the maximum time in seconds (ss) that the script can run before it shuts down automatically. |
//X |
Executes the entire script in the Microsoft Script Debugger (if it's installed). |
For example, the following command runs MyScript.vbs in batch mode with a 60-second maximum execution time:
wscript myscript.vbs //B //TT:60