I’m trying to enable Efficiency Mode (EcoQoS) for a process given its process ID (PID). I have referred to this similar question on Stack Overflow, but I’m still facing issues.
Issue:
Although the logs indicate that EcoQoS is being enabled, it is not reflected in Task Manager. For any process, if Efficiency Mode is on, Task Manager should show the status for that process in Efficiency Mode.
Goal:
Enable EcoQoS for a given PID. Currently, I am trying this in a sample C++ console application in Visual Studio 2022 in Windows 11. Eventually, I plan to integrate this approach into a larger UWP application written in .NET C#.
Code:
#include <iostream>
#include <windows.h>
#include <pdh.h>
#include <pdhmsg.h>
#include <tchar.h>
#include <sstream>
#pragma comment(lib, "pdh.lib")
// Enables EcoQoS (power throttling) for a specific process by its PID
void enable_ecoqos_for_pid(DWORD pid) {
// Open a handle to the target process with the required access rights
HANDLE hProcess = OpenProcess(PROCESS_SET_INFORMATION, FALSE, pid);
if (hProcess == NULL) {
// Log an error message if the process handle cannot be obtained
std::cerr << "Failed to open process. Error: " << GetLastError() << std::endl;
return;
}
// Initialize the power throttling state structure
PROCESS_POWER_THROTTLING_STATE powerThrottlingState = {};
powerThrottlingState.Version = PROCESS_POWER_THROTTLING_CURRENT_VERSION;
powerThrottlingState.ControlMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
powerThrottlingState.StateMask = PROCESS_POWER_THROTTLING_EXECUTION_SPEED;
// Apply the power throttling settings to the target process
if (!SetProcessInformation(hProcess, ProcessPowerThrottling, &powerThrottlingState, sizeof(powerThrottlingState))) {
// Log an error message if setting the power throttling information fails
std::cerr << "Failed to enable power throttling for PID " << pid << ". Error: " << GetLastError() << std::endl;
} else {
// Log a success message if the power throttling settings are applied successfully
std::cout << "Power throttling enabled successfully for PID " << pid << "." << std::endl;
}
// Close the handle to the process to free resources
CloseHandle(hProcess);
}
int main() {
// Define the process ID for which EcoQoS should be enabled
DWORD pid = 16196;
// Enable EcoQoS for the specified process ID
enable_ecoqos_for_pid(pid);
// Print a message indicating the end of the program
std::cout << "Hello World!" << std::endl;
// Return 0 to indicate successful program termination
return 0;
}
Questions:
- Is my code correctly enabling Efficiency Mode for the given PID?
- How can I verify that Efficiency Mode is enabled for the process, especially when it is not reflected in Task Manager?
Additional Information:
I’m using Visual Studio 2022.
The target UWP application for integration is written in .NET C# having a process to be run in Efficiency mode.
Documentation on enabling Efficiency Mode for a process is scarce.
Any insights or suggestions would be greatly appreciated! Thank you in advance for your help.
1