private static Dictionary <string, string> ParseWinNT51_52Keys() { // With NT 5.1 and 5.2 (XP and Server 2003/XP 64bit) Windows uninstalled updates by the // SOFTWARE\Microsoft\Updates registry key. Then using the "UninstallCommand" key within. // Registry Keys used to uninstall updates. First is default; Second is for 32bit apps on 64bit Windows. var uninstallKeys = new List <string>(); uninstallKeys.Add(@"SOFTWARE\Microsoft\Updates\Windows XP"); var uninstallDict = new Dictionary <string, string>(); // Ugly iteration of the registry keys. foreach (string key in uninstallKeys) { using (RegistryKey rootXpKey = Registry.LocalMachine.OpenSubKey(key)) { if (rootXpKey != null) { foreach (var subName in rootXpKey.GetSubKeyNames()) { using (var subKey = rootXpKey.OpenSubKey(subName)) { if (subKey != null) { foreach (var kbName in subKey.GetSubKeyNames()) { using (var kbKey = subKey.OpenSubKey(kbName)) { if (kbKey != null && ((kbKey.GetValue("Description") != null) && (kbKey.GetValue("UninstallCommand") != null))) { var kbString = WindowsUpdates.GetKbString(kbKey.GetValue("Description").ToString()); var uninstallString = kbKey.GetValue("UninstallCommand").ToString(); if (!uninstallDict.ContainsKey(kbString)) { uninstallDict.Add(kbString, uninstallString); } } } } } } } } } } return(uninstallDict); }
private Dictionary <string, string> ParseUninstallKeys() { // This logic is only reliable for packages/applications that install system wide "UninstallString" keys in the // Windows registry (aka "the pit of horse shit"). // Registry Keys used to uninstall apps. First is default; Second is for 32bit apps on 64bit Windows. var uninstallKeys = new List <string>(); uninstallKeys.Add(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); if (_win64) { uninstallKeys.Add(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); } var programDict = new Dictionary <string, string>(); foreach (var key in uninstallKeys) { using (var rKey = Registry.LocalMachine.OpenSubKey(key)) { if (rKey != null) { foreach (var skName in rKey.GetSubKeyNames()) { using (var sk = rKey.OpenSubKey(skName)) { if (sk != null && ((sk.GetValue("DisplayName") != null) && (sk.GetValue("UninstallString") != null))) { var kbString = WindowsUpdates.GetKbString(sk.GetValue("DisplayName").ToString()); var uninstallString = sk.GetValue("UninstallString").ToString(); if (!programDict.ContainsKey(kbString)) { programDict.Add(kbString, uninstallString); } } } } } } } return(programDict); }