Click here to Skip to main content
15,885,366 members
Articles / Web Development / ASP.NET
Tip/Trick

Get Version of a Software using C#

Rate me:
Please Sign up or sign in to vote.
4.44/5 (7 votes)
29 Dec 2013CPOL 34.6K   711   17   8
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

C#
//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" 

C#
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)


Written By
Systems Engineer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionRemote access? Pin
Member 1581252528-Oct-22 1:52
Member 1581252528-Oct-22 1:52 
QuestionTo get list of all installed app in windows 10/11 Pin
sameer.covetus5-May-22 14:57
sameer.covetus5-May-22 14:57 
GeneralFile download Problem Pin
Abhishek Pant27-Dec-13 18:38
professionalAbhishek Pant27-Dec-13 18:38 
GeneralRe: File download Problem Pin
Dinesh Thammineni28-Dec-13 19:09
professionalDinesh Thammineni28-Dec-13 19:09 
GeneralRe: File download Problem Pin
Abhishek Pant29-Dec-13 19:51
professionalAbhishek Pant29-Dec-13 19:51 
Questioncannot download source file Pin
fredatcodeproject27-Dec-13 14:21
professionalfredatcodeproject27-Dec-13 14:21 
AnswerRe: cannot download source file Pin
Dinesh Thammineni28-Dec-13 19:10
professionalDinesh Thammineni28-Dec-13 19:10 
GeneralRe: cannot download source file Pin
fredatcodeproject30-Dec-13 12:02
professionalfredatcodeproject30-Dec-13 12:02 

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

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