Scripting Solutions with WSH and COM: Using WSC to Build a Progress Bar Dialog Box, Part 1

Alistair begins a three-part series on how to use Windows Script Components (WSC) to create a dialog box that you can use to track a script’s execution. This month, he shows you what makes up WSC and how to begin building the dialog box.

8 Min Read
ITPro Today logo

Windows Script Host—Intermediate

For the next 3 months, I'm going to show you how to create a progress bar dialog box that you can use with your scripts. The progress bar specifies both graphically and textually how a script's execution is proceeding.

One way to create this progress bar dialog box is to use Microsoft Visual Basic (VB) to create a COM object, then place the object inside a DLL. After you install and register that DLL on a machine, your scripts can call the DLL whenever you want a progress bar. Although effective, this solution requires that you write VB code and use a VB compiler.

A simpler solution is to use Windows Script Components (WSC—formerly called Scriptlets). WSC lets you create reusable COM objects in any scripting language that Windows Script Host (WSH) supports. These objects not only offer methods and properties but also support events.

This month, I show you what makes up WSC and how to begin building a progress bar dialog box. To create this progress bar dialog box, you need WSH 2.0, VBScript 5.0, and Microsoft Internet Explorer (IE) 4.0 or later. If you need any of these programs, go to http://www.microsoft.com/msdownload/vbscript/scripting.asp and download the Windows Script (WS) 5.5 set. You also need the Windows Script Component Wizard. WS 5.5 includes this wizard, but you can download it separately from the Microsoft Scripting Web site (http://msdn.microsoft.com/scripting/ default.htm?/scripting/scriptlets/default.htm). This site also contains the WSC language reference and supporting documentation.

What Makes Up WSC?
Simply stated, WSC consists of three components:

The script component runtime engine (scrobj.dll). This DLL helps dispatch COM requests to your scripts.

A set of interface handlers. Interface handlers are compiled COM components that implement specific COM interfaces. Microsoft built several interface handlers in the script component runtime engine, including the COM Automation, Active Server Pages (ASP), and IE 5.0 Dynamic HTML (DHTML) interface handlers. Other interface handlers are available as add-on components in DLLs or are embedded into specific applications. You'll be using the COM Automation interface handler for the progress bar dialog box.

Script component files. Script component (.wsc) files are .xml files that contain information about the type of COM component you want to create (i.e., the interface handler you want to use). Then, depending on the functionality the interface handler makes available, you write code in the .wsc file to implement those interfaces. For example, one of the most common types of COM components (and the one you'll be creating) is the Automation component, which is a component with properties, methods, and events that you can call from other applications. Microsoft built the low-level COM interfaces required to implement this functionality into an Automation interface handler. In your .wsc file, you define the properties, methods, and events you want to expose, and the Automation handler makes sure they're called correctly when the host application needs them. You use special XML elements to write these definitions.

What Are XML Elements?
In WSC, XML elements define the .wsc file's script component and its behavior. Because .xml files are similar to .html files, the XML elements are similar to HTML tags. A basic .wsc file might contain any number of the following common XML elements:

  • The element. If the host that will access the script component uses the Windows Registry to create an instance of that component (e.g., WSH), you need to include the element. This element lets you register your script component as an available COM component in the Registry. You don't need to include the element if the host doesn't directly use the Windows Registry when creating an instance of the script component (e.g., IE 5.0).

  • The

    This element contains the code that implements the logic of the script component, depending on what type of COM component you're creating. For example, if you're creating a COM Automation component, you declare properties, methods, and events in a element, then write the script to define them in one or more

    • The element. This element contains declarations for properties, methods, and events that your script component exposes. The declarations point to variables or functions that you define in a separate

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like