Results 1 to 6 of 6

Thread: [RESOLVED] Get the version number of an installed program

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Resolved [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.

    Name:  CMSApp's version number.jpg
Views: 128
Size:  11.1 KB
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    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.

  3. #3
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    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;
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  4. #4

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: [RESOLVED] Get the version number of an installed program

    Quote Originally Posted by Lord Orwell View Post
    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.

  5. #5
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,621

    Re: [RESOLVED] Get the version number of an installed program

    Quote Originally Posted by MMock View Post
    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.
    My light show youtube page (it's made the news) www.youtube.com/@artnet2twinkly
    Contact me on the socials www.facebook.com/lordorwell

  6. #6

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    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
  •  



Click Here to Expand Forum to Full Width