/// <summary> /// Looks through the uninstall keys in the registry to see if a certain piece of software is installed. /// </summary> /// <param name="name">The software to look for.</param> /// <param name="comparer">How to search for the software.</param> /// <returns>True if the software is found, else false.</returns> public static bool FindSoftware(string name, RegistryComparer comparer) { if (string.IsNullOrEmpty(name)) { return(false); } //Current User var uninstallKeys = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); if (FindKey(uninstallKeys, name, comparer)) { return(true); } //x86 Registry uninstallKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); if (FindKey(uninstallKeys, name, comparer)) { return(true); } //x64 Registry uninstallKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); if (FindKey(uninstallKeys, name, comparer)) { return(true); } return(false); }
public static bool FindKey(RegistryKey root, string key, RegistryComparer comparer) { if (!string.IsNullOrEmpty(key) && root != null) { try { Func <string, string, bool> compare; if (comparer == RegistryComparer.Contains) { compare = (x, y) => x.Contains(y); } else { compare = (x, y) => x == y; } using (root) { var keyFound = root.GetSubKeyNames() .Select(root.OpenSubKey) .Where(x => x != null) .Select(x => Convert.ToString(x.GetValue("DisplayName"), CultureInfo.CurrentCulture)) .Any(x => !string.IsNullOrEmpty(x) && compare(x, key)); if (keyFound) { return(true); } } } catch { return(false); } } return(false); }
public static bool FindKey(RegistryKey root, string key, RegistryComparer comparer) { if (!string.IsNullOrEmpty(key) && root != null) { try { Func<string, string, bool> compare; if (comparer == RegistryComparer.Contains) { compare = (x, y) => x.Contains(y); } else { compare = (x, y) => x == y; } using (root) { var keyFound = root.GetSubKeyNames() .Select(root.OpenSubKey) .Where(x => x != null) .Select(x => Convert.ToString(x.GetValue("DisplayName"), CultureInfo.CurrentCulture)) .Any(x => !string.IsNullOrEmpty(x) && compare(x, key)); if (keyFound) return true; } } catch { return false; } } return false; }
/// <summary> /// Looks through the uninstall keys in the registry to see if a certain piece of software is installed. /// </summary> /// <param name="name">The software to look for.</param> /// <param name="comparer">How to search for the software.</param> /// <returns>True if the software is found, else false.</returns> public static bool FindSoftware(string name, RegistryComparer comparer) { if (string.IsNullOrEmpty(name)) return false; //Current User var uninstallKeys = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); if (FindKey(uninstallKeys, name, comparer)) return true; //x86 Registry uninstallKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"); if (FindKey(uninstallKeys, name, comparer)) return true; //x64 Registry uninstallKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"); if (FindKey(uninstallKeys, name, comparer)) return true; return false; }