Looking for a way to open Control Panel applets from your programs without opening the Control Panel?
Whether you want your users to change the system date/time properties, add a new modem or change joystick settings, there's an easy way to call all such Control Panel applets (icons) without opening the Control Panel folder. The good news is that you can use this method in any Windows programming environment or even in a simple BATch file. Running the following command from your program will do the trick (CPL being the file name of the Control Panel applet to open. a list of such applets can be found at the bottom of this document): For example, to bring up the "Date/Time Properties" dialog box, run: To open a Control Panel applet from a Windows BATch file, simply include the above command in a line by itself. Since we're using a regular executable file, rundll32.exe, you can include the above command in any location you can execute a program, such as a shortcut icon, Intranet web page anchor, script, etc. Although the concept is simple enough, let's look at some code samples on how to ease calling the above command from a C/C++ or Delphi program. Note that you can use any "WinExec()" equivalent function to achieve the same effect. C Language / C++ / C++Builder code sample Include the following code in your program and call "RunControlPanelApplet()". Example call: RunControlPanelApplet("timedate.cpl"); Delphi / C++Builder code sample Include the following unit into your project and call "RunControlPanelApplet()" with the name of the applet to open. Example: RunControlPanelApplet( 'timedate.cpl' ); How to find the names of the applet files Control Panel applet files have the extension CPL. To get a list of applets installed on your system, go to your Windows SYSTEM (Windows 95) or SYSTEM32 (Windows NT) directory and look for files with the CPL extension. Example: DIR C:\WINDOWS\SYSTEM\*.CPL Following is a list of applets common to Windows 95 and Windows NT:
Read more
- rundll32.exe shell32.dll,Control_RunDLL CPL
- rundll32.exe shell32.dll,Control_RunDLL timedate.cpl
#include<stdio.h>
#include<windows.h>
int RunControlPanelApplet(
char*sAppletFileName)
{
char s[1024];
sprintf(s,
"rundll32.exe shell32.dll,"
"Control_RunDLL %s",
sAppletFileName);
return
WinExec(s, SW_SHOWNORMAL);
}
#include<windows.h>
int RunControlPanelApplet(
char*sAppletFileName)
{
char s[1024];
sprintf(s,
"rundll32.exe shell32.dll,"
"Control_RunDLL %s",
sAppletFileName);
return
WinExec(s, SW_SHOWNORMAL);
}
Listing #1 : C code. Download opencpl2.c (0.31 KB).
unit open_cpl;
interface
function RunControlPanelApplet(
sAppletFileName : string) : integer;
implementation
uses Windows;
function RunControlPanelApplet(
sAppletFileName : string) : integer;
begin
Result :=
WinExec(
PChar('rundll32.exe shell32.dll,'+
'Control_RunDLL '+sAppletFileName),
SW_SHOWNORMAL);
end;
end.
interface
function RunControlPanelApplet(
sAppletFileName : string) : integer;
implementation
uses Windows;
function RunControlPanelApplet(
sAppletFileName : string) : integer;
begin
Result :=
WinExec(
PChar('rundll32.exe shell32.dll,'+
'Control_RunDLL '+sAppletFileName),
SW_SHOWNORMAL);
end;
end.
Listing #2 : Delphi code. Download opencpl1.pas (0.33 KB).
- access.cpl: Accessibility Properties
- appwiz.cpl: Add/Remove Programs Properties
- desk.cpl: Display Properties
- intl.cpl: Regional Settings Properties
- joy.cpl: Joystick Properties
- main.cpl: Mouse Properties
- mmsys.cpl: Multimedia Properties
- modem.cpl: Modems Properties
- sysdm.cpl: System Properties
- timedate.cpl: Time/Date Properties