/// <summary> /// returns a recursive sequence of the sub keys of a registry key. /// </summary> /// <param name="ScopeKeyPath"></param> /// <returns></returns> public static IEnumerable <string> RegistryKeysDeep(string ScopeKeyPath) { var regKey = RegistryKeyExt.OpenRegistryKey(ScopeKeyPath); if (regKey == null) { yield break; } else { foreach (var subKeyName in regKey.GetSubKeyNames()) { // first, return the sub key. var subKeyPath = RegistryKeyExt.Combine(regKey.Name, subKeyName); yield return(subKeyPath); // next, return the sub keys of the sub key. foreach (var keyPath in RegistryKeyExt.RegistryKeysDeep(subKeyPath)) { yield return(keyPath); } } regKey.Close(); yield break; } }
/// <summary> /// returns a sequence of registry key paths to file extensions in the registry. /// </summary> /// <returns></returns> public static IEnumerable <string> FileExtensionRegistryKeys() { using (var cr = RegistryKey.OpenBaseKey(RegistryHive.ClassesRoot, RegistryView.Default)) { foreach (var keyName in cr.GetSubKeyNames()) { if ((keyName.Length > 0) && (keyName[0] == '.')) { var extPath = RegistryKeyExt.Combine(cr.Name, keyName); yield return(extPath); } } } yield break; }
public static RegistryKey OpenRegistryKey(string KeyPath) { RegistryKey subKey = null; var rootName = RegistryKeyExt.GetRoot(KeyPath); var subKeyPath = RegistryKeyExt.GetPathAfterRoot(KeyPath); if (rootName.IsNullOrEmpty()) { subKey = RegistryKeyExt.OpenBaseKey(KeyPath); } else { using (var bk = RegistryKeyExt.OpenBaseKey(rootName)) { subKey = bk.OpenSubKey(subKeyPath); } } return(subKey); }