Why Use WSH?

WSH exposes a relatively small but very significant portion of the functionality of the 32-bit Windows family of operating systems. In addition, WSH allows you to tap into other object models (such as the FileSystemObject object model provided by the Scripting Runtime library) that allow you to access additional features of either the operating system or individual applications.

The advantage of any script is that it allows repetitive tasksincluding complex ones that require multiple stepsto be performed more or less automatically. This makes scripting suitable for batch operationsthat is, for repetitive operations that do not require user intervention. In addition, if you are writing your scripts in VBScript, you can allow user interaction through the standard VBScript InputBox andMsgBox functions, as well as by instantiating components that support more sophisticated forms of interaction. Support for user interaction enhances the scripting environment's flexibility and increases the range of applications for which it is suitable.

Although the flexibility and power of WSH means that its actual uses are limited only by the imagination, we can nevertheless identify some areas in which WSH clearly excels:

Access to network resources

Although Windows makes automatic (and therefore more or less permanent) access to network resources at logon very easy, transitory access to network resources is not. WSH can be used to connect to network drives and printers for a short period, perform some operation, and then disconnect from the network resource.

System administration

A single script that is run locally on the user's machine or that is run from the system administrator's system and iterates network systems can enormously facilitate the tasks of administering a networked system.

Simple installation scripts

If your installation routine needs merely to check available disk space, determine whether any files are likely to be overwritten, copy some files, and add some registry settings, writing a WSH script can be as effective as a professional installation program while involving much less overhead.

File operations

By instantiating the FileSystemObject object, you can gain access to the local computer's filesystem, including attached network drives. This allows you to perform repetitivefile operations, as well as to determine the status, capability, and storage space available on individual drives.

Software automation

Using WSH and VBScript, you can access the object model of an application program or a system service to perform some repetitive operation. For instance, you might use CDO to send a batch of emails with Microsoft Outlook, use Microsoft Word and Access to print mailing labels, or use Microsoft Excel to update monthly sales data and print the results in chart form.

Vbscript in a Nutshell
VBScript in a Nutshell, 2nd Edition
ISBN: 0596004885
EAN: 2147483647
Year: 2003
Pages: 335
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net