public static bool OpenWritableSubKeySafe(this RegistryKey key, string name, Func<RegistryKey, bool> onSuccess) { try { using (var subKey = key.OpenSubKey(name, true)) { if (subKey == null) return false; return onSuccess(subKey); } } catch { return false; } }