-
Jan 12th, 2022, 09:37 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Get the version number of an installed program
Good morning. I have a C# application in which I would like to get this same information that is displayed in Windows Settings Add/Remove program. Both these applications are my own, which I believe is relevant and makes it much more straightforward than the solution that is proposed here.
There are 10 kinds of people in this world. Those who understand binary, and those who don't.
-
Jan 12th, 2022, 12:07 PM
#2
Thread Starter
PowerPoster
Re: Get the version number of an installed program
I am all set. Here is my code.
Code:
private void GetCMSAppVersionCurrentlyInstalled()
{
RegistryKey baseRegistryKey = Registry.LocalMachine;
string subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
RegistryKey uninstallKey = baseRegistryKey.OpenSubKey(subKey);
string[] allApplications = uninstallKey.GetSubKeyNames();
//RegistryKey appKey = baseRegistryKey.OpenSubKey(subKey + "\\" + applicationSubKeyName);
RegistryKey appKey;
string appName;
string appVersion;
for (int i = 0; i < allApplications.Length; ++i)
{
appKey = baseRegistryKey.OpenSubKey(subKey + "\\" + allApplications[i]);
appName = (string)appKey.GetValue("DisplayName");
if (appName == "CMS App")
{
appVersion = (string)appKey.GetValue("DisplayVersion");
if (appVersion == "3.0.0")
bbInstallCMSApp.Hint = "You have the latest version of CMS App.";
else
bbInstallCMSApp.Hint = "There is a new CMS App available to install.";
// To end the loop
i = allApplications.Length;
}
}
}
There are 10 kinds of people in this world. Those who understand binary, and those who don't.
-
Jan 13th, 2022, 04:04 PM
#3
Re: [RESOLVED] Get the version number of an installed program
I believe you went way overkill on this. You can easily pull a file's version like this:
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(path-to-file);
string version = fvi.ProductVersion;
-
Jan 13th, 2022, 04:10 PM
#4
Thread Starter
PowerPoster
Re: [RESOLVED] Get the version number of an installed program
Originally Posted by Lord Orwell
I believe you went way overkill on this. You can easily pull a file's version like this:
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(path-to-file);
string version = fvi.ProductVersion;
How do I know what path-to-file is? The user has control over the destination folder when he installs.
There are 10 kinds of people in this world. Those who understand binary, and those who don't.
-
Jan 18th, 2022, 02:11 PM
#5
Re: [RESOLVED] Get the version number of an installed program
Originally Posted by MMock
How do I know what path-to-file is? The user has control over the destination folder when he installs.
well that would complicate things. If you're just trying to read your own app, that's easier.
Last edited by Lord Orwell; Jan 18th, 2022 at 02:19 PM.
-
Jan 18th, 2022, 02:20 PM
#6
Thread Starter
PowerPoster
Re: [RESOLVED] Get the version number of an installed program
No problem. It's resolved as in post #2.
Thanks.
There are 10 kinds of people in this world. Those who understand binary, and those who don't.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|