Last active
February 7, 2026 10:24
-
-
Save imba-tjd/b54c61382800cf186add0a69e24a2c74 to your computer and use it in GitHub Desktop.
Windows EcoQoS / Efficency Mode Enabler CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /o /platform:x64 eco.cs && C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ngen.exe install eco.exe | |
| // Known issue: not work and no error for UWP apps. | |
| using System; | |
| using System.Diagnostics; | |
| using System.Runtime; | |
| using System.Runtime.InteropServices; | |
| using System.Collections.Generic; | |
| using System.ComponentModel; | |
| static class Eco | |
| { | |
| [DllImport("Kernel32", SetLastError = true)] | |
| static extern bool SetProcessInformation(IntPtr hProcess, int PROCESS_INFORMATION_CLASS, ref PROCESS_POWER_THROTTLING_STATE pi, int ProcessInformationSize); | |
| struct PROCESS_POWER_THROTTLING_STATE | |
| { | |
| public uint Version; | |
| public uint ControlMask; | |
| public uint StateMask; | |
| } | |
| const int ProcessPowerThrottling = 4; | |
| const int PROCESS_POWER_THROTTLING_CURRENT_VERSION = 1; | |
| const int PROCESS_POWER_THROTTLING_EXECUTION_SPEED = 1; | |
| static readonly int STATE_SIZE = Marshal.SizeOf<PROCESS_POWER_THROTTLING_STATE>(); | |
| static PROCESS_POWER_THROTTLING_STATE STATE = new PROCESS_POWER_THROTTLING_STATE | |
| { | |
| Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION, | |
| ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED, | |
| StateMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED | |
| }; | |
| public static string Set(IntPtr hProcess) | |
| { | |
| if (!SetProcessInformation(hProcess, ProcessPowerThrottling, ref STATE, STATE_SIZE)) | |
| return new Win32Exception(Marshal.GetLastWin32Error()).Message; | |
| return null; | |
| } | |
| } | |
| class Program | |
| { | |
| static int Main(string[] args) | |
| { | |
| GCSettings.LatencyMode = GCLatencyMode.LowLatency; | |
| if (args.Length == 0) | |
| { | |
| Console.WriteLine("Usage: eco notepad ..."); | |
| return 0; | |
| } | |
| var targetPs = new HashSet<string>(args); | |
| int cnt = 0; | |
| foreach(var p in Process.GetProcesses()) | |
| { | |
| if (targetPs.Contains(p.ProcessName.ToLowerInvariant())) | |
| { | |
| string ret = Eco.Set(p.Handle); | |
| if (ret != null) | |
| Console.Error.WriteLine("Failed to access {0}: {1}", p.ProcessName, ret); | |
| else | |
| cnt++; | |
| } | |
| } | |
| if (cnt != args.Length) | |
| { | |
| Console.Error.WriteLine("{0} succeed.", cnt); | |
| return 1; | |
| } | |
| else | |
| return 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment