tags:

views:

494

answers:

2

Is there a programmatic way in C# to determine whether a particular COM DLL has been installed? Or is this a matter of scanning the registry for the classId?

+4  A: 

What I usually did (and would do, if I needed this again) is try to create an object instance of a class you know is in the COM library - either by ProgID or GUID - and checking for failure.

peSHIr
Should be more robust than registry scanning, plus detection of a bad installation. Depends on whether loading the DLL or creating the object is expensive, though.
Pontus Gagge
Right. Probably best to try and use a "suitable" class from the library. And I'm guessing there would be no need to check if COM library is installed if you are not planning to do at least something with the library, so then loading it to check for install is usually no problem...
peSHIr
A: 

Try and create it, and handle the error if not.

Under Win32 CoCreateInstance will return REGDB_E_CLASSNOTREG if not installed (including, IIRC, if registered but the dll/exe implementing it is then deleted).

Under .NET the generated COM interop assembly will throw some error (need to check this, don't have convenient code to test for which exception type). Note. if the interop assembly is missing then that will be treated as missing assembly possibly leading to an application load error.

Richard