Export (0) Print
Expand All

WScript Object

Microsoft® Windows® 2000 Scripting Guide

The WScript object provides a wide range of capabilities to WSH scripts regardless of the language in which that script is written. As such, the WScript object ensures that a WSH-compliant language will always be able to carry out such key tasks as binding to COM objects and parsing command-line arguments.

Depending on the scripting language you use and the task you have chosen, you might or might not need to use the WScript object. For example, VBScript includes a GetObject function that allows your script to bind to COM objects. Because the syntax of the VBScript GetObject function is slightly simpler, you will likely use it rather than the WScript equivalent.

On the other hand, VBScript does not include functions for parsing command-line arguments. Fortunately, you can still use command-line arguments within VBScript; you simply make use of the argument parsing functionality provided by the WScript object. This ability to mix and match methods from WSH with methods and functions from the scripting language is one primary advantages of using WSH as a scripting environment.

Figure 3.3 shows the properties and methods of the WScript object as well as the properties and methods of the WshArguments, WshUnnamed, and WshNamed collections, all of which are accessed through the WScript object.

Figure 3.3 WScript Object Model

sas_wsh_60c

Accessing the WScript Object

The WScript object is available to all WSH scripts without the script needing to bind to the object. No call to the WScript CreateObject method is required prior to using WScript properties and methods. This means you can use WSH functions such as Echo or Sleep without having to bind to the WScript object; as a result, this single line of code is a perfectly valid WSH script:



Wscript.Echo "No binding required."

The WScript object is always available for one reason: CreateObject and GetObject are methods found within this object. If the WScript object were not always available, neither CreateObject nor GetObject would be. Thus, you would not be able to bind to any COM object (including the WScript object).

WScript Capabilities

The primary purpose of the WScript object is to provide your script with basic functionality as opposed to carrying out a particular system administration task. In other words, you will not find the capability to manage services or event logs; instead, you will find capabilities that enable you to bind to other objects that can be used to manage services or event logs.

Table 3.3 lists the capabilities provided by the WScript object, along with the methods and properties that your scripts can use to access this functionality. Each of these methods and properties is explained in more detail in subsequent sections of this chapter.

Table 3.3 Capabilities Provided by the WScript Object

Category

Methods or Properties

Using COM objects

CreateObject, GetObject

Handling input and output

Echo, StdOut, StdIn, StdErr

Working with command-line arguments

Arguments

Controlling script execution

Quit, Sleep, Timeout, Interactive

Obtaining WSH environment info

Application, BuildVersion, FullName, Name, Path, ScriptFullName, ScriptName, Version

Handling events

CreateObject, GetObject, ConnectObject, DisconnectObject

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft