Running WSH Scripts

Microsoft® Windows® 2000 Scripting Guide

If you were to ask a group of people how to start Microsoft Word, you would likely get a number of different answers. After all, you can start Word by clicking the Start menu and then clicking Microsoft Word, or by typing winword.exe in the Run dialog box. Some people might start Word from the command prompt, some from the Quick Launch bar, and others by using a keyboard shortcut. You can also start Word implicitly, by double-clicking a file with the .doc file name extension. Regardless of the method employed, in each case the end result is the same: Microsoft Word will run. Whether or not one method is better than another depends on such factors as convenience, personal preference, and individual needs (for example, whether you want a specific document to be loaded when Word starts).

There are also many ways of running WSH scripts. For example, some system administration scripts are run as logon scripts or scheduled tasks. In that respect, you do not actually run these scripts; you simply schedule them and let the operating system run them for you. Scripts that are not run on a regular basis or that require user interaction can be run either from the command line or by using the Windows graphical user interface (GUI). In some cases it makes no difference how these scripts are run. In other cases, it makes a very big difference.

While you are working through the examples in this chapter, it is recommended that you run the scripts from the command line using CScript (unless otherwise indicated). Often times it makes no difference which script host you use to run a script. However, many system administration scripts should be run under CScript, the console-based script host, for at least two reasons.

For one, running your scripts under CScript enables them to run an external program and retrieve the output from the program. Perhaps more important, though, returned data is displayed in a command window rather than in a series of message boxes. This is particularly useful for scripts that might return hundreds of items of data, such as scripts that retrieve events from the event logs.

The next few sections of this chapter will discuss the ins and outs of running scripts in more detail.