Welcome to the first of many columns about Windows Script Host (WSH). In this column, I discuss what tasks you can automate with WSH when you complement it with other scripting technologies. (If you're unfamiliar with the various scripting technologies, see Dino Esposito, "An Introduction to Scripting Technologies and Object Models," May 2000.) I also discuss where you can download WSH and find some useful WSH resources.

An Important Technology
Although many scripting technologies exist, WSH is one of the most important technologies for several reasons

WSH provides versatility. WSH provides an environment that lets you use different scripting technologies in the same script. In other words, WSH is the glue that you can use to combine various scripting technologies.

WSH is economical. You don't need to purchase any new software to write WSH scripts. You can simply use your favorite text editor. However, if you want a more sophisticated development environment, a variety of third-party products are available for use with WSH.

WSH is language independent. By default, WSH interprets JScript (through the jscript.dll interpreter) and VBScript (through the vbscript.dll interpreter). However, you can easily enhance WSH to support other scripting languages, such as Perl.

WSH provides two ways to execute scripts. With WSH, you can execute any script that has a .wsf, .vbs, or .js extension by either double-clicking the script or typing an execution command. These two options are possible because WSH has two runtime execution environments that take the script and pass it through the relevant interpreter (i.e., jscript.dll or vbscript.dll). These environments output the results to either the 32-bit Windows environment (through wscript.exe) or the command-line environment of a command-prompt window (through cscript.exe). By default, if you double-click a script such as MyScript.vbs, the system passes that script to wscript.exe, just as if you had manually typed

wscript.exe MyScript.vbs

at the command line. You can change the default interpreter for all scripts or on a per-script basis.

WSH comes with an object model. WSH comes with an object model containing objects that let you run programs; read from and write to the Registry; create and delete files and shortcuts; manipulate the contents of files; read and write environment variables; map and remove drives; and add, remove, and set default printers. Because you can access these objects, you can write logon scripts in VBScript, JScript, or other COM-compliant languages such as Perl to configure users' environments.

WSH lets you use other COM objects. WSH's real power lies in its ability to use other COM objects to access and manipulate your system. You can think of WSH and COM as a series of LEGO sets. The basic LEGO set provides you with the essential blocks and connectors you need to build a variety of fun projects, such as a car or house. Similarly, WSH provides you with the essential blocks (i.e., objects in the WSH object model) and connectors (i.e., VBScript and JScript) you need to build scripts. The WSH objects let you perform a variety of useful OS actions, such as manipulating Registry entries, files, and environment variables. VBScript and JScript let you perform a variety of useful scripting actions, such as manipulating strings, declaring variables and constants, and using conditional loops. It doesn't matter which language you use because VBScript and JScript have the same basic functionality.

After you know how to use the basic LEGO set, you'll likely want to build bigger and better projects. To build these projects, you need specialty LEGO sets. For example, if you want to build remote-controlled cars, you need the LEGO Remote Control Cars component. If you want to build a spaceship, you need the LEGO Mission Control component. The same holds true for WSH and COM in that you need to use the set of COM components that are appropriate for the task you want to perform. For example, if you want to automate databases, you need the set of components called ActiveX Data Objects (ADO). If you want to automate messaging and collaboration, you need the set of components called Collaboration Data Objects (CDO) or CDO for Windows NT Server (CDONTS). If you want to automate access to management information, you need the set of components called Windows Management Instrumentation (WMI).

In future columns, I'll show you how to effectively and efficiently apply those sets of COM components that are commonly used with WSH to automate tasks in Windows 2000 (Win2K), NT, and Microsoft Office 2000 applications. The components I'll cover include Active Directory Service Interfaces (ADSI), ADO, CDO, CDONTS, and WMI.

In addition, I'll cover which development environments are best for scripting. If you write a lot of scripts, a sophisticated development environment can help you develop your scripts, highlight bugs during coding, and reduce your development time. I use the feature-rich WSH development environment PrimalSCRIPT 2.0 from SAPIEN Technologies. I'll discuss the advantages and disadvantages of PrimalSCRIPT and some of its contenders.

If you want me to cover any other areas or aspects of scripting, please let me know. You can email your requests to me at alistair@win2000mag.com.

Where to Obtain and Learn About WSH
To use WSH, you need a set of components called Windows Script. WS 5.1 is the most recent version and contains WSH 2.0, VBScript 5.1, JScript 5.1, Windows Script Components (WSC), and Windows Script Runtime 5.1.

Win2K includes WS 5.1, and Windows 98 includes WS 5.0. If you want to upgrade Win98 to WS 5.1 or install WS 5.1 on NT 4.0 or Win95 servers and workstations, go to http://www.microsoft.com/msdownload/vbscript/scripting.asp and download the relevant files.

You need to install WS 5.1 on the PC or server from which you'll be running your scripts. After installing it, you can run scripts that will automate tasks on the 10, 100, or 1000 machines connected to that one PC or server. You don't have to install WS 5.1 on each connected machine.

Next month, I'll introduce you to some easy-to-deploy WSH-WMI solutions. In the meantime, if you want to learn about WSH or another scripting technology, check out the sites in the sidebar "Web Scripting Resources," page 7.