473,387 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to check version of an installed COM DLL

I'm using a COM DLL from a C# application via an interop wrapper
generated by 'tlbimp.exe'. That all works fine, I can fire off methods
and things happen as they should.

My issue is that I want my application to check both that the COM DLL
is registered on the system and its version is acceptable. I envisage
a bit of code at the beginning of the application's runtime that
performs these checks.

I've got a 'soup' of ideas about how to tackle this. I get the
impression that I can't get the information I'm looking for from the
COM object if it's been instantiated via the interop. I tried this...

MyCOMLib.MyInterface MyInstance = new MyCOMLib.MyInterface();
Assembly myAssembly = Assembly.GetAssembly(MyInstance.GetType());
Console.WriteLine("name=" + SampleAssembly.CodeBase);

But it just gave me the pathname to the interop wrapper whereas I want
the pathname to the DLL that the interop uses.

So then I tried this to get rid of the interop haze in the middle...

Type myType = Type.GetTypeFromProgID("MyCOMLib.MyInterface");
Object myObject = Activator.CreateInstance(myType);

This felt just like instantiating a COM object in C++ with
CreateInstance(). So now I want to do something like a call to the
Platform SDK's GetModuleFileName(), passing in the object reference,
but looking around the framework I can only find the
'FullyQualifiedName' property of the Module class in
System.Reflection. Maybe I can use this somehow?

Armed with this fully qualified filename I was hoping to be able to
feed it into some kind of embedded resource-parsing function in the
framework that would give me the version directly from the file (like
GetFileVersionInfo() does in version.lib). Maybe there's a way of the
framework getting me the version without having to resolve the DLL's
pathname first though?

As for checking whether the COM object is registered at all on the
system at all, I imagine putting an exception check round an
instantiation statement would suffice?

Any comments welcome!
James
Nov 15 '05 #1
2 9784
> As for checking whether the COM object is registered at all on the
system at all, I imagine putting an exception check round an
instantiation statement would suffice?


yes, this would be sufficient.

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.

regards,
Wiktor
Nov 15 '05 #2
Wiktor Zychla wrote:
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.


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;
}
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Vincent | last post by:
Dear all, I would like to know how to check for the MS Access version that is installed on someones computer via a webpage. I thought vbscript would work, but because I cannot figure out how to...
32
by: deko | last post by:
I'm trying to create an MSI in VS.NET that will check for installed Office System components - so my MDE will only install if requirements are met. I'm thinking about using VBScript to inspect...
6
by: Phil Campaigne | last post by:
Hi All, How can I determine what version of postgresql is installed. Can't find answer in archives. thanks, Phil ---------------------------(end of broadcast)---------------------------...
5
by: kourosh | last post by:
how can I check that which version of dotnet installed on the web server?
1
by: bishweshwar | last post by:
i was not able to get the command ( unix ) to know the iplanet version installed. can someone help me out in this.
2
by: krev | last post by:
Is is possible to check the version of a software installed in client system using javascript?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.