Method for C to Obtain Software Inventory through windows Registry

  • 2021-07-18 08:48:14
  • OfStack

This article illustrates how C # obtains software inventory through windows registry. Share it for your reference. The details are as follows:


foreach (string SoftwareName in Object.SoftwareList())
{
  textBox.Text += SoftwareName + Environment.NewLine;
}
////////////////////////////////////////////////////////////////////////
/// <summary>
/// Windows System Acquisition Software List 
/// </summary>
/// <returns>String [] softwareList</returns>
public String [] SoftwareList()
{
 String[] softwareList = null;
 // Dynamic array 
 ArrayList list = new ArrayList();
 try
 {
  // Turn on the Register List Uninstall option 
  //SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  RegistryKey Key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
  if (Key != null)// Returns if the system disables access null
  {
   foreach (String SubKeyName in Key.GetSubKeyNames())
   {
    // Open the corresponding software name 
    RegistryKey SubKey = Key.OpenSubKey(SubKeyName);
    if (SubKey != null)
    {
     String SoftwareName = SubKey.GetValue("DisplayName", "Nothing").ToString();
     // If it is not fetched, it is not stored in the dynamic array 
     if (SoftwareName != "Nothing")
     {
      list.Add(SoftwareName);
     }
    }
   }
   // Cast to an array of strings to prevent overflow of modified data 
   softwareList = (string[])list.ToArray(typeof(string));
  }
 }
 catch (Exception err)
 {
  Console.WriteLine(" Error message :" + err.ToString());
 }
 return softwareList;
}

I hope this article is helpful to everyone's C # programming.


Related articles: