public static IEnumerable <Tuple <string, string, object, RegistryValueKind> > EnumerateValues(this RegistryKey key, bool recursive = false, bool failOnSecurityException = false) { if (key == null) { throw new ArgumentNullException("key"); } foreach (var value in key.GetValueNames()) { yield return(new Tuple <string, string, object, RegistryValueKind>(key.Name, value, key.GetValue(value), key.GetValueKind(value))); } if (recursive) { foreach (var subKey in key.GetSubKeyNames()) { using (RegistryKey openedSubKey = key.OpenSubKeyInternal(subKey, failOnSecurityException)) { if (openedSubKey != null) { foreach (var tuple in openedSubKey.EnumerateValues(recursive, failOnSecurityException)) { yield return(tuple); } } } } } }
public static IEnumerable <Tuple <string, string, object, RegistryValueKind> > EnumerateValues(this RegistryKey key, string subKey, bool recursive = false, bool failOnSecurityException = false) { if (key == null) { throw new ArgumentNullException("key"); } if (string.IsNullOrEmpty(subKey)) { foreach (var tuple in key.EnumerateValues(recursive, failOnSecurityException)) { yield return(tuple); } } else { using (RegistryKey openedSubKey = key.OpenSubKeyInternal(subKey, failOnSecurityException)) { if (openedSubKey != null) { foreach (var tuple in openedSubKey.EnumerateValues(recursive, failOnSecurityException)) { yield return(tuple); } } } } }
private List <Tuple <string, string, uint> > GetScalingsList() { using (RegistryKey key = Registry.LocalMachine.OpenSubKey(graphicsDriversConfigurationSubKey)) { return(key.EnumerateValues(true). Where(tuple => tuple.Item2 == "Scaling" && tuple.Item4 == RegistryValueKind.DWord). Select(tuple => new Tuple <string, string, uint>(tuple.Item1, tuple.Item2, Convert.ToUInt32(tuple.Item3))). ToList()); } }