Deepak N
Deepak N

Reputation: 2571

How to find version of an application installed using c#

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

Upvotes: 2

Views: 4443

Answers (3)

kalan
kalan

Reputation: 1842

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);

Upvotes: 0

Frederik
Frederik

Reputation: 2971

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.

Upvotes: 2

Manish Basantani
Manish Basantani

Reputation: 17509

FileVersionInfo.GetVersionInfo("some.dll");

Upvotes: 1

Related Questions