public int CompareTo(object obj) { SoftwareInfo other = (obj as SoftwareInfo); if (other == null) { throw new ArgumentException(obj.GetType().Name); } return(this.productName.CompareTo(other.productName)); }
public List <SoftwareInfo> GetSoftware() { Console.Write("Enumerating software"); int swEnum = 0; if (Win32KernelCalls.IsOS64Bit()) { //64-bit OS List <SoftwareInfo> result = new List <SoftwareInfo>(); try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Product"); foreach (ManagementObject queryObj in searcher.Get()) { SoftwareInfo child = new SoftwareInfo(); child.productName = (string)queryObj["Caption"]; child.installPath = (string)queryObj["InstallLocation"]; child.manufacterer = (string)queryObj["Vendor"]; child.registrationKey = ""; child.version = (string)queryObj["Version"]; result.Add(child); if ((swEnum++ % 10) == 0) { Console.Write("."); } } } catch (Exception e) { throw; } //Der folgende Code listet alle 32-bit Applikation. (Das ist schon einfacher... :D) RegistryKey targetKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); ScanSoftwareRegistryKey(targetKey, result); result.Sort((x, y) => (x.CompareTo(y))); Console.WriteLine("."); return(result); } else { //32-bit OS (trivial...) RegistryKey targetKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"); Console.WriteLine("."); return(ScanSoftwareRegistryKey(targetKey)); } }
public override bool Equals(object obj) { SoftwareInfo other = (obj as SoftwareInfo); if (other == null) { return(false); } if ((productName == null) && (other.productName == null)) { return(true); } return(productName.Equals(other.productName)); }
private void ScanSoftwareRegistryKey(RegistryKey rk, List <SoftwareInfo> outputList) { while (true) { //Zunächst Liste von nullern säubern, um Crash im nächsten Block zu vermeiden. (kann bei Win7-64 mal passieren...) SoftwareInfo si = outputList.Find(x => string.IsNullOrEmpty(x.productName)); if (si != null) { outputList.Remove(si); continue; } break; } foreach (string subKeyName in rk.GetSubKeyNames()) { RegistryKey subkey = rk.OpenSubKey(subKeyName, false); string dn = (string)subkey.GetValue("DisplayName"); if (!string.IsNullOrEmpty(dn)) { /*if (!outputList.Contains(dn)) * { * outputList.Add(dn); * }*/ if (outputList.Find(x => x.productName.Equals(dn)) == null) { SoftwareInfo child = new SoftwareInfo(); child.productName = dn; child.manufacterer = (string)subkey.GetValue("Publisher"); child.installPath = (string)subkey.GetValue("InstallLocation"); child.version = (string)subkey.GetValue("DisplayVersion"); outputList.Add(child); } } } }