简体   繁体   English

使用C ++ winAPI设置Windows的高性能电源计划

[英]Setting On windows' High Performance power plan using C++ winAPI

Ive written a code trying to activate the windows' high perfomance power plan through the winAPI in c++. 我写了一个代码试图通过c ++中的winAPI激活windows的高性能电源计划。 It seems to work well for all the power plans (in my terminal they are called Balanced, Power saver and Dell) excepting for the one im interested in, the high performance plan! 它似乎适用于所有电源计划(在我的终端,他们被称为平衡,节电和戴尔),除了我感兴趣的高性能计划! I would like the code to go over through all the power plans and when finding the high performance one just set it on and then quit. 我希望代码能够完成所有的电源计划,当找到高性能时,只需将其设置为然后退出。 Ill put my code underneath in case anybody can help me. 如果有人可以帮助我,我会把我的代码放在下面。 thanks in advance! 提前致谢!

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

} }

这可以更容易一些:

PowerSetActiveScheme(0, &GUID_MIN_POWER_SAVINGS);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM