Microsoft KB Archive/232536

From BetaArchive Wiki

HOWTO: Enumerate and Run Available Control Panel Applications

Q232536



The information in this article applies to:


  • Microsoft Win32 Application Programming Interface (API), included with:
    • the operating system: Microsoft Windows 2000
    • Microsoft Windows NT Server version 4.0
    • Microsoft Windows NT Workstation version 4.0
    • Microsoft Windows 98
    • Microsoft Windows 95





SUMMARY

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



MORE INFORMATION

The Control.exe file is a utility included with Windows 95, Windows 98, Windows NT 4.0, and Windows 2000 that launches control panel applications. Applications can use the following command line to start a Control Panel applet:

C:\>control.exe 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 as demonstated in the following:


 Control.exe Mycontrol.cpl,My Control 

To enumerate the list of available Control Panel applications 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("Control %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 applications 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
Control c:\winnt\system32\ups.cpl,&UPS
   Control c:\winnt\system32\telephon.cpl,Telephony
   Control c:\winnt\system32\ups.cpl,&UPS
   Control c:\winnt\system32\telephon.cpl,Telephony
   Control c:\winnt\system32\srvmgr.cpl,Ser&ver
   Control c:\winnt\system32\srvmgr.cpl,Servi&ces
   Control c:\winnt\system32\srvmgr.cpl,&Devices
   Control c:\winnt\system32\ncpa.cpl,Network
   Control c:\winnt\system32\main.cpl,Mouse
   Control c:\winnt\system32\main.cpl,Keyboard
   Control c:\winnt\system32\main.cpl,Printers
   Control c:\winnt\system32\main.cpl,Fonts
   Control c:\winnt\system32\odbccp32.cpl,OD&BC
   Control c:\winnt\system32\console.cpl,Console
   Control c:\winnt\system32\appwiz.cpl,Add/Remove Programs
   Control c:\winnt\system32\access.cpl,Accessibility Options
   Control c:\winnt\system32\inetcpl.cpl,Internet
   Control c:\winnt\system32\DESK.CPL,Display
   Control c:\winnt\system32\DEVAPPS.CPL,PC Card (PCMCIA)
   Control c:\winnt\system32\DEVAPPS.CPL,SCSI Adapters
   Control c:\winnt\system32\DEVAPPS.CPL,Tape Devices
   Control c:\winnt\system32\INTL.CPL,Regional Settings
   Control c:\winnt\system32\MMSYS.CPL,Multimedia
   Control c:\winnt\system32\MMSYS.CPL,Sounds
   Control c:\winnt\system32\MODEM.CPL,Modems
   Control c:\winnt\system32\PORTS.CPL,Ports
   Control c:\winnt\system32\SYSDM.CPL,System
   Control c:\winnt\system32\TIMEDATE.CPL,Date/Time
 

Any one of these lines can be executed to start the corresponding Control Panel application from the command line.

Using RunDLL32 can also be used to debug a Control Panel application, 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 kbOSWinNT kbOSWinNT400 kbOSWin2000 kbOSWin95 kbOSWin98 kbGrpDSNTDDK
Issue type : kbhowto
Technology : kbAudDeveloper kbWin32sSearch kbWin32API


Last Reviewed: December 16, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.