How to set power mode programmatically?

Emmett 66 Reputation points
2022-01-18T07:52:40.753+00:00

Hi,

My target device is windows 11 (21H2).

I want to set/get power mode from my app.

I known PowerGetActiveScheme/PowerSetActiveScheme can get/set power scheme like:
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)
Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance)
Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver)

And I can use PowerRegisterForEffectivePowerModeNotifications to get current power mode.
But I can not found any function to set power mode.
https://support.microsoft.com/en-us/windows/change-the-power-mode-for-your-windows-pc-c2aff038-22c9-f46d-5ca0-78696fdf2de8#Category=Windows_11
Best power efficiency
Balanced
Best performance
https://learn.microsoft.com/en-us/windows/win32/api/powersetting/ne-powersetting-effective_power_mode
In win32 is EFFECTIVE_POWER_MODE.

And I use "powercfg /list" to check power scheme for each power mode,
the power scheme of these three mode are all 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced)

Is windows support application to set power mode ?

How can I set power mode programmatically?

P.S. My application can run as admin.

Thanks.

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,148 questions
{count} vote

Accepted answer
  1. Limitless Technology 39,351 Reputation points
    2022-01-25T10:02:51.933+00:00

    Hello Emmet,

    I would like to share the way I do it. Basically with a custom powerplan:

    You first need to create a profile, your master profile, if you will. Then from the command line:

    "powercfg -l" (this will list profiles and their GUIDs)
    copy the GUID for the profile you created
    "powercfg -export c:\YourPowerProfile.pow {GUID}"
    on a target machine, you'll want to run "powercfg -import c:\YourPowerProfile.pow {GUID}"
    Then you need to make it active, so: "powercfg -setactive {GUID}"
    The thing is, you can use the same GUID each time. You can import it with the GUID that was created when you first made the profile.Therefore, since you know the GUID ahead of time, you can script it in a batch file.

    I placed my .pow file on a network share in the same folder as a batch file (only these two files exist in the folder). My batch file looks like:

    ---BEGIN---

    md c:\power
    cd c:\power
    copy "\server\share*."
    powercfg -import c:\power\MyPowerConfig.pow 551d289f-0b99-46b9-8914-18830df35155
    powercfg -setactive 551d289f-0b99-46b9-8914-18830df35155
    powercfg -l
    pause
    del c:\power*.
    /q
    cd\
    rd c:\power
    pause

    ---END---

    I added a powercfg -l to list the current power configs and be sure mine's listed and set to active.


    --If the reply is helpful, please Upvote and Accept as answer--


0 additional answers

Sort by: Most helpful