HOWTO: Enumerate and Run Available Control Panel Applets

ID: Q232536


The information in this article applies to:


SUMMARY

This article explains how to extract a list of available Control Panel applets and how to execute them from the command line or from another program.


MORE INFORMATION

Rundll32 is a utility included with Windows 95, Windows 98, Windows NT 4.0, and Windows 2000 that allows you to start a function that is exported from a DLL from a command line. The Windows Explorer Shell uses RUNDLL32 to call the Control_RunDLL function in Shell32.dll to start a Control Panel applet. Applications can use the following command line to start a Control Panel applet:

C:\>rundll32.exe shell32.dll,Control_RunDLL mycontrol.cpl  


This starts the first Control Panel applet in Mycontrol.cpl. If you have multiple Control Panel applets in Mycontrol.cpl, you need to add the name of the Control Panel applet to the command line. For Example:
Rundll32.exe Shell32.dll,Control_RunDLL Mycontrol.cpl,My Control 


To enumerate the list of available control panel applets in a *.cpl file, you can use the following program sample code:

// Control Panel Enumeration
#include <stdio.h>
#include <windows.h>
#include <cpl.h>

int main(int argc, char **argv, char **envp)
{   
    union { 
        NEWCPLINFOA NewCplInfoA;
        NEWCPLINFOW NewCplInfoW; 
    } Newcpl;
    
    HINSTANCE hLib; // Library Handle to *.cpl file
    APPLET_PROC CplCall; // Pointer to CPlApplet() function
    LONG i;
    
    // -------------------
    if (!(hLib = LoadLibrary(argv[1]))) 
        return 1;	
    if (!(CplCall=(APPLET_PROC)GetProcAddress(hLib,"CPlApplet")))
    {
        FreeLibrary(hLib);        
        return 2;
    }
    
    // -------------------
    CplCall(NULL, CPL_INIT,0,0); // Init the *.cpl file
    
    for (i=0;i<CplCall(NULL,CPL_GETCOUNT,0,0);i++)
    {
        printf("RunDLL32 shell32.dll,Control_RunDLL %s",argv[1]);
        
        Newcpl.NewCplInfoA.dwSize = 0;
        Newcpl.NewCplInfoA.dwFlags = 0;
        CplCall(NULL,CPL_NEWINQUIRE,i,(long)&Newcpl);
        
        if (Newcpl.NewCplInfoA.dwSize == sizeof(NEWCPLINFOW))
        {   // Case #1, CPL_NEWINQUIRE has returned an Unicode String
            wprintf(L",%s\n", Newcpl.NewCplInfoW.szName);
        }
        else 
        {   // Case #2, CPL_NEWINQUIRE has returned an ANSI String
            if (Newcpl.NewCplInfoA.dwSize != sizeof(NEWCPLINFOA))
            {
                // Case #3, CPL_NEWINQUIRE failed to return a string
                //    Get the string from the *.cpl Resource instead
                CPLINFO CInfo;
                
                CplCall(NULL,CPL_INQUIRE,i,(long)&CInfo);				
                LoadStringA(hLib,CInfo.idName,
                    Newcpl.NewCplInfoA.szName,32);
            }
            printf(",%s\n", Newcpl.NewCplInfoA.szName);
        }
    } // for
    
    CplCall(NULL,CPL_EXIT,0,0);
    
    // -------------------
    FreeLibrary(hLib);        
    return 0;
} 

This program (Enumcpl.exe) will take one *.cpl file as a parameter and print the available Control Panel applets in that file.

For example, to enumerate all installed *.cpl files on a system:

C:\>for %i in ( c:\winnt\system32\*.cpl ) do @enumcpl %i
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\ups.cpl,&UPS
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\telephon.cpl,Telephony
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\srvmgr.cpl,Ser&ver
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\srvmgr.cpl,Servi&ces
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\srvmgr.cpl,&Devices
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\ncpa.cpl,Network
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\main.cpl,Mouse
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\main.cpl,Keyboard
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\main.cpl,Printers
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\main.cpl,Fonts
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\odbccp32.cpl,OD&BC
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\console.cpl,Console
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\appwiz.cpl,Add/Remove Programs
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\access.cpl,Accessibility Options
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\inetcpl.cpl,Internet
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\DESK.CPL,Display
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\DEVAPPS.CPL,PC Card (PCMCIA)
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\DEVAPPS.CPL,SCSI Adapters
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\DEVAPPS.CPL,Tape Devices
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\INTL.CPL,Regional Settings
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\MMSYS.CPL,Multimedia
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\MMSYS.CPL,Sounds
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\MODEM.CPL,Modems
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\PORTS.CPL,Ports
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\SYSDM.CPL,System
RunDLL32 shell32.dll,Control_RunDLL c:\winnt\system32\TIMEDATE.CPL,Date/Time 
Any one of these lines can be executed to start the corresponding Control Panel applet from the command line.

Using RunDLL32 can also be used to debug a Control Panel applet, by using the RunDLL32.exe as the program and the string generated above as the arguments to RunDLL32.


REFERENCES

Q164787 The Windows 95 Rundll and Rundll32 Interface

Q166168 HOWTO: Use RUNDLL32 to Debug Control Panel Applets

Q183106 HOWTO: Debug Control Panel Property Sheet Extensions

Q135068 HOWTO: Start a Control Panel Applet in Windows 95, 98, or WinNT

Q192806 How to Run Control Panel Tools by Typing a Command

Additional query words:


Keywords          : kbCPApplet kbDDK kbNTOS kbNTOS400 kbWinOS2000 kbWinOS95 kbWinOS98 kbGrpNTDDK 
Version           : winnt:4.0
Platform          : winnt 
Issue type        : kbhowto 

Last Reviewed: June 10, 1999