Change active Win 10 Power Plan

Post your working scripts, libraries and tools.
ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Change active Win 10 Power Plan

Post by ludamo » 14 Jul 2022, 01:26

I searched on this V2 forum for powrprof.dll and couldn't find it, so went I about coding the following, with help from posts in V1 by noee, HotKeyIt, qwerty12, SvenBent, lmstearn and V2 by SKAN. Many thanks.

Code: Select all

/* 
	AHK Version 2 power scheme changing code using powrprof.dll OR POWERCFG command-line
	Help using information from:
	SKAN				V2		https://www.autohotkey.com/boards/viewtopic.php?f=83&t=99581&p=444234&hilit=GUID+structure#p444234
	noee, HotKeyIt		V1		https://www.autohotkey.com/board/topic/61079-powrprofpowergetactivescheme-pointer-to-the-guid/
	qwerty12 SvenBent 	V1		https://www.autohotkey.com/boards/viewtopic.php?t=29779
	lmstearn			V1		https://www.autohotkey.com/boards/viewtopic.php?t=68530
*/

#Requires AutoHotkey v2.0-a
#Warn VarUnset	;, OutputDebug
#Warn LocalSameAsGlobal	;, OutputDebug
#Warn Unreachable	;, OutputDebug
#SingleInstance

Persistent True
ListLines False							; turn on in specific area to debug 


*+!F9:: { 

static bufSz := 1024
static GUID_TYPICAL_POWER_SAVINGS := Buffer(16)	; Balanced 381B4222-F694-41F0-9685-FF5BB260DF2E
NumPut "UInt", 0x381B4222, "UShort", 0xF694, "UShort", 0x41F0, "UChar", 0x96, "UChar", 0x85, "UChar", 0xFF
, "UChar", 0x5B, "UChar", 0xB2, "UChar", 0x60, "UChar", 0xDF, "UChar", 0x2E, GUID_TYPICAL_POWER_SAVINGS
static GUID_MIN_POWER_SAVINGS := Buffer(16)		; High Performance 8C5E7FDA-E8BF-4A96-9A85-A6E23A8C635C
NumPut "UInt", 0x8C5E7FDA, "UShort", 0xE8BF, "UShort", 0x4A96, "UChar", 0x9A, "UChar", 0x85, "UChar", 0xA6
, "UChar", 0xE2, "UChar", 0x3A, "UChar", 0x8C, "UChar", 0x63, "UChar", 0x5C, GUID_MIN_POWER_SAVINGS

bufName := Buffer(bufSz)
DllCall("powrprof\PowerGetActiveScheme", "Ptr", 0, "Ptr*", &pGUID := 0)

DllCall("powrprof.dll\PowerReadFriendlyName", "Ptr", 0, "Ptr", pGUID, "Ptr", 0, "Ptr", 0, "Ptr", bufName, "Ptr*", &bufSz) ;sdesc :LPDWORD

DllCall("LocalFree", "Ptr", pGUID, "Ptr")

if (StrGet(bufName) = "Balanced")
{	
	if DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", GUID_MIN_POWER_SAVINGS) = 0
		TrayTip "AutoHotkey notification.", "High performance power profile active", 17
}
else
{	if DllCall("powrprof\PowerSetActiveScheme", "Ptr", 0, "Ptr", GUID_TYPICAL_POWER_SAVINGS) = 0
		TrayTip "AutoHotkey notification.", "Balanced power profile active", 17

}
}

*+!F10:: {

Err := RunWait( A_ComSpec ' /c POWERCFG /GETACTIVESCHEME | FIND /I "381B4222-F694-41F0-9685-FF5BB260DF2E  (Balanced)"',, "Min" )

if Err		; ErrorLevel!=0 means string was NOT found
{	
	Run 'POWERCFG /SETACTIVE 381B4222-F694-41F0-9685-FF5BB260DF2E',, "Hide"		; change profile to (Balanced)
	TrayTip "AutoHotkey notification.", "Balanced power profile active", 17
}
else			; ErrorLevel=0 means string WAS found
{	
	Run 'POWERCFG /SETACTIVE 8C5E7FDA-E8BF-4A96-9A85-A6E23A8C635C',, "Hide"		; change profile to (High performance)
	TrayTip "AutoHotkey notification.", "High performance power profile active", 17
}
}


User avatar
Animan8000
Posts: 58
Joined: 11 May 2022, 05:00
Contact:

Re: Change active Win 10 Power Plan

Post by Animan8000 » 16 Jul 2022, 09:13

Ultimate power mode is missing ^^'

I could imagine it should be doable to select with AHK as well, but may need to be activated before with another command.

Cheers!

ludamo
Posts: 44
Joined: 25 Mar 2015, 02:21

Re: Change active Win 10 Power Plan

Post by ludamo » 17 Jul 2022, 05:27

Searching in Winnt.h for GUID*_POWER_ shows some of the power plans. Perhaps the ultimate one you refer to is:
GUID_MAX_POWER_SAVINGS, 0xA1841308, 0x3541, 0x4FAB, 0xBC, 0x81, 0xF7, 0x15, 0x56, 0xF2, 0x0B, 0x4A
a1841308-3541-4fab-bc81-f71556f20b4a

User avatar
Animan8000
Posts: 58
Joined: 11 May 2022, 05:00
Contact:

Re: Change active Win 10 Power Plan

Post by Animan8000 » 17 Jul 2022, 08:04

Code: Select all

powercfg -duplicatescheme e9a42b02-d5df-448d-aa00-03f14749eb61
That is a Cmd command to make it available, needs to be ran as admin and then it can be selected in the control panel. Is the only thing I know.

Post Reply

Return to “Scripts and Functions (v2)”