tags:

views:

127

answers:

5

I have a COM interop assembly, and I would like to check from a .NET application whether the component I'm about to create is installed on the machine.

I would like to provide a nice error message if it is not installed.

Put the instantiation into try-catch is not a good solution for me, as I would like to distingwish between the missing installation and the other errors that may occur.

My idea is to check whether the node with the COM class id exists in the registry under the *HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Interface* path. But is there a better approach?

A: 

You might also instantiate an object of the com class you want to check in a try/catch block so as to warn your user in the catch block. Blunt solution, I agree.

Checking the registry seems the most reasonable approach to me, as an unregistered com component is pretty useless.

Vinzz
+6  A: 

I think the best way, unfortunately, is to try and instantiate it. Checking in the registry does not guarantee that the component is actually there at all (e.g. the file may have been deleted or moved post registration).

Eyvind
Moreover we should not check for registry. It is implementation dependent, Microsoft can change it at any time.
Vinay
+2  A: 

In addition to the problem that Eyvind mentions, there's a few other things to consider when you're performing your registry check:

  • It's possible (not common, but possible) to have (parts of) the COM registration in HKCU\Software\Classes, so you would have to check that as well.
  • There's also Registration-free COM, where you won't find anything in the registry, but still would be able to instantiate the COM object...

Neither of the above are common, but good to be aware of nonetheless.

Eyvind's scenario is probably something you'd run into more often: someone deleting your COM server from disk without unregistering it first.

Arnout
A: 

You could use iTripoli Type Library Viewer - free. Using the above, open the EXE/DLL in question. Then, you'll discover the GUID. Open regedit, go to KEY: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID. Search/find using the above GUID.

Aaron
A: 

Type.GetTypeFromProgID("MyProgID") != null

Christian Hayter