我写了一个代码试图通过c ++中的winAPI激活windows的高性能电源计划。它似乎适用于所有电源计划(在我的终端,他们被称为平衡,节电和戴尔),除了我感兴趣的高性能计划!我希望代码能够完成所有的电源计划,当找到高性能时,只需将其设置为然后退出。如果有人可以帮助我,我会把我的代码放在下面。提前谢谢!
#include <windows.h>
#include <powrprof.h>
#include <iostream>
#include "stdio.h"
#include <ntstatus.h>
#include <string>
#pragma comment(lib, "powrprof.lib")
using namespace std;
int main(int argc, char **argv) {
////////////////// SET ACTIVE HIGH PERFORMANCE PLAN ///////////////////
//Variables
UCHAR displayBuffer[64] = " ";
DWORD displayBufferSize = sizeof(displayBuffer);
GUID buffer;
DWORD bufferSize = sizeof(buffer);
//Go throught the machine's power plans and activate the high performance one
for(int index = 0; ; index++)
{
if (ERROR_SUCCESS == PowerEnumerate(NULL,NULL,&GUID_VIDEO_SUBGROUP,ACCESS_SCHEME,index,(UCHAR*)&buffer,&bufferSize) )
{
if (ERROR_SUCCESS == PowerReadFriendlyName(NULL,&buffer,&NO_SUBGROUP_GUID,NULL,displayBuffer,&displayBufferSize) )
{
wprintf(L"%s\n", (wchar_t*)displayBuffer);
if( 0 == wcscmp ( (wchar_t*)displayBuffer, L"High Performance" ) )
{
cout << "High Performance Plan Found!\n";
if (ERROR_SUCCESS == PowerSetActiveScheme(NULL,&buffer) )
{
cout << "* Setting Active High Performance Power Plan *";
//std::cin.get(); //pause
break;
}
}
}
}
else break;
}
return 0;
}
答案 0 :(得分:4)
这可以更轻松一点:
PowerSetActiveScheme(0, &GUID_MIN_POWER_SAVINGS);