Skip to content

Instantly share code, notes, and snippets.

@Mijyuoon
Created August 17, 2019 03:04
Show Gist options
  • Save Mijyuoon/c263afc5623acebeb599e4bb36ee814a to your computer and use it in GitHub Desktop.
Save Mijyuoon/c263afc5623acebeb599e4bb36ee814a to your computer and use it in GitHub Desktop.
IntelDPSTDisable
using System;
using Microsoft.Win32;
namespace IntelDPSTDisable {
class Program {
static string RegPath = @"System\{0}\Control\Class\{{4d36e968-e325-11ce-bfc1-08002be10318}}\{1}";
static string[] CSs = new[] { "ControlSet001", "CurrentControlSet" };
static string[] IDs = new[] { "0000", "0001" };
static string FeatValue = "FeatureTestControl";
static int[] FeatBit = new[] { 0x10, 0x10, 0x00 }; // mask, disable, enable
static string PwrValue1 = "DCUserPreferencePolicy";
static string PwrValue2 = "PowerDcPolicy";
static string PwrValue3 = "PowerAcPolicy";
static int[] PwrBit = new[] { 0x02, 0x00, 0x02 }; // mask, disable, enable
static int MaskSet(int val, int mask, int set) {
return (val & ~mask) | (set & mask);
}
static void ProcessValue(RegistryKey subkey, string value, int[] bits, bool isEnable) {
int oval = (int)subkey.GetValue(value);
if((oval & bits[0]) != bits[1]) {
int nval = MaskSet(oval, bits[0], bits[isEnable ? 2 : 1]);
Console.WriteLine(" * {0} = {1:X8}, wrong!", value, oval);
Console.WriteLine(" > Resetting to {0:X8}", nval);
subkey.SetValue(value, nval);
int vval = (int)subkey.GetValue(value);
Console.WriteLine(" Verification: {0:X8} == {1:X8}", nval, vval);
if(nval != vval) {
Console.WriteLine(" > Verification failed!");
}
} else {
Console.WriteLine(" * {0} = {1:X8}, already correct", value, oval);
}
}
static void Main(string[] args) {
Console.WriteLine("Select option:");
Console.WriteLine(" 1. Disable DPST");
Console.WriteLine(" 2. Enable DPST");
Console.Write("> ");
bool isEnable;
switch(Console.ReadKey().Key) {
case ConsoleKey.D1:
isEnable = false;
Console.WriteLine("\nDisabling DPST...\n");
break;
case ConsoleKey.D2:
isEnable = true;
Console.WriteLine("\nEnabling DPST...\n");
break;
default:
Console.WriteLine("Invalid option selected");
return;
}
foreach(var cset in CSs) {
Console.WriteLine("Checking control set {0}...", cset);
foreach(var ikid in IDs) {
var path = String.Format(RegPath, cset, ikid);
var subkey = Registry.LocalMachine.OpenSubKey(path, true);
if(subkey.GetValue(PwrValue1) is null) continue;
Console.WriteLine("* {0}", path);
ProcessValue(subkey, PwrValue1, PwrBit, isEnable);
ProcessValue(subkey, PwrValue2, PwrBit, isEnable);
ProcessValue(subkey, PwrValue3, PwrBit, isEnable);
ProcessValue(subkey, FeatValue, FeatBit, isEnable);
}
Console.WriteLine();
}
Console.WriteLine("Completed. Press any key to exit...");
Console.ReadKey(true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment