As many a Mac or UNIX devotee will tell you, one of Windows’ weaknesses is its lack of a built-in scripting language. So, admins must write BAT files—and lose their hair prematurely—to accomplish automation. Enter the Windows Scripting Host (WSH). WSH allows language-independent access to Windows system functions via script programs run on the desktop. WSH ships with Windows 98, NT Option Pack 4, and Windows 2000 with support for Visual Basic Scripting Edition (VBScript) and Microsoft’s Java-based scripting language, JScript.

I am object, hear me roar
Of course, before you can start using WSH, you’ll need at least a conceptual idea of what an object is. Objects expose the outside world to WSH scripts by defining and allowing access to the file system, network, databases, and Web sites. Objects usually model processes and store internally whatever information is required to complete a given task. For example, an object that modeled an automated car wash would likely have a “method” of washing a car and would have “properties” that stored the cost of a basic wash and that of a wash and wax, along with the number of quarters a customer had inserted into the coin slot.

The WSH creates and exposes one object for you automatically: the Wscript object. This provides the executing script with a degree of self-awareness, exposing such information as the path and name of the script file that’s currently executing and the list of command line arguments that were passed to the script. It also serves as a starting point for other built-in scripting objects.

The CreateObject keyword is implemented as a method of the Wscript object and is the ladder that provides WSH scripts with their extensibility. Everything from creating a shortcut to opening a database is accomplished using this keyword. CreateObject needs to know two things: the library the object lives in and the name of the object it’s creating. All the objects we’ll cover in this two-part article (except the FileSystem object) are in the Wscript library. For example, to use the wshNetwork object, one would call CreateObject(“Wscript.Network”).

She sells sea shells
The WshShell object is implemented as a “child object” of the Wscript object and has the richest functionality of any built-in WSH functionality. It allows a script to launch other applications or scripts and access environment settings previously available only to full-blown programmers via API calls using the WshShell’s Environment object. Its SpecialFolders object allows access to the names of special system folders such as the Desktop. Two child objects allow scripts to create regular (WshShortcut) and Web (WshURLShortcut) shortcuts. In conjunction with access to system special folders, this is powerful stuff.

Useful Special Folders
Desktop User’s Desktop
Fonts Fonts folder
MyDocuments User’s My Documents folder
NetHood Network Neighborhood
AllUsersDesktop Not well documented but appears to be the Guest or default user’s desktop on Windows NT.
Returns Null on 9x.
SendTo The Windows SendTo folder

Keep an eye out next week for a look at some scripts that create popup dialog boxes for users, methods for retrieving network information, and FileSystem objects.