A hands-on guide to using WSH
Windows Scripting Host (WSH) is a new Microsoft technology that is sure to become extremely popular because of its versatility. WSH lets Windows NT host any Microsoft ActiveX scripting language, including Visual Basic Script (VBScript) and JScript (Microsoft's implementation of the ECMAScript scripting language, formerly known as JavaScript). WSH also lets NT host third-party ActiveX scripting languages, such as ActiveState Tool's PerlScript (http://www.activestate.com).
WSH is a general-purpose, scripting-enabling tool. With the base WSH object model and a scripting language, you can create scripts that automate common setup, configuration, and administrative tasks, including:
- Reading and writing variables in your directory services
- Creating shortcuts for users on their desktop
- Accessing special folders, such as Desktop, Start Menu, Favorites, and My Documents
- Mapping network shares
- Mapping and setting default printers
- Reading, writing, and deleting Registry keys
- Launching programs
The base WSH object model consists of five types of objects: WScript, WshShell, WshNetwork, WshShortcut, and WshUrlShortcut. As Table 1, page 124, shows, each object type has certain properties and methods that define it. (If you are unfamiliar with the component object modelCOMconcept and ActiveX objects, see http://www.microsoft.com/activex.)
Two of the WScript object's methodsGetObject and CreateObjectwork with any ActiveX object servers (including NT 5.0's ActiveX Directory Objects) registered on the local system. Thus, you can use WSH to access other object servers, such as Active Directory Services Interface (ADSI), Internet Explorer (IE), and Microsoft Office. With WSH and these object servers, you can set passwords, add users and organization units, initialize a browser, and manipulate and print documents.
Microsoft will integrate WSH into Windows 95 updates, NT 5.0, and the NT Option Pack. You can download WSH from Microsoft's Web site (http://www.microsoft.com/management/wsh.htm) for use with Win95 and NT 4.0.
The WSH package is surprisingly small, consisting of two separate scripting hosts, three support DLLs, six sample scripts, and a Help file. The two scripting hostscommand shell (cscript.exe) and Windows shell (wscript.exe)let you run scripts from a command line and from the Windows environment, respectively. The command-shell host is particularly useful when you combine it with traditional command-line options, such as piping the output to a text file or other device. The Windows-shell host uses message boxes to display output information (unless you use an additional ActiveX component to handle the file I/O). The following simple examples show how you can use these two scripting hosts.