Gets a list of installed software

Tips, tricks and other stuff
Post Reply
User avatar

Topic author
Superl
Site Admin
Site Admin
Posts: 1267
Joined: Sat Apr 16, 2011 7:49 am
Location: Montreal, Canada
Contact:

Gets a list of installed software

#2284

Post by Superl » Sun Dec 20, 2015 7:19 pm

Gets a list of installed software Introduction:
Gets a list of installed software and, if known, the software's install path.
  1. /// <summary>
  2. /// Gets a list of installed software and, if known, the software's install path.
  3. /// </summary>
  4. /// <returns></returns>
  5. private string Getinstalledsoftware()
  6. {
  7.       //Declare the string to hold the list:
  8.       string Software = null;
  9.  
  10.       //The registry key:
  11.       string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
  12.       using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
  13.       {
  14.             //Let's go through the registry keys and get the info we need:
  15.             foreach (string skName in rk.GetSubKeyNames())
  16.             {
  17.                   using (RegistryKey sk = rk.OpenSubKey(skName))
  18.                   {
  19.                         try
  20.                         {
  21.                               //If the key has value, continue, if not, skip it:
  22.                               if (!(sk.GetValue("DisplayName") == null))
  23.                               {
  24.                                     //Is the install location known?
  25.                                     if (sk.GetValue("InstallLocation") == null) //Nope, not here.
  26.                                           Software += sk.GetValue("DisplayName") + " - Install path not known\n";                                          
  27.                                     else //Yes, here it is...
  28.                                         Software += sk.GetValue("DisplayName") + " - " +                                                                                               sk.GetValue("InstallLocation") + "\n";
  29.                               }
  30.                         }
  31.                         catch (Exception ex)
  32.                        {
  33.                        //No, that exception is not getting away... :P
  34.                        }
  35.                  }
  36.             }
  37.       }
  38.  
  39. return Software;
  40. }
Example usage:

Code: Select all

//Example usage:
private void get_software_list_button__Click(object sender, EventArgs e)
{
      MessageBox.Show(Getinstalledsoftware());
}


Come and say hello in here
Any donation will help click here please.

Have a nice day :103:

Post Reply

Return to “How To Forum”

Who is online

Users browsing this forum: No registered users and 1 guest