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

33,905

Solution 1

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

Solution 2

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

Solution 3

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.

Share:
33,905
softwarematter
Author by

softwarematter

C++, Java, C#, ASP.NET

Updated on July 28, 2020

Comments

  • softwarematter
    softwarematter almost 4 years

    How do I check if a COM component (EXE/DLL file) is registered or not using .NET?

  • Roman R.
    Roman R. about 9 years
    It does not answer the question, which is about programmatic check.
  • C. Augusto Proiete
    C. Augusto Proiete over 8 years
    Here is an example using C#: stackoverflow.com/questions/4966508/…
  • Shane Kenyon
    Shane Kenyon over 6 years
    You know, none of the other answers are technically programmatic either. Down vote is pretty meh.