.net – the best way to detect if a COM component is installed

comnet

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?

Best Answer

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).