Overview Of The New Windows Scripting Host 5.6 - Let's Get This Show On The Road
(Page 5 of 7 )
There are two programs that we'll be dealing with in the following sections. The first is WScript.exe, which is the graphical version of WSH. It provides a standard Graphical User Interface (GUI) to set properties. The second is its command-line cousin, CScript.exe, which uses switches (such as //I and //B) to do the same thing. The differences between the two programs are more than just the difference between getting the output from a pop up window or a command prompt. In fact, there are certain advantages to both, which I'll discuss shortly.
As far as WScript.exe is concerned, there's not really much to tell. To see a script's properties you do what you always do to check the properties of a file: Right click on the file -> Properties. What you will notice is that in FAT and FAT32 environments you'll only get two tabs (General and Script), while in NTFS environments you'll get a third (Summary) and possibly a fourth (Security), depending on your configuration. When properties are set on a script, a text file by the name of the script and with a .wsf extension is created. This file is used as a control file for the scripts settings and can be used to launch the script.
A bit more interesting is the CScript.exe file, which you'll need to run from a command prompt. The syntax of the command is as follows:
cscript [scriptname.extension] [options...] [arguments...]
Under most circumstances, of the three bracketed options, only the script name is required. Just typing cscript will display the command page. Speaking of which, here's the list of commands:
//I
Default setting: Interactive mode (opposite of //B)
//B
Batch mode: Suppresses script errors and prompts from displaying.
//D
Enables active debugging.
//E:Engine
Use a certain engine for executing scripts. This is useful because it allows you to run scripts with custom file name extensions. Example: cscript
//E:vbscript test.admin
The advantage of doing this is that it guards against accidentally double clicking and running a script you didn't want to run.
//Job:xxxx
Executes a WSF job
//T:nn
Time out in seconds. Maximum amount of time a script is allowed to run (default is indefinitely).
//logo
Default: displays a logo banner.
//nologo
Suppresses the logo banner. This is often used by scripts that output to a file which needs to be parsed or used as the control document for another script.
//H:cscript
Changes default to CScript.exe.
//H:wscript
Changes default to WScript.exe (this is the default).
//S
Save the command line options. For example, if you never want to see the logo, then you would type the following: cscript hello.vbs //nologo //S.
As I mentioned before, there are certain advantages to using either the GUI or CLI versions of WSH. The biggest advantages are in favor of the CLI (CScript.exe), which allows you to exercise greater control over how a file should be run and interpreted. Running scripts under CScript enables them to run an external program and retrieve the output from the program. The biggest advantage of the GUI is that it doesn't take more than a twitchy finger to launch a script which will show you your output in a nice little pop-up box. Unfortunately, this becomes annoying when you have a script which is intended to prompt hundreds of times, such as an event log script. Instead, CScript neatly displays retrieved data in a command window.
Next: Example Scripts >>
More Windows Scripting Articles
More By Norbert Cartagena