Stuff
OS/400 Edition
Volume 1, Number 13 -- July 18, 2002

Access Windows Control Panel Using VBScript


by Shannon O'Donnell

[The code for this article is available for download.]

display

Since I'm on an HTML kick lately, I thought I might show you how to do a few unusual, yet nifty, things using HTML and VBScript. In this column, I'll show you how to access the now-familiar Windows SHELL command via VBScript to open various options in the Windows Control Panel.

CPL Does Not Stand for "Corporal"

Of course, anyone can click the Windows Start button and then select the Settings menu item, followed by the Control Panel menu item to get to the Control Panel. But what if you wanted to give your users access to only certain Control Panel items via a Web page? Can you do it?

Of course you can! To accomplish this feat, we'll use the power of VBScript and the Windows Control Panel application named Control.exe.

Control.exe will open Windows Control Panel. You can try it yourself; just click Start, then Run, and enter the following command:

rundll32.exe url.dll,FileProtocolHandler control.exe

This command will open the Windows Control Panel just as if you'd opened it via the menu items detailed above. So how do you only open the Control Panel items you need? You do it by passing the name of the appropriate .cpl file to the Control.exe application. CPL stands for "Control Panel," and it's a special type of file that provides access to the specific ActiveX (or COM) object that points to each Control Panel item.

VB Script and HTML

Take a look at the HTML file named CPOps.html. This HTML file uses VBScript. If you've been following my HTML articles in recent months, then you know that so far all I've talked about has been JavaScript. But before there was JavaScript, there was VBScript (at least I think it was before, although if I'm wrong I'm sure I'll hear about it!).

VBScript is, functionally, exactly like JavaScript. You access it the same way, and, for the most part, you code it the same way. The biggest difference between them, as illustrated in our example, is how you define ActiveX objects, such as the SHELL ActiveX object.

In JavaScript, you specify something like the following:

var oShell = new ActiveXObject("Shell.Application");

And then you execute it with a line such as this:

oShell.ShellExecute ("YOURPROGRAM.exe", parms, "", "open", "1");

In VBScript, you first need to define the ActiveX object using the HTML <OBJECT> tag:

<OBJECT ID="oShell"
    CLASSID="clsid:13709620-C279-11CE-A49E-444553540000">
</OBJECT>

Because of the CLASSID parameter, this probably looks a lot more complicated than simply specifying the ActiveX name, as you do with JavaScript. But don't let that scare you. Every ActiveX object has a unique CLASSID to identify it to Windows, and it's pretty easy to find. If you're not sure what the CLASSID is of a particular ActiveX object you want to use, you can find out by scanning for the ActiveX object name in the Windows Registry. The CLASSID of that object will be shown when you find the ActiveX object.

To execute an ActiveX command via VBScript, you use the following syntax:

oShell.ControlPanelItem ControlPanelParm

ControlPanelItem is the internal SHELL method you want to execute and ControlPanelParm is the parms (if any) you need to pass to that method.

Here are some of the other SHELL methods:

  • oShell.MinimizeAll--Minimizes all windows on the desktop.
  • oShell.FileRun--Displays the Run dialog box.
  • oShell.ShutdownWindows--Displays the Shut Down Windows dialog box.
  • oShell.FindFiles--Displays the Find dialog box.
  • oShell.SetTime--Displays the Date/Time dialog box.
  • oShell.Explore "C:\My Documents"--Explores a given directory.
  • oShell.BrowseForFolder 0, "My Programs", 0, "C:\Program Files"--Enables user to select a folder from Program Files.
  • oShell.Open "C:\WINDOWS\Favorites"--Opens the Favorites folder.
  • oShell.TrayProperties--Displays taskbar properties.
  • oShell.ShellExecute "C:\ NOTEPAD.EXE", "", "", "open", "1"--Executes commands.

In the HTML example, I'm using the oShell.ControlPanelItem, passing it the name of a specific CPL file. Depending on which CPL file I pass to the VBScript function named controlPanelFunction, I will allow the Control Panel to be opened to a selected Control Panel item.

The World Is Your Oyster

OK, save the HTML and try it out. You should be able to open up most of the options I've shown in the sample. Some of the CPL files I reference may not exist on your PC, but that's OK. You can easily substitute your own CPL files for the ones I use in this example. The easiest way to find out what CPL files are available to you is to use the Windows Find function to scan the C:\WINNT directory, looking for matches on *.cpl. Just replace the names I have in my HTML sample with the options you want to add.

Using VBScript is a great way to exploit the underlying power of Windows via ActiveX objects and HTML. And it's a great way to impress your boss with your HTML prowess. Now you're sure to get that raise you've been asking for!


Sponsored By
SOFTLANDING SYSTEMS

Download FREE WebSphere Toolkit!

Automate WebSphere management tasks on the iSeries with commands that stop/start a WAS instance, install Enterprise applications, pre-compile JSPs in production before users access them, copy configs for editing, backup, or applying to another server, and more. >

If your WebSphere environment includes the iSeries, these tools and other solutions from SoftLanding Systems will give you a head start on managing your WebSphere applications.

TurnOver Change Management oversees the entire development process from request thru deployment to any server -- iSeries, NT, Unix, or Linux. Automate WebSphere Application Server tasks within TurnOver with the FREE WebSphere toolkit.

PVCS Version Manager plugs into both the WebSphere IDE and TurnOver to deliver the most streamlined, integrated management of WebSphere and iSeries objects available today.

TurnOver PDQ almost entirely eliminates downtime during database changes or reorgs.

SoftLanding brings you a powerful combination of WebSphere-integrated software to streamline and automate your entire WebSphere development process.

Get your free WebSphere tools and more info/free product trials online, or call SoftLanding at 603-924-8818 x1.


THIS ISSUE
SPONSORED BY:

T.L. Ashford
SoftLanding Systems
Affirmative Computer
ASNA
Profound Logic Software
WorksRight Software


BACK ISSUES

TABLE OF CONTENTS
Plug into Sockets

Access Windows Control Panel Using VBScript

Cool Things in CODE/400: Keyboard Shortcuts

How to Interact Directly with JavaBeans from JSPs

FTP Basics: Batch Processing

The Random Number Generator API

Editors
Shannon O'Donnell
Kevin Vandever

Managing Editor
Shannon Pastore

Contributing Editors:
Howard Arner
Joe Hertvik
Ted Holt
David Morris
Richard Shaler

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com



Last Updated: 7/18/02
Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.