开发者

how could i know the version of an another application using c#

i need to write a program in c# to collect information about processes running on my computer. I successfuly get the processes's names and ID using this code:

... Process[] processlist; ... foreach (Process theprocess in processlist) { Console.WriteLine(theprocess.ProcessName + ...) } ...

But i couldn't get the version of the开发者_JAVA技巧 processes (like Firefox or Visual Studio). does anybody know how to get the version of a running process? thanks a lot!


theProcess.MainModule.FileVersionInfo. But there are one or two exceptions you need to catch.


You can get the filename of the executable from Process.StartInfo.FileName. Get a new instance of FileVersionInfo using the filename like this:

FileVersionInfo myFileVersionInfo = FileVersionInfo.GetVersionInfo(Process.StartInfo.FileName);

Then access myFileVersionInfo.FileVersion to get the file version.

EDIT: Daniel's way seems more efficient; I didn't know you could just access the loaded module's FileVersionInfo directly..


Keep in mind that the executable's FileVersion and/or ProductVersion may not necessarily be the same as the application's version. For example, Firefox 3.5.3 reports a FileVersion of 1.9.1.3523, but a ProductVersion of 3.5.3. VMware Player 2.5.1, on the other hand, reports a FileVersion of 6.5.1.5078 and a ProductVersion of 6.5.1 build-126130. Depending on what you are using the information for, this may or may not be an issue.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜