private IRegKey GetExistingRegistryKey(IRegKey regKey, string path) { if (string.IsNullOrEmpty(path)) { return(regKey); } var pos = path.IndexOf('\\'); if (pos == -1) { var child = regKey.GetSubKey(path); if (child != null) { return(child); } return(null); } else { var child = regKey.GetSubKey(path.Substring(0, pos)); if (child == null) { return(null); } return(this.GetExistingRegistryKey(child, path.Substring(pos + 1))); } }
private static void RemoveRecurse(IRegKey foundKey) { foreach (var subKeyName in foundKey.Keys.Select(k => k.Name).ToArray()) { using var subKey = foundKey.GetSubKey(subKeyName); RemoveRecurse(subKey); } // remove all values foreach (var value in foundKey.Values.ToArray()) { foundKey.RemoveValue(value.Name); } foundKey.Parent.RemoveSubKey(foundKey.Name); }