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;
}