Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, November 9, 2017 10:54 PM
Hi, i'm new in this and need help on C#.
How can i get the Versions of applications.
I have desktop app and i create label.
Now i want that my label will show current versions of programs on computer.
lets say :
Skype: - version -
Notepad++ : - version
Chrome : -version
If i can just tell C:\Program Files\Notepad++\notepad++.exe and get me version of this..
i think something like
var versionskype = (path for program and get version)
var versionnote = (path for program and get version)
var chrome = (path for program and get version)
label.Text = versionskype + var versionnote + chrome ;
All replies (5)
Friday, November 10, 2017 12:33 AM
Hello,
Using Notepad in my example of C# Console project in VS2012 on Win7;
Code
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace FileVer
{
class Program
{
static void Main( string[] args )
{
string src = @"C:\Windows\system32\notepad.exe";
Console.WriteLine( System.Diagnostics.FileVersionInfo.GetVersionInfo( src ).ToString() );
}
}
}
MSDN Class Link
https://msdn.microsoft.com/en-us/library/system.diagnostics.fileversioninfo(v=vs.110).aspx
Hope this helps :)
Friday, November 10, 2017 12:44 AM
The below only works for a .NET assembly. If the program is a COM and not a .NET assembly, then it's not going to work.
string assemblyVersion = Assembly.LoadFile("filepath").GetName().Version.ToString();
You can use Win32 API to get it from a COM assembly, and maybe someone can help you there, because the programs you are talking about might be COM assemblies.
Friday, November 10, 2017 6:45 AM
Hi SRhelp,
Agree with User3DX, if you want to get the ProductVersion, you could use the following code.
string chromePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe";
string chromeVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(chromePath).ProductVersion;
label.Text = chromeVersion;
Best regards,
Cole Wu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
Friday, November 10, 2017 2:54 PM
Hi SRhelp,
Agree with User3DX, if you want to get the ProductVersion, you could use the following code.
string chromePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"; string chromeVersion = System.Diagnostics.FileVersionInfo.GetVersionInfo(chromePath).ProductVersion; label.Text = chromeVersion;
Best regards,
Cole Wu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact [email protected].
All it's going to give is file info, and the assembly version cannot be obtained.
Friday, November 10, 2017 3:08 PM
You can try WMI
(avoid the ad about surface which covers almost the whole page)
https://www.microsoft.com/en-us/download/details.aspx?id=8572
Here a snippet around what you ask
https://code.msdn.microsoft.com/windowsdesktop/CCS-LABS-WMI-How-To-get-a4f8a026
Success
Cor