开发者

How to find version of an application installed using c#

开发者 https://www.devze.com 2023-01-03 04:34 出处:网络
How to find version of an a开发者_JAVA技巧pplication installed, using c#. Is there a way to know component id of application?

How to find version of an a开发者_JAVA技巧pplication 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


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.


FileVersionInfo.GetVersionInfo("some.dll");


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

精彩评论

暂无评论...
验证码 换一张
取 消