Running WSH Scripts
Typically, WSH scripts have a file
extension of .vbs
(if they are written in VBScript) or
.wsf
(a Windows Script File, which contains
XML elements along with script written in a language defined by the
XML <SCRIPT>
tag), both of which are associated with
the Windows Script Host executable in the registry. This allows the
user to simply double-click on the file in an Explorer window in
order to execute the script. If the script is a
.wsf
file containing multiple jobs, only the
executable script in the first job (which must be delimited by the
<job>...</job>
tags) is executed.
It is also possible to run a script from the command line by using the syntax:
CScript.exe filename [//options
] [/arguments]
or from the Run dialog or a Windows shortcut by using the syntax:
WScript.exe [//options
] [/arguments]
where //
options
is one
or more of the WSH features shown in Table 7.1, each of which must be preceded by
double slashes.
Table 7-1. WSH Options Switches
Switch |
Description |
---|---|
|
Batch mode (prevents script errors and user interface elements such
as those produced by the |
|
Enables debugging. Automatically launches the debugger if an unhandled exception occurs. |
|
Uses |
|
Changes the default script host to |
|
Changes the default script host to |
|
Interactive ... |
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.