Пример #1
0
        public static ProtocolHandlerState GetState()
        {
            try
            {
                bool bHasAny = false;
                bool bHasAll = true;

                List <RegistrySetting> Keys = GetRegistrySettings();
                foreach (IGrouping <RegistryKey, RegistrySetting> RootKeyGroup in Keys.GroupBy(x => x.RootKey))
                {
                    foreach (IGrouping <string, RegistrySetting> KeyNameGroup in RootKeyGroup.GroupBy(x => x.KeyName))
                    {
                        using (RegistryKey RegistryKey = RootKeyGroup.Key.OpenSubKey(KeyNameGroup.Key))
                        {
                            if (RegistryKey == null)
                            {
                                bHasAll = false;
                            }
                            else
                            {
                                bHasAll &= KeyNameGroup.All(x => (RegistryKey.GetValue(x.ValueName) as string) == x.Value);
                                bHasAny  = true;
                            }
                        }
                    }
                }

                return(bHasAll? ProtocolHandlerState.Installed : bHasAny?ProtocolHandlerState.Unknown : ProtocolHandlerState.NotInstalled);
            }
            catch
            {
                return(ProtocolHandlerState.Unknown);
            }
        }
Пример #2
0
 public static void InstallElevated()
 {
     try
     {
         List <RegistrySetting> Keys = GetRegistrySettings();
         foreach (IGrouping <RegistryKey, RegistrySetting> RootKeyGroup in Keys.GroupBy(x => x.RootKey))
         {
             foreach (IGrouping <string, RegistrySetting> KeyNameGroup in RootKeyGroup.GroupBy(x => x.KeyName))
             {
                 using (RegistryKey RegistryKey = RootKeyGroup.Key.CreateSubKey(KeyNameGroup.Key))
                 {
                     foreach (RegistrySetting Setting in KeyNameGroup)
                     {
                         RegistryKey.SetValue(Setting.ValueName, Setting.Value);
                     }
                 }
             }
         }
     }
     catch (Exception Ex)
     {
         MessageBox.Show(String.Format("Unable to register protocol handler: {0}", Ex));
     }
 }