views:

233

answers:

3

How to find version of an application installed, using c#. Is there a way to know component id of application?

EDIT: I need to get version of an already installed application.This is required for generating the diagnostics report on users machine.

Example:Version of Outlook 2007 installed on a user's machine

+1  A: 
FileVersionInfo.GetVersionInfo("some.dll");
Amby
This approach we have find the dll(s) copied by application installer/update to application and find the version of dll.
Deepak N
+2  A: 

If it's assemblies you're after:

For the current assembly:

Assembly.GetExecutingAssembly().GetName().Version

Replace Assembly.GetExecutingAssembly() with an Assembly instance you got through other means to determine that one's version.

One way would be:

Assembly assembly = Assembly.LoadFrom("something.dll");

It will return the value from the AssemblyVersion attribute.

FrederikB
A: 

There is no unified method suitable for all the applications I'm afraid. But for MS office application you may get version via COM objects.

Sorry, I don't have outlook on my computer, so I can't try it with oulook. But with excel and word it can be done like that:

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
Console.WriteLine("Excel: Version-" + excelApp.Version + " Build-" + excelApp.Build);
Console.WriteLine("Word: Version-" + wordApp.Version + " Build-" + wordApp.Build);

I think that getting version of other MS applications will be quite the same. Good luck.

PS. Do not forget to call Quit() in the end and to release com objects via Marshal.ReleaseComObject() method like

Marshal.ReleaseComObject(excelApp);
Marshal.ReleaseComObject(wordApp);
kalan