2010-05-02 175 views

回答

3

谷歌搜索「枚舉的ActiveX控件」把這個作爲第一個結果:

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

雖然我想補充一點,你不需要調用AddRef()pCatInfo因爲CoCreateInstance()調用,爲你。

這是我會怎麼做:

#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; 
} 
1

由於某些原因,例如其他賽格發佈我的故障。 這裏是我的刺吧:

https://gist.github.com/810398

雖然是C代碼似乎並沒有列舉所有的人都適合我。 有關更多的答案,請參見how do you enumerate WIN32OLE available servers?,我想。

+0

現在,如果我能弄清楚如何從Powershell做到這一點,那就太棒了。一個指向C#或VBScript的指針會讓我更接近這一點。 – 2011-05-11 21:43:20

相關問題