コード例 #1
0
        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();
                }
            }
        }
コード例 #2
0
 // Token: 0x06007676 RID: 30326 RVA: 0x00186058 File Offset: 0x00184258
 public static void Initialize(ResourceHealthComponent resourceHealthComponent)
 {
     if (resourceHealthComponent == ResourceHealthComponent.None)
     {
         throw new ArgumentException("You should not use ResourceHealthComponent.None when initializing the ResourceHealthMonitorManager.");
     }
     if (!ResourceHealthMonitorManager.Initialized)
     {
         ResourceHealthMonitorManager.resourceHealthComponent = resourceHealthComponent;
         ResourceHealthMonitorManager.CheckRegistryActive();
         return;
     }
     if (resourceHealthComponent != ResourceHealthMonitorManager.resourceHealthComponent)
     {
         throw new InvalidOperationException("ResourceHealthMonitorManager was already initialized with budget type: " + resourceHealthComponent);
     }
 }
コード例 #3
0
        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);
        }