How to check if a COM component (EXE/DLL file) is registered or not (using .NET)? [duplicate]

不打扰是莪最后的温柔 提交于 2019-12-04 22:52:43

Just make a lookup in the registry. HKEY_CLASSES_ROOT\yourcom.component.

DB Tech

It depends. Your component will be registered into the Windows Registry so you need to figure out which hive you want to look in.

If your component is installed with regasm, chances are HKCU will be used, since it will be run from a user's command line. If, however, you use an MSI, the MSI may not use regasm and may place the entries directly into HKLM if you run the MSI in PER MACHINE mode (ALLUSERS = "1") or as an admin. On the other hand, if you run the MSI as PER USER (ALLUSERS = "") or as an unprivileged account, it will use HKCU.

HKCR is merged view of HKLM and HKCU, so you can't tell which hive was actually used, and it might not give you what you want to know. MSDN HKEY_CLASSES_ROOT

If your COM component is registered PER USER, it might fail depending on which user ran the install. So if you want to check whether or not it was installed CORRECTLY, you need to figure out which key you actually want to use, or if HKCR is acceptable. For end user testing, HKCR might be the safest way to test as it will be accessible by everyone and (in .NET) will not throw security exceptions.

Also see this post: regasm and HKCU

From Visual Studio you can do this from the Reference Manager.

  1. Go to Solution Explorer > References
  2. Right click on References
  3. Choose Add Reference...
  4. Choose the COM item from the menu

The nice thing about this tool is you can search for the objects by keyword a bit more elegantly than navigating through the registry. Note you can see the non-COM objects registered in the GAC as well.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!