Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

June 11, 2002 12:00 AM

Scripting Solutions with WSH and COM: Extending WSH with ActiveX Controls

Windows IT Pro
InstantDoc ID #25288
Rating: (0)
Downloads
25288.zip

Microsoft designed Windows Script Host (WSH) to use ActiveX controls that support automation. However, not all ActiveX controls work with WSH (e.g., the Task Scheduler API ActiveX control I discussed in "Advanced Methods for Task Scheduling," May 2002, InstantDoc ID 24592). A developer can wrap such an ActiveX control by using Visual Basic (VB) or another compiled language. In doing so, the developer creates a new automation ActiveX control that supports WSH, and the developer creates identical interfaces, methods, and properties (with all their associated parameters) in the new automation object. A WSH script can then call a method in the new automation object, and that object will call the identical method in the original nonautomation object and pass all parameters to the nonautomation object.

The developer must have the appropriate tools to wrap the original ActiveX control. Even then, this approach isn't always viable (e.g., the ActiveX control's contents might not be built for WSH scripting, preventing you from wrapping the ActiveX control). Fortunately, many automation ActiveX controls do work with WSH.

In the next few columns, I'll show you how to use several practical components from the Internet to extend WSH. To kick things off, I introduce you to an ActiveX control, Woodchop Software's GooeyScript, that lets you quickly create event-driven forms. I offer a brief overview of ActiveX controls, describe scripting with GooeyScript, then walk you through the process of scripting event-driven forms.

Understanding ActiveX Controls
Authors sometimes develop ActiveX controls that rely on VB runtime components. Usually, the controls call the methods or properties of core VB runtime DLLs. As a result, you must download and install these runtime components on each client PC on which you want to use the control. You can download the VB 6.0 runtime DLLs from http://www.microsoft.com/downloads/release.asp?releaseid=28337&area=search&ordinal=22 and download the VB 5.0 runtime DLLs from http://www.microsoft.com/downloads/release.asp?releaseid=12651&area=search&ordinal=9.

You must copy all ActiveX controls to the client PC that will use them and register them in the client PC's registry to make the controls available to your programs and scripts. To register ActiveX controls, you must call regsvr32.exe and specify the path to the control. For example,

regsvr32 /u /s c:\windows\system32\mynew.dll

references the mynew.dll control. The /s switch silences the reference, and the /u switch indicates that you want to unregister the ActiveX control later, in case you want to remove references to the control from the registry.

Occasionally, the author of an ActiveX control will create an ActiveX executable (.exe file) rather than an ActiveX DLL because of the out-of-process threading model that ActiveX executables use. Whereas executables can spawn their own process, DLLs execute within the same process from which they're called. For example, GooeyScript is an out-of-process ActiveX executable: The script and the form run in separate processes, so the script executes while a form gathers or displays information. Although you can register an ActiveX executable with regsvr32.exe the same way you register a DLL, you would typically use the ActiveX executable's built-in registration capabilities (i.e., /regserver), as the following example shows:

GooeyScriptDemo.exe /regserver

Scripting with GooeyScript
Lee Carlson designed GooeyScript for WSH. You can download GooeyScript from http://www.woodchop.com. The demo version is full-featured except that it displays a splash screen for 10 seconds every time you open a new dialog box. To remove the splash screen, you must purchase the ActiveX control, at a cost of $1 per client (in blocks of 50 clients). However, I think this ActiveX control is worth the money.

Several Windows Scripting Solutions authors have offered better methods than Message Box and Input Box to create dialog boxes to use with WSH. Dino Esposito introduced an ActiveX control that he wrote to create dialog boxes. Several other authors and I have described how to use Microsoft Internet Explorer (IE) to create custom dialog boxes and progress bars. For a list of these articles, see "Related Articles in Previous Issues" on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com, InstantDoc ID 25288). GooeyScript is a superbly customizable option.

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.