Gets a list of installed software and, if known, the software's install path.
Code: Select all
/// <summary>
/// Gets a list of installed software and, if known, the software's install path.
/// </summary>
/// <returns></returns>
private string Getinstalledsoftware()
{
      //Declare the string to hold the list:
      string Software = null;
      //The registry key:
      string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
      using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey))
      {
            //Let's go through the registry keys and get the info we need:
            foreach (string skName in rk.GetSubKeyNames())
            {
                  using (RegistryKey sk = rk.OpenSubKey(skName))
                  {
                        try
                        {
                              //If the key has value, continue, if not, skip it:
                              if (!(sk.GetValue("DisplayName") == null))
                              {
                                    //Is the install location known?
                                    if (sk.GetValue("InstallLocation") == null) //Nope, not here.
                                          Software += sk.GetValue("DisplayName") + " - Install path not known\n";                                          
                                    else //Yes, here it is...
                                        Software += sk.GetValue("DisplayName") + " - " +                                                                                               sk.GetValue("InstallLocation") + "\n";
                              }
                        }
                        catch (Exception ex)
                       {
                       //No, that exception is not getting away... :P
                       }
                 }
            }
      }
return Software;
}Code: Select all
//Example usage:
private void get_software_list_button__Click(object sender, EventArgs e)
{
      MessageBox.Show(Getinstalledsoftware());
} 


 
	 
						
