怎么列举计算机安装了那些ACTIVEX组件?(100)

  • 主题发起人 主题发起人 蓝叶菱
  • 开始时间 开始时间

蓝叶菱

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么列举计算机安装了那些ACTIVEX组件? 类似于DELPHI编译器自带的安装ACTIVEX组件界面的效果,类似于菜单Component->Import ActiveX 那个界面的效果。
 
我看了一下MSDN的OLEView源代码,居然用注册表搞的。我试过WIN 7下的TComAdminCatalog组件,不过不行。不过效果还一般。不知道有没有代码给我参考一下。我贴出代码,大家看看。 HKEY hkCLSID ; if (RegOpenKey( HKEY_CLASSES_ROOT, _T("CLSID"), &hkCLSID) == ERROR_SUCCESS) { CObjectData* lpOD ; LONG cb ; TCHAR szBuf[_MAX_PATH + 1] ; TCHAR szName[64] ; TCHAR szCLSID[64] ; DWORD dwIndex ; for ( dwIndex = 0 ; RegEnumKey( hkCLSID, dwIndex, szCLSID, sizeof(szCLSID)) == ERROR_SUCCESS ; ++dwIndex ) { lpOD = NULL ; cb = sizeof(szName); if (RegQueryValue( hkCLSID, (LPTSTR)szCLSID, szName, &cb) == ERROR_SUCCESS) { lpOD = new CObjectData ; lpOD->m_nType = CObjectData::typeObject ; ASSERT(lpOD) ; ::CLSIDFromString( CT2OLE(szCLSID), &lpOD->m_clsid); lpOD->m_szProgID[0] = '/0' ; // Assume it's an object lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT) ; // Now find out more about it. // // #1 Look in CLSID/{clsid} for the /Control key // #2 Assume it is an 'non-embeddable' OLE 2.0 object // #3 If /<progid>/NotInsertable exists we'redo
ne // #4 if !#2 then
if /<progid>/Insertable it's an insertable OLE 2.0 object // and we'redo
ne // #5 if !#3 see if it's an OLE 1.0 object by checking Ole1Class // HKEY hkClass, hkTemp ; if (RegOpenKey( hkCLSID, szCLSID, &hkClass ) == ERROR_SUCCESS) { BOOL fHasServer32 = HasServer32( hkClass ) ; if (fHasServer32) lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT32) ; else
lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT) ; // First determine if it is a system component // cb = sizeof(szBuf) ; LONG cb2 = sizeof(szBuf) ; if (RegQueryValue( hkClass, (LPTSTR)_T("InprocServer32"), szBuf, &cb ) == ERROR_SUCCESS) { // RegQueryValue may not return a null terminated string. szBuf[_MAX_PATH] = '/0'; if ((0 == _stricmp( szBuf, _T("ole32.dll") )) || (0 == _stricmp( szBuf, _T("oleprx32.dll") )) || (0 == _stricmp( szBuf, _T("ole2pr32.dll") )) || (0 == _stricmp( szBuf, _T("olecnv32.dll") )) || (0 == _stricmp( szBuf, _T("oleaut32.dll") ))) { lpOD->m_uiBitmap = BMINDEX(IDB_QUESTION32) ; } } // Query InprocServer else
if (RegQueryValue( hkClass, (LPTSTR)_T("InprocServer"), szBuf, &cb2 ) == ERROR_SUCCESS) { if ((0 == _stricmp( szBuf, _T("ole2prox.dll") )) || (0 == _stricmp( szBuf, _T("ole2.dll") )) || (0 == _stricmp( szBuf, _T("ole2disp.dll") ))) { lpOD->m_uiBitmap = BMINDEX(IDB_QUESTION) ; } } // If it has "Ole1Class" then
it's an OLE 1.0 object // _stprintf_s( szBuf, _MAX_PATH, _T("CLSID//%s//Ole1Class"), (LPTSTR)szCLSID) ; if (RegOpenKey( HKEY_CLASSES_ROOT, szBuf, &hkTemp ) == ERROR_SUCCESS) { // Is it 32 bit or 16 bit? if (fHasServer32) lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT_INSERTABLE1032) ;
// that succeeded. This means we're insertable else
lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT_INSERTABLE10) ;
// that succeeded. This means we're insertable RegCloseKey( hkTemp ) ; goto lblInsertInList ; } // We now recognize the "Control" key which indicates it's // an OLE Custom Control. // _stprintf_s( szBuf, _MAX_PATH, _T("CLSID//%s//Control"), (LPTSTR)szCLSID) ; if (RegOpenKey( HKEY_CLASSES_ROOT, szBuf, &hkTemp ) == ERROR_SUCCESS) { // Is it 32 bit or 16 bit? if (fHasServer32) lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT_CONTROL32) ; else
lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT_CONTROL) ; RegCloseKey( hkTemp ) ; goto lblInsertInList ; } // If it's not a control, but it's insertable it must be a CD object // _stprintf_s( szBuf, _MAX_PATH, _T("CLSID//%s//Insertable"), (LPTSTR)szCLSID) ; if (RegOpenKey( HKEY_CLASSES_ROOT, szBuf, &hkTemp ) == ERROR_SUCCESS) { // Is it 32 bit or 16 bit? if (fHasServer32) lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT_INSERTABLE32) ;
// that succeeded. This means we're insertable else
lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT_INSERTABLE) ;
// that succeeded. This means we're insertable RegCloseKey( hkTemp ) ; goto lblInsertInList ; } cb = sizeof(lpOD->m_szProgID) ; if (RegQueryValue( hkClass, (LPTSTR)_T("ProgID"), lpOD->m_szProgID, &cb) == ERROR_SUCCESS) { HKEY hkInsertable ; // Is it an OLE 1.0 object? // cb = 64 ; if (RegQueryValue( hkClass, (LPTSTR)"Ole1Class", szBuf, &cb ) == ERROR_SUCCESS) { if (fHasServer32) lpOD->m_uiBitmap = BMINDEX( IDB_OBJECT_INSERTABLE1032 ) ; else
lpOD->m_uiBitmap = BMINDEX( IDB_OBJECT_INSERTABLE10 ) ; goto lblInsertInList ; } //do
es the object force "NotInsertable"? // _stprintf_s( szBuf, _MAX_PATH, _T("%s//NotInsertable"), (LPTSTR)lpOD->m_szProgID ) ; if (RegOpenKey( HKEY_CLASSES_ROOT, szBuf, &hkInsertable ) == ERROR_SUCCESS) { if (fHasServer32) lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT32) ; else
lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT) ; RegCloseKey( hkInsertable ) ; goto lblInsertInList ; } // Is it insertable? // _stprintf_s( szBuf, _MAX_PATH, _T("%s//Insertable"), (LPTSTR)lpOD->m_szProgID ) ; if (RegOpenKey( HKEY_CLASSES_ROOT, szBuf, &hkInsertable ) == ERROR_SUCCESS) { if (fHasServer32) lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT_INSERTABLE32) ;
// that succeeded. This means we're insertable else
lpOD->m_uiBitmap = BMINDEX(IDB_OBJECT_INSERTABLE) ;
// that succeeded. This means we're insertable RegCloseKey( hkInsertable ) ; goto lblInsertInList ; }#ifdef SHOW_CONTAINERS // Try HKEY_CLASSES_ROOT/szProgID/shell/open to see if it's // a container. // wsprintf( szBuf, _T("%s//shell//open"), (LPTSTR)lpOD->m_szProgID ) ; if (RegOpenKey( HKEY_CLASSES_ROOT, szBuf, &hkInsertable ) == ERROR_SUCCESS) { if (fHasServer32) lpOD->m_uiBitmap = BMINDEX(IDB_CONTAINER32) ; else
lpOD->m_uiBitmap = BMINDEX(IDB_CONTAINER) ; RegCloseKey( hkInsertable ) ; goto lblInsertInList ; }#endif } RegCloseKey( hkClass ) ; } // if RegOpenKey( ... &hkClass )lblInsertInList: HTREEITEM htree = NULL ; switch( lpOD->m_uiBitmap ) { case BMINDEX(IDB_QUESTION): case BMINDEX(IDB_QUESTION32): htree = m_hInternal ; break ; case BMINDEX(IDB_OBJECT_INSERTABLE10): case BMINDEX(IDB_OBJECT_INSERTABLE1032): htree = m_hOLE1 ; break ; case BMINDEX(IDB_OBJECT_INSERTABLE): case BMINDEX(IDB_OBJECT_INSERTABLE32): htree = m_hInsertable ; break ;#ifdef SHOW_CONTAINERS case BMINDEX(IDB_CONTAINER): case BMINDEX(IDB_CONTAINER32): htree = m_hContainers ; break ;#endif case BMINDEX(IDB_OBJECT_CONTROL): case BMINDEX(IDB_OBJECT_CONTROL32): htree = m_hControls ; break ; case BMINDEX(IDB_OBJECT): case BMINDEX(IDB_OBJECT32): default: htree = m_hUnclassified ; break ; } if (htree && htree == pnmtv->itemNew.hItem) { RegOpenKey( hkCLSID, szCLSID, &hkClass ) ; cb = sizeof(szBuf) ; if (RegQueryValue( hkClass, (LPTSTR)"ToolboxBitmap32", szBuf, &cb ) == ERROR_SUCCESS || RegQueryValue( hkClass, (LPTSTR)"ToolboxBitmap", szBuf, &cb ) == ERROR_SUCCESS) { TCHAR * nextTok; TCHAR * pszBitmapModule = _tcstok_s(szBuf, _T(","), &nextTok); TCHAR * pszBitmapId = _tcstok_s(NULL, _T(","), &nextTok); HINSTANCE hinstBitmap; int nBitmapId; if ((pszBitmapModule != NULL) && (pszBitmapId != NULL)) { LPTSTR p ; if (*pszBitmapModule == '"') { _tcscpy_s( pszBitmapModule, _MAX_PATH - (pszBitmapModule - szBuf), pszBitmapModule+1 ) ; p = strrchr( pszBitmapModule, '"' ) ; if (p) *p = '/0' ; } nBitmapId = _ttoi(pszBitmapId); if (g_osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) hinstBitmap = LoadLibrary(pszBitmapModule); else
hinstBitmap = LoadLibraryEx(pszBitmapModule, NULL, LOAD_LIBRARY_AS_DATAFILE); if (hinstBitmap && (nBitmapId > 0)) { HBITMAP hbmGlyph = ::LoadBitmap(hinstBitmap, MAKEINTRESOURCE(nBitmapId)); if (hbmGlyph) { lpOD->m_uiBitmap = theApp.m_images.Add( CBitmap::FromHandle(hbmGlyph), RGBLTGRAY ) ; ::DeleteObject(hbmGlyph) ; } FreeLibrary( hinstBitmap ) ; } } } RegCloseKey( hkClass ) ; ASSERT(lpOD) ; TV_INSERTSTRUCT tvis ; tvis.hParent = htree ; tvis.hInsertAfter = TVI_SORT ; tvis.item.mask = TVIF_PARAM | TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE |TVIF_CHILDREN ; tvis.item.cChildren = 1 ; tvis.item.lParam = (LPARAM)(LPVOID)lpOD ; tvis.item.pszText = szName ; tvis.item.iImage = tvis.item.iSelectedImage = lpOD->m_uiBitmap ; GetTreeCtrl().InsertItem( &tvis ) ; } else
delete lpOD ; } } RegCloseKey( hkCLSID ) ;
 
void CObjTreeView::ExpandClassification( NM_TREEVIEW* pnmtv )。不过效果和DELPHI自带的,Visual Studio 2008自带的有差距,还有一大片空的呢。有没有简单一点的?给位仁兄。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部