发现注册的COM组件 [英] Discovering registered COM components

查看:377
本文介绍了发现注册的COM组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法通过解析注册表中的信息来确定注册的COM组件是否可作为独立组件创建?特别是,根据HKCR / ClsId中的资料?



我的系统在此键中有超过12,000个条目,我已经排除没有InProcServer32或LocalServer32键的任何项目,但这只消除了大约一半项目。我相信还有另外几千个不是可创造的对象。我真的不想试图做一个CreateObject()在每一个他们,以区分可以创建的那些不能。有更有效的方法吗?

解决方案

Oleview



Oleview
用于此目的(返回日期:))



手动/程序化



正确(没有Windows PC附近):




  • 类应链接到类型库

  • typelib将指向二进制(dll,ocx,exe)

  • 此二进制包含物理类型库,您应该解析

    • 编译器可以这样做(生成存根/ C头)

    • oleview可以这样做(提取IDL)

    • tlbimp可以做到

    • 您可以使用Win32 API

    • 执行任何可创建对象应标记为 coclass c> interface 或 source ;还有一些全局模块,我想是可以创建的:我只是不知道它们是否被定义为coclasses




显示代码



可以使用ITypeLib和ITypeInfo接口读取类型库中的信息。它们可以使用ICreateTypeLib和ICreateTypeInfo接口创建。但是,Microsoft IDL编译器(MIDL)可能是唯一使用ICreateType和ICreateTypeInfo的应用程序。



一个快速的google翻了这个有用的页面: 阅读类型库C ++



它包含刚才开始的代码。只是看看它是否值得任何东西,我解雇一个云Windows实例,抓住所有的来源和编译它。



与网站上提到的选项相反,我只需在Windows上编辑

  cl.exe * .cpp / EHs ole32.lib oleaut32.lib 

乐趣,我编译的东西在Linux(64位)使用MingW:

  i586-mingw32msvc-g ++ * .cpp -loleaut32  - lole32 -o Typelib.exe 

为了节省你的工作,我把 zip文件下载 包含:

  win32_Unicode.cpp  - 来源RenéNyffenegger 
win32_Unicode.h
TestTypelib.cpp
Typelib.cpp
Typelib.h
VariantHelper.cpp
VariantHelper.h
TestTypelib.exe - 在Windows上编译的二进制程序

测试运行:

 #linux:./a.exe〜/ .wine / drive_c / windows / system32 / msxml6.dll 
C:\Games\Stacko> TestTypelib.exe c:\Windows \System32\msxml6.dll

MSXML2:Microsoft XML,v6.0
Nof类型信息:149

IXMLDOM实施
----------------------------
接口:Dispatch
函数:8
变量:0

功能:QueryInterface
返回:VT_VOID
标志:
类型:
params:2
params opt:0
参数:riid type = VT_PTR(VT_USERDEFINED(GUID))in
参数:ppvObj type = VT_PTR(VT_PTR)out

函数:AddRef
返回:VT_UI4
标志:
invoke kind:function
params:0
params opt:0



(snip)

结束



我希望这为您扫描系统中已安装,可创建的COM组件提供了一个良好的起点


Is there a way to determine if a registered COM component is creatable as a stand-alone component simply by parsing the information available in the registry? In particular, by the information found in HKCR/ClsId?

My system has over 12,000 entries in this key, and I am already excluding any items that do not have an InProcServer32 or LocalServer32 key, but this only eliminates about half of the items. I believe there are still another couple thousand that are not creatable objects. I really don't want to have to attempt to do a CreateObject() on every one of them to distinguish the ones that can be created from the ones that cannot. Is there a more efficient way?

解决方案

Oleview

I used Oleview for this purpose (back in the day :))

Manual/programmatic

If I remember correctly (no Windows PC nearby):

  • the class should link to a typelibrary
  • the typelib will point to a binary (dll, ocx, exe)
  • this binary contains the physical typelibrary, which you should parse
    • the midl compiler can do that (generate stubs/C headers)
    • oleview can do that (extract IDL)
    • tlbimp can do that
    • you can do it with Win32 API
    • any creatable objects should be marked coclass (not interface or source; there were also global modules which I suppose are creatable too: I'm just not sure whether they are defined as coclasses

Show me the code

It is possible to read the information within a type library with the ITypeLib and ITypeInfo interfaces. They can be created with the ICreateTypeLib and ICreateTypeInfo interfaces. However, the Microsoft IDL compiler (MIDL) is probably the only application to ever use ICreateType and ICreateTypeInfo.

A quick google turned up this useful page: Reading Type Libraries with C++.

It contains just the code to get started. Just to see whether it was worth anything, I fired up a cloud Windows instance, grabbed all the sources and compiled it.

In contrast with the options mentioned on the site, I simply compiled on windows with

cl.exe *.cpp /EHs ole32.lib oleaut32.lib

Just for fun, I compiled the stuff on Linux (64 bit) using MingW:

i586-mingw32msvc-g++ *.cpp -loleaut32 -lole32 -o Typelib.exe

To save you the work I have put a zip-file up for download containing:

win32_Unicode.cpp     - sources by René Nyffenegger
win32_Unicode.h
TestTypelib.cpp
Typelib.cpp
Typelib.h
VariantHelper.cpp
VariantHelper.h
TestTypelib.exe       - binary compiled on windows

A test run:

# linux: ./a.exe ~/.wine/drive_c/windows/system32/msxml6.dll
C:\Games\Stacko>TestTypelib.exe c:\Windows\System32\msxml6.dll

MSXML2: Microsoft XML, v6.0
Nof Type Infos: 149

IXMLDOMImplementation
----------------------------
  Interface: Dispatch
  functions: 8
  variables: 0

  Function     : QueryInterface
    returns    : VT_VOID
    flags      : 
    invoke kind: function
    params     : 2
    params opt : 0
    Parameter  : riid type = VT_PTR (VT_USERDEFINED (GUID)) in
    Parameter  : ppvObj type = VT_PTR (VT_PTR) out

  Function     : AddRef
    returns    : VT_UI4
    flags      : 
    invoke kind: function
    params     : 0
    params opt : 0

(snip) and 15499 lines more

Concluding

I hope this gives you a good starting point in scanning your system for installed, creatable, COM components

这篇关于发现注册的COM组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆