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

Alistair continues his discussion about how to use Windows Script Components (WSC) to create a progress bar dialog box. This month, he shows you how to manually create a .wsc file and how to create this file with the Windows Script Component Wizard.

Alistair G. Lowe-Norris

September 26, 2000

6 Min Read
ITPro Today logo in a gray background | ITPro Today


Last month, I showed you the components in Windows Script Components (WSC—formerly known as Scriptlets). One of those components—the script component (.wsc) file—contains XML elements. This month, I show you how to use the XML elements to build a .wsc file that creates the ProgressDialogBox object and its methods and properties. First, I manually create this .wsc file to help you understand the concepts. Then, I introduce an easier way to create this file with the Windows Script Component Wizard.

Manually Creating a .wsc File
The progress bar dialog box that you're creating lets you know both graphically and textually how a script's execution is proceeding. To create the progress bar dialog box, you need to build a COM Automation interface—that is, a COM object that exposes methods and properties for use in a script. Thus, you need to use the element to flag the declarations for the methods, properties, and events that your script component exposes. As callout A in Listing 1, page 2, shows, you need to place the tag before the first declaration and the tag after the last declaration.

You use the , , and elements to declare the script component's methods, properties, and events, respectively. The code in callout A is declaring the ProgressDialogBox object's methods, properties, and events that Table 1 outlined in Part 1. In the declarations, note that the property declarations include the element. This element specifies that a property is write-only. If you want a read-only property, you use the element.

With the declarations in place, you now need to define the declared methods, properties, and events. The code at callout B in Listing 1 defines ProgressDialogBox's methods, properties, and events.

Enclosing the declarations and definitions are the and elements, which detail the script component's ID and registration data. The registration data is necessary so that you can register the script component as a COM component with a program such as regsvr32.exe. Registration places information about the script component in a public location; in Windows OSs, the Registry stores the registration information. Host applications read the registration information to find and load the script component. The most important information for registration is the programmatic identifier (ProgID), which is the name the host applications use when creating an instance of the WSC object.

The template in Listing 1 isn't difficult to write, but it's missing some basic XML elements. For example, the template doesn't include code to specify whether you can debug the script component, whether the script component can generate errors, and the script component's version number. But perhaps most important is that the template doesn't include the class ID. The class ID is a globally unique ID (GUID) that identifies the script component. Using GUIDs is a good idea because you're less likely to have computer conflicts if other objects you download or install have the same object name as your WSC object.

Although you can use a program such as the Microsoft Windows 2000 Resource Kit utility uuidgen.exe to manually generate a GUID then add it to the .xml file, an easier way is to use the Windows Script Component Wizard or a Windows Script Host (WSH) editor such as PrimalScript to create the .xml file. The wizard and PrimalScript automatically generate class IDs and include debugging, error, and other elements, providing you with a more fully featured .xml file. Let's look at how you use the wizard. (I'll cover how to use PrimalScript in a future column.)

Automatically Creating a .wsc File with the Wizard
The Windows Script Component Wizard is a free program that you can download from the Microsoft Scripting Web site. Windows Script (WS) 5.5, which you can download from http://www.microsoft.com/msdownload/vbscript/scripting.asp, includes the wizard.

The Windows Script Component Wizard automates the process of creating a .wsc file. The wizard performs these basic functions:

  • Creates the .wsc file, and adds the basic XML elements

  • Creates the registration code

  • Specifies the type of interface handler you want the script component to use

  • Creates the necessary elements for the properties and methods you want to expose in the scripting language you specify

  • Creates the skeleton event elements for the events you want the script component to fire

Let's look at how to use the Windows Script Component Wizard to create the .wsc file for the progress bar dialog box. To create this file, just follow these six easy steps:

  1. Specify the basic information for the script component you want to create. As Figure 1 shows, this information consists of the name of the script component, the filename of the .wsc file, the ProgID (anyone or anything using your component will need to reference this ID), the version number, and the location in which you're creating the component. Click Next to continue.

  2. Specify the language you want to use. In this case, you want to use VBScript, as Figure 2 shows. If you were using an Active Server Pages (ASP) or Dynamic HTML (DHTML) interface rather than a COM Automation interface, you would select that interface under the Do you want special implements support? option. In this step, you can also specify whether you want to enable error checking and debugging. Click Next to continue. At this point, you've entered most of the information from the code preceding callout A in Listing 1.

  3. Enter the data about your script component's properties. In this case, enter the ProgressDialogBox object's four properties, as Figure 3 shows. Use the drop-down list in the Type column to specify whether each property is read-write, read-only, or write-only. Although none of the ProgressDialogBox object's properties have default (i.e., initial) values, you can enter such values in the Default column. Click Next to continue.

  4. Enter the data about your script component's methods. In this case, enter the ProgressDialogBox object's Open and Close methods. Although the Close method doesn't have any parameters, the Open method has five parameters, as Figure 4 shows. Enter these parameters as comma separated values (CSVs) in the Parameters column. Click Next to continue.

  5. Specify the events to which your script component will react. In this case, enter Cancel, as Figure 5 shows. Click Next to continue. You've now entered most of the information from the code in callouts A and B in Listing 1.

  6. Review the data you've entered, scrolling down if necessary. Figure 6 shows an example of the window you'll see, except that I manually cut and pasted two screen shots together so that you could see all the data in one window. If you see a mistake in the data, click Back until you reach the step in which you need to make the correction. If all the information is correct, click Finish to create the script component.

When the wizard finishes, you'll have a .wsc file similar to that in Listing 2. Although I produced this file with PrimalScript, it's very similar to one the wizard would generate.

Next Time
The Windows Script Component Wizard lets you easily create the .wsc file for the script component. In the December 2000 issue, I'll show you how to complete the script component and put it to good use.

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