private void SetRegistryFlag(ResourceHealthComponent component, bool registryValue) { RegistryKey registryKey = null; try { registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchange ResourceHealth", true); if (registryKey == null) { registryKey = Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchange ResourceHealth", RegistryKeyPermissionCheck.ReadWriteSubTree); } registryKey.SetValue(component.ToString(), registryValue ? 1 : 0, RegistryValueKind.DWord); } catch (SecurityException ex) { base.WriteError(new LocalizedException(new LocalizedString(ex.Message)), ErrorCategory.PermissionDenied, null); } catch (UnauthorizedAccessException ex2) { base.WriteError(new LocalizedException(new LocalizedString(ex2.Message)), ErrorCategory.PermissionDenied, null); } finally { if (registryKey != null) { ((IDisposable)registryKey).Dispose(); } } }
internal bool?CheckRegistryActive(ResourceHealthComponent component) { bool?result; try { using (RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\MSExchange ResourceHealth", false)) { if (registryKey == null) { result = null; } else { object value = registryKey.GetValue(component.ToString()); if (value == null || !(value is int)) { result = null; } else { result = new bool?((int)value != 0); } } } } catch (SecurityException ex) { base.WriteError(new LocalizedException(new LocalizedString(ex.Message)), ErrorCategory.PermissionDenied, null); result = new bool?(false); } catch (UnauthorizedAccessException ex2) { base.WriteError(new LocalizedException(new LocalizedString(ex2.Message)), ErrorCategory.PermissionDenied, null); result = new bool?(false); } return(result); }