tags:

views:

191

answers:

1

I have a software diagnostic page on which I would like to list the File Version information of a couple of COM DLLs. The page is running under the normal, restricted ASP.Net account (NETWORK SERVICE).

Given the ProgIDs of a COM library, what's the best way to go about getting the physical file path or otherwise accessing the file version #?

Note that loading it via Type.GetTypeFromProgID and using the type's Assembly object won't work, as the Assembly object returned is the one for mscorlib.

The install path can be selected by the user and is not guaranteed to be a specific value.

+1  A: 

One way of approaching this is to use the COM function CLSIDFromProgID (Pinvoke.Net shows how to call this from .Net here) to obtain a CLSID, use the GUID.ToString("B") to convert the CLSID to a suitably formatted string then use it to go grovelling in the registry to find where the COM server is registered.

The path will be
HKEY_CLASSES_ROOT\CLSID\<YourCLSID>\InprocServer32 if the COM server is an in-process server (i.e. a DLL as you're expecting)

Note that the file path in the registry is not necessarily a fully qualified path.

Dan Blanchard
That seems to work, thanks! Do you know offhand when the path is likely to not be a fully qualified path?
technophile
The path is usually fully qualified - however, it's up to the installer code to write the path into the registry. I have encountered COM DLL registration code that expects the DLL to be installed in a directory in the PATH. This causes grief when the installing user differs from the consuming user!
Dan Blanchard