简体   繁体   中英

How to list all installed ActiveX controls?

I need to display a list of ActiveX controls for the user to choose. It needs to show the control name and description.

How do I query Windows on the installed controls?

Is there a way to differentiate controls from COM automation servers?

Googling for "enumerate activex controls" give this as the first result:

http://www.codeguru.com/cpp/com-tech/activex/controls/article.php/c5527/Listing-All-Registered-ActiveX-Controls.htm

Although I would add that you don't need to call AddRef() on pCatInfo since CoCreateInstance() calls that for you.

This is how I would do it:

#include <cstdio>
#include <windows.h>
#include <comcat.h>

int main()
{
    // Initialize COM
    ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    // Obtain interface for enumeration
    ICatInformation* catInfo = NULL;
    HRESULT hr = ::CoCreateInstance(CLSID_StdComponentCategoriesMgr,
        NULL, CLSCTX_INPROC_SERVER, IID_ICatInformation, (void**)&catInfo);

    // Obtain an enumerator for classes in the CATID_Control category.
    IEnumGUID* enumGuid = NULL;
    CATID catidImpl = CATID_Control;
    CATID catidReqd = CATID_Control;
    catInfo->EnumClassesOfCategories(1, &catidImpl, 0, &catidReqd, &enumGuid);

    // Enumerate through the CLSIDs until there is no more.
    CLSID clsid;
    while((hr = enumGuid->Next(1, &clsid, NULL)) == S_OK)
    {
        BSTR name;
        // Obtain full name
        ::OleRegGetUserType(clsid, USERCLASSTYPE_FULL, &name);
        // Do something with the string
        printf("%S\n", name);
        // Release string.
        ::SysFreeString(name);
    }

    // Clean up.
    enumGuid->Release();
    catInfo->Release();
    ::CoUninitialize();
    return 0;
}

for some reason the other example posted seg faults for me. Here's my stab at it:

https://gist.github.com/810398

Though that C code doesn't seem to enumerate all of them for me. See how do you enumerate WIN32OLE available servers? for more answers, I think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM