| re: How to check version of an installed COM DLL
Wiktor Zychla wrote:[color=blue]
> as for the version - I know two possibilities:
> 1. implement the Version property in the COM object and check it. several
> existing COM objects implement such property (for example Office objects)
> 2. get the guid of the COM type and look into the registry under
> HKClassesToor\CLSID\. after you find the proper key, query its
> "InprocServer32" subkey which will tell you the name of the object source.
>
> if there's a simpler way, I would like to know it too.[/color]
Wiktor, thanks for your suggestion, I have attempted to implement it
in the following function below. Seems to do everything I wanted -
thank you very much. In all it was a lot less work than I was
expecting. If anyone knows of any other shortcuts / improvements then
please post!
here's the code.
// need these...
using System.Diagnostics; // for 'FileVersionInfo'
using Microsoft.Win32; // for 'RegistryKey'
// then somewhere in your main application...
string retval;
if( checkComServerExists("{blahblah-blah-blah-blah-blahblahblah}",
out retval) == false )
{
Console.WriteLine("didn't exist, reason: " + retval);
return;
}
Console.WriteLine("existed - Ver." + retval);
// checks to see if a COM server is registered and exists on the
system
public static bool checkComServerExists(string CLSID,
out string retval)
{
RegistryKey myRegKey = Registry.LocalMachine;
Object val;
try {
// get the pathname to the COM server DLL if the key exists
myRegKey = myRegKey.OpenSubKey(@"SOFTWARE\Classes\CLSID\" +
CLSID + @"\InprocServer32");
val = myRegKey.GetValue(null); // the null gets default
// value from key
}
catch {
retval = "not registered";
return false;
}
FileVersionInfo myFileVersionInfo = null;
try {
// parse out the version number embedded in the resource
// in the DLL
myFileVersionInfo =
FileVersionInfo.GetVersionInfo(val.ToString());
}
catch {
retval = ".dll not found";
return false;
}
retval = myFileVersionInfo.FileVersion;
return true;
} |