4

我编写了一个代码,试图通过 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;

}

4

1 回答 1

7

这可以更容易完成:

PowerSetActiveScheme(0, &GUID_MIN_POWER_SAVINGS);
于 2012-10-22T09:26:54.587 回答