Wednesday, September 25, 2013

Get installed application list in windows OS using C#.Net

Find installed application in my PC using C#.Net

Some time we need to know before installing our new setup file it’s already installed or not in the computer. In the below examples I have explained how to get list of application installed in the system (OS) using C#.Net 2.0. The Example 1 will give you more quick result compare then Example 2.

  private void Form1_Load(object sender, EventArgs e)

In the Example1 explained get the registory access and display the list of installed application in the windows system.

Example 1:
//Check the list of application installed in the OS
        private bool CheckInstalledApplication()
            string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
            string strDispName;
            List<string> lsRegistory = new List<string>();
            using (RegistryKey rkRegistryKeyOne = Registry.LocalMachine.OpenSubKey(SoftwareKey))
                foreach (object varName in rkRegistryKeyOne.GetSubKeyNames())
                    using (RegistryKey rkRegistryKeyTwo = rkRegistryKeyOne.OpenSubKey(varName.ToString()))
                        strDispName = Convert.ToString(rkRegistryKeyTwo.GetValue("DisplayName"));
                        if (!string.IsNullOrEmpty(strDispName))
                            lsRegistory.Add(strDispName + " ---> " + Convert.ToString(rkRegistryKeyTwo.GetValue("DisplayVersion")));
            listBox1.DataSource = lsRegistory.ToArray();
            return true;            

In the Example2 explained using management object get the win32 product list from the windows OS.

Example 2:
using System.Management;
        private void LoadSoftwareList()
            ManagementObjectCollection moReturn;
            ManagementObjectSearcher moSearch;

            moSearch = new ManagementObjectSearcher("Select * from Win32_Product");

            moReturn = moSearch.Get();
            foreach (ManagementObject mo in moReturn)

Note: Thanks to Antony

No comments: