|
|
![]() |
|
|
Access Windows Control Panel Using VBScript by Shannon O'Donnell [The code for this article is available for download.]
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:
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!
|
Editors
Contact the Editors |
|
Last Updated: 7/18/02 Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. |