Click here to Skip to main content
Click here to Skip to main content

Get Version of a Software using C#

, 29 Dec 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Get Version of any software on MSI installed in any System/Server

Introduction 

This DLL will get you the Version of the software that is present in your installed programs in control panel. This is specially use full when we might need to get the MSI version of any product that we drop in servers.

Using the code

//Download the "ReadSoftwareVersion.dll" from the attachments and add it to the references of your project 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReadSoftwareVersion;

namespace TestVersion
{
    class Program
    {
        static void Main(string[] args)
        {
            Software objVersion = new Software();
            string version = objVersion.GetSoftwateVersion("Your Software Name");
            Console.WriteLine(version);
            Console.ReadLine();
        }
    }
}
// This is a Wild Card Search. You need not give full name for "Your Software Name" 

Actual Code inside the "ReadSoftwareVersion.dll" 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;  // Include this in references

namespace ReadSoftwareVersion
{
    // your own class name
    public class Software
    {
        // Method that will fetch the version of a given software
        public string GetSoftwateVersion(string softWareName)
        {
            string strVersion = string.Empty;
            try
            {
                var version = (object)null;
                //Query the system registery for the verion of the given software                
                var searcher = new ManagementObjectSearcher(
                  "SELECT * FROM Win32_Product where Name LIKE " + 
                  "'%" + softWareName + "%'");
                foreach (ManagementObject obj in searcher.Get())
                {
                    version = obj["Version"];
                }
                if (version != null)
                {
                    strVersion = (String)version;
                }
                // if given product is not found in list of installed products in control panel
                else
                {
                    strVersion = "Given Product is not found the list of Installed Programs";
                }
            }
            // Exception Handling
            catch (Exception e)
            {
                strVersion = "An Error occured while fetching Version" + 
                  " (" + e.Message + ")";
            }
            return strVersion;
        }
    }
}

Here just a Console Application is shown for DEMO. In general, this dll can be added to any project, i.e to web application.... where ever needed.

Points of Interest

This will specially help in the cases where we need to fetch the MSI information of the product that is dropped in remote server. Generally, we might need to follow with installation teams to get the MSI Version. But using this we can fetch the MSI Version and display it in UI, if needed. This method is relatively slow and will take around 10 to 20 seconds to execute. This is completely tested and 100% working.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dinesh Thammineni
Systems Engineer
India India
No Biography provided

Comments and Discussions

 
GeneralFile download Problem PinmemberAbhishek Pant27-Dec-13 19:38 
GeneralRe: File download Problem PinprofessionalDinesh Thammineni28-Dec-13 20:09 
GeneralRe: File download Problem PinmemberAbhishek Pant29-Dec-13 20:51 
Questioncannot download source file Pinmemberfredatcodeproject27-Dec-13 15:21 
AnswerRe: cannot download source file PinprofessionalDinesh Thammineni28-Dec-13 20:10 
GeneralRe: cannot download source file Pinmemberfredatcodeproject30-Dec-13 13:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1411023.1 | Last Updated 29 Dec 2013
Article Copyright 2013 by Dinesh Thammineni
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid