Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting application version numbers in C#

Getting application version numbers in C#

Scheduled Pinned Locked Moved C#
csharpjsontutorialquestionannouncement
12 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Matt Fishbeck
    wrote on last edited by
    #1

    Hello All. I would like to know what api calls/functions are required to retrieve all the application version numbers that are currently installed on a windows platform. What I want is to get all the version numbers as displayed when one goes to the Control Panel->Add/Remove Programs. I want to get the application names and the versions so I can generate reports, forward in an email etc. Does any body know how to do this? Many thanks, Matt

    D realJSOPR 2 Replies Last reply
    0
    • M Matt Fishbeck

      Hello All. I would like to know what api calls/functions are required to retrieve all the application version numbers that are currently installed on a windows platform. What I want is to get all the version numbers as displayed when one goes to the Control Panel->Add/Remove Programs. I want to get the application names and the versions so I can generate reports, forward in an email etc. Does any body know how to do this? Many thanks, Matt

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      You need to enumerate the registry entries in this location HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Expect everything to be hard and then enjoy the things that come easy. (code-frog)

      1 Reply Last reply
      0
      • M Matt Fishbeck

        Hello All. I would like to know what api calls/functions are required to retrieve all the application version numbers that are currently installed on a windows platform. What I want is to get all the version numbers as displayed when one goes to the Control Panel->Add/Remove Programs. I want to get the application names and the versions so I can generate reports, forward in an email etc. Does any body know how to do this? Many thanks, Matt

        realJSOPR Online
        realJSOPR Online
        realJSOP
        wrote on last edited by
        #3

        Try these: Assembly Version:

        Assembly.GetExecutingAssembly().GetName().Version

        File Version:

        System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        M M 3 Replies Last reply
        0
        • realJSOPR realJSOP

          Try these: Assembly Version:

          Assembly.GetExecutingAssembly().GetName().Version

          File Version:

          System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          M Offline
          M Offline
          Manas Bhardwaj
          wrote on last edited by
          #4

          He doesn't want o know his application's version but the version of all apllication on Windows... ;)

          Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

          1 Reply Last reply
          0
          • realJSOPR realJSOP

            Try these: Assembly Version:

            Assembly.GetExecutingAssembly().GetName().Version

            File Version:

            System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)

            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

            M Offline
            M Offline
            Matt Fishbeck
            wrote on last edited by
            #5

            Thanks, but how do I use 'Assembly.GetExecutingAssembly().GetName().Version' to get the applications the at are 'installed' on the system?

            realJSOPR 2 Replies Last reply
            0
            • M Matt Fishbeck

              Thanks, but how do I use 'Assembly.GetExecutingAssembly().GetName().Version' to get the applications the at are 'installed' on the system?

              realJSOPR Online
              realJSOPR Online
              realJSOP
              wrote on last edited by
              #6

              You'll have to use Interop services to check the version number of executables, and Use WMI to get a list of installed applications (look at the Win32_Product class). There is a "Version" property available that gives you what you want. BTW, there was no need for anyone to vote a 1 on my first response. That was pretty rude, considering nobody else has suggested a solution. Here's some code from one of my own projects. The GetObjectPropertyString() method is one of several helper methods I wrote that serve no other purpose than to clean up the code that I'm actually working in. No messy exception handling, no conversions - just a function call.

              //--------------------------------------------------------------------------------
              private static string GetObjectPropertyString(ManagementObject mo, string name, string defaultValue)
              {
              string value = defaultValue;
              try
              {
              value = mo[name].ToString();
              }
              catch (Exception ex)
              {
              if (ex != null) {}
              #if DEBUG
              System.Diagnostics.Trace.WriteLine(string.Format("GetObjectPropertyString() EXCEPTION - looking for {0} property", name));
              #endif
              }
              return value;
              }

              ManagementClass mc = new ManagementClass("Win32_Product");
              ManagementObjectCollection moc = mc.GetInstances();
              foreach (ManagementObject mo in moc)
              {
              string name = GetObjectPropertyString(mo, "Name", ""); // you can also use "Caption" or "Description"
              string version = GetObjectPropertyString(mo, "Version", "");
              }

              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

              modified on Friday, September 5, 2008 11:28 AM

              M 1 Reply Last reply
              0
              • realJSOPR realJSOP

                Try these: Assembly Version:

                Assembly.GetExecutingAssembly().GetName().Version

                File Version:

                System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)

                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                M Offline
                M Offline
                Matt Fishbeck
                wrote on last edited by
                #7

                Also, I need to get the version of an installation, not the individual assemblies within it. For example, If I have a driver installer version 1.0. I may contain the following sets; driverX.sys version 1.1 driverY.sys version 1.11 driverZ.sys version 1.12 Where is the Add/Remove feature in the control panel looking to obtain the 1.0? Regards, Matt

                1 Reply Last reply
                0
                • M Matt Fishbeck

                  Thanks, but how do I use 'Assembly.GetExecutingAssembly().GetName().Version' to get the applications the at are 'installed' on the system?

                  realJSOPR Online
                  realJSOPR Online
                  realJSOP
                  wrote on last edited by
                  #8

                  Did my last response help?

                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                  M 1 Reply Last reply
                  0
                  • realJSOPR realJSOP

                    You'll have to use Interop services to check the version number of executables, and Use WMI to get a list of installed applications (look at the Win32_Product class). There is a "Version" property available that gives you what you want. BTW, there was no need for anyone to vote a 1 on my first response. That was pretty rude, considering nobody else has suggested a solution. Here's some code from one of my own projects. The GetObjectPropertyString() method is one of several helper methods I wrote that serve no other purpose than to clean up the code that I'm actually working in. No messy exception handling, no conversions - just a function call.

                    //--------------------------------------------------------------------------------
                    private static string GetObjectPropertyString(ManagementObject mo, string name, string defaultValue)
                    {
                    string value = defaultValue;
                    try
                    {
                    value = mo[name].ToString();
                    }
                    catch (Exception ex)
                    {
                    if (ex != null) {}
                    #if DEBUG
                    System.Diagnostics.Trace.WriteLine(string.Format("GetObjectPropertyString() EXCEPTION - looking for {0} property", name));
                    #endif
                    }
                    return value;
                    }

                    ManagementClass mc = new ManagementClass("Win32_Product");
                    ManagementObjectCollection moc = mc.GetInstances();
                    foreach (ManagementObject mo in moc)
                    {
                    string name = GetObjectPropertyString(mo, "Name", ""); // you can also use "Caption" or "Description"
                    string version = GetObjectPropertyString(mo, "Version", "");
                    }

                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                    modified on Friday, September 5, 2008 11:28 AM

                    M Offline
                    M Offline
                    Matt Fishbeck
                    wrote on last edited by
                    #9

                    Thanks very much for your email. It all work perfectly now. Many thanks. Matt

                    1 Reply Last reply
                    0
                    • realJSOPR realJSOP

                      Did my last response help?

                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                      -----
                      "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                      M Offline
                      M Offline
                      Matt Fishbeck
                      wrote on last edited by
                      #10

                      Hello John. thanks for your response concerning ManagementClass and ManagementObjectCollection. I have implemented this which returns everything that I need but it is hideously slow. I have had to run it in a seperate thread since it sometime takes minutes to finish. Is this normal? Is there another way you know which is faster? When one click add remove programs it does not take this long..... Thanks, Matt

                      realJSOPR 1 Reply Last reply
                      0
                      • M Matt Fishbeck

                        Hello John. thanks for your response concerning ManagementClass and ManagementObjectCollection. I have implemented this which returns everything that I need but it is hideously slow. I have had to run it in a seperate thread since it sometime takes minutes to finish. Is this normal? Is there another way you know which is faster? When one click add remove programs it does not take this long..... Thanks, Matt

                        realJSOPR Online
                        realJSOPR Online
                        realJSOP
                        wrote on last edited by
                        #11

                        How long it takes depends on how much stuff you have installed, and what kind of system you have. I'm running XP-64 with 8gb of RAM and fairly speedy hard drives. With about 60 things installed, it takes about 4 seconds for Add/Remove Programs to populate itself. BTW, did you vote my response a 1?

                        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                        -----
                        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                        M 1 Reply Last reply
                        0
                        • realJSOPR realJSOP

                          How long it takes depends on how much stuff you have installed, and what kind of system you have. I'm running XP-64 with 8gb of RAM and fairly speedy hard drives. With about 60 things installed, it takes about 4 seconds for Add/Remove Programs to populate itself. BTW, did you vote my response a 1?

                          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                          -----
                          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                          M Offline
                          M Offline
                          Matt Fishbeck
                          wrote on last edited by
                          #12

                          I am running a dual core 2.3g pentium 2 with 2 gb of ram. See below for a list for the output of the program - note the elapsed time; It is strange because when I go to contorl panel - add/remove programs it is allot faster - even for the first time after boot. Perhaps windows in caching the entries where as this method probably reads through the registry in a manual fashion....See the output of the program below. <<< Querying registry for installed components. Please wait... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................................... ............................................

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups