Exemplo n.º 1
0
 public static bool SetBootFeatureConfigurations(List <FeatureConfiguration> configurations)
 {
     try
     {
         foreach (var config in configurations)
         {
             uint obfuscatedId  = RtlDataHelpers.GetObfuscatedFeatureId(config.FeatureId);
             var  obfuscatedKey = $@"SYSTEM\CurrentControlSet\Control\FeatureManagement\Overrides\{config.Group}\{obfuscatedId}";
             if (config.Action == FeatureConfigurationAction.Delete)
             {
                 Registry.LocalMachine.DeleteSubKeyTree(obfuscatedKey, false);
             }
             else
             {
                 using (var rKey = Registry.LocalMachine.CreateSubKey(obfuscatedKey))
                 {
                     if ((config.Action & FeatureConfigurationAction.UpdateEnabledState) == FeatureConfigurationAction.UpdateEnabledState)
                     {
                         rKey.SetValue("EnabledState", (int)config.EnabledState);
                         rKey.SetValue("EnabledStateOptions", config.EnabledStateOptions);
                     }
                     if ((config.Action & FeatureConfigurationAction.UpdateVariant) == FeatureConfigurationAction.UpdateVariant)
                     {
                         rKey.SetValue("Variant", config.Variant);
                         rKey.SetValue("VariantPayload", config.VariantPayload);
                         rKey.SetValue("VariantPayloadKind", config.VariantPayloadKind);
                     }
                 }
             }
         }
         return(true);
     } catch { return(false); }
 }
Exemplo n.º 2
0
 public static bool RemoveBootFeatureConfigurations(List <FeatureConfiguration> configurations)
 {
     try
     {
         foreach (var config in configurations)
         {
             uint obfuscatedId = RtlDataHelpers.GetObfuscatedFeatureId(config.FeatureId);
             Registry.LocalMachine.DeleteSubKeyTree($@"SYSTEM\CurrentControlSet\Control\FeatureManagement\Overrides\{config.Group}\{obfuscatedId}", false);
         }
         return(true);
     }
     catch { return(false); }
 }
Exemplo n.º 3
0
 public static bool RemoveBootFeatureUsageSubscriptions(List <FeatureUsageSubscription> subscriptions)
 {
     try
     {
         string[] bootSubs;
         using (var rKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\FeatureManagement\UsageSubscriptions"))
             bootSubs = rKey.GetSubKeyNames();
         foreach (var sub in subscriptions)
         {
             var obfuscatedKey = RtlDataHelpers.GetObfuscatedFeatureId(sub.FeatureId).ToString();
             if (bootSubs.Contains(obfuscatedKey))
             {
                 bool isEmpty = false;
                 obfuscatedKey = @"SYSTEM\CurrentControlSet\Control\FeatureManagement\UsageSubscriptions\" + obfuscatedKey;
                 using (var sKey = Registry.LocalMachine.OpenSubKey(obfuscatedKey, true))
                 {
                     foreach (var subGuid in sKey.GetSubKeyNames())
                     {
                         bool toRemove = false;
                         using (var gKey = sKey.OpenSubKey(subGuid))
                         {
                             if ((int)gKey.GetValue("ReportingKind") == sub.ReportingKind &&
                                 (int)gKey.GetValue("ReportingOptions") == sub.ReportingOptions &&
                                 BitConverter.ToUInt64((byte[])gKey.GetValue("ReportingTarget"), 0) == sub.ReportingTarget)
                             {
                                 toRemove = true;
                             }
                         }
                         if (toRemove)
                         {
                             sKey.DeleteSubKeyTree(subGuid, false);
                         }
                     }
                     isEmpty = sKey.SubKeyCount == 0;
                 }
                 if (isEmpty)
                 {
                     Registry.LocalMachine.DeleteSubKeyTree(obfuscatedKey, false);
                 }
             }
         }
         return(true);
     }
     catch { return(false); }
 }
Exemplo n.º 4
0
 public static bool AddBootFeatureUsageSubscriptions(List <FeatureUsageSubscription> subscriptions)
 {
     try
     {
         foreach (var sub in subscriptions)
         {
             uint obfuscatedId = RtlDataHelpers.GetObfuscatedFeatureId(sub.FeatureId);
             using (var rKey = Registry.LocalMachine.CreateSubKey($@"SYSTEM\CurrentControlSet\Control\FeatureManagement\UsageSubscriptions\{obfuscatedId}\{{{Guid.NewGuid()}}}"))
             {
                 rKey.SetValue("ReportingKind", (int)sub.ReportingKind);
                 rKey.SetValue("ReportingOptions", (int)sub.ReportingOptions);
                 rKey.SetValue("ReportingTarget", BitConverter.GetBytes(sub.ReportingTarget));
             }
         }
         return(true);
     }
     catch { return(false); }
 }