How can I find out the version of another application using C #

I need to write a program in C # to collect information about the processes running on my computer. I am successfully getting process names and IDs with this code:

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

But I was unable to get the version of the processes (like Firefox or Visual Studio). does anyone know how to get the version of a running process? Thank you so much!

+2


source to share


3 answers


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



+10


source


Be aware that the FileVersion and / or ProductVersion executables may not match the application version. For example Firefox 3.5.3 reports FileVersion 1.9.1.3523, but ProductVersion 3.5.3. VMware Player 2.5.1, on the other hand, reports FileVersion 6.5.1.5078 and ProductVersion 6.5.1 build-126130. Depending on what you are using this information for, this may or may not be a problem.



+2


source


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

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

      

Then go to myFileVersionInfo.FileVersion to get the file version.

EDIT: Daniel seems to be more efficient; I didn't know that you can just access the loaded FileVersionInfo module directly.

+1


source







All Articles