Page 1 of 1
does it exist an API for windows 10 to change the power plan
Posted: Fri Jun 14, 2019 6:53 am
by Maitre_Kanter
Hello,
I want to implement a software which change Power Plan for windows 10 by programming time triggers.
Somebody knows an api to change the power plan ?
Sorry for my english... I am french !
Arnaud
Re: does it exist an API for windows 10 to change the power
Posted: Fri Jun 14, 2019 7:31 am
by chi
You could use RunProgram with:
Code: Select all
powercfg -list (get power scheme GUID)
powercfg -setactive GUID
Re: does it exist an API for windows 10 to change the power
Posted: Sun Jun 16, 2019 4:34 pm
by Maitre_Kanter
Thanks a lot !
Re: does it exist an API for windows 10 to change the power
Posted: Sun Jun 16, 2019 10:00 pm
by infratec
You need a wrapper for powrprof.dll
Like done here:
https://github.com/Ravatsaas/PowerManagerAPI
Re: does it exist an API for windows 10 to change the power
Posted: Sun Jun 16, 2019 10:19 pm
by infratec
As a starting point:
Code: Select all
Prototype.l Prototype_PowerGetActiveScheme(*UserPowerKey, *ActivePolicyGuid)
Global PowerGetActiveScheme.Prototype_PowerGetActiveScheme
powrprof = OpenLibrary(#PB_Any, "powrprof.dll")
If powrprof
PowerGetActiveScheme = GetFunction(powrprof, "PowerGetActiveScheme")
Define *test.GUID
PowerGetActiveScheme(#Null, @*test)
GUID$ = RSet(Hex(*test\Data1, #PB_Long), 8, "0") + "-"
GUID$ + RSet(Hex(*test\Data2, #PB_Word), 4, "0") + "-"
GUID$ + RSet(Hex(*test\Data3, #PB_Word), 4, "0") + "-"
GUID$ + RSet(Hex(*test\Data4[0] << 8 | *test\Data4[1], #PB_Word), 4, "0") + "-"
GUID$ + RSet(Hex(*test\Data4[2], #PB_Byte), 2, "0")
GUID$ + RSet(Hex(*test\Data4[3], #PB_Byte), 2, "0")
GUID$ + RSet(Hex(*test\Data4[4], #PB_Byte), 2, "0")
GUID$ + RSet(Hex(*test\Data4[5], #PB_Byte), 2, "0")
GUID$ + RSet(Hex(*test\Data4[6], #PB_Byte), 2, "0")
GUID$ + RSet(Hex(*test\Data4[7], #PB_Byte), 2, "0")
Debug GUID$
LocalFree_(*test)
CloseLibrary(powrprof)
EndIf
Re: does it exist an API for windows 10 to change the power
Posted: Mon Jun 17, 2019 12:49 pm
by infratec
Re: does it exist an API for windows 10 to change the power
Posted: Mon Jun 17, 2019 5:14 pm
by chi
Nice one, thanks!
Re: does it exist an API for windows 10 to change the power
Posted: Wed Jun 19, 2019 12:50 pm
by infratec
I extended the version above.
Re: does it exist an API for windows 10 to change the power
Posted: Wed Jun 19, 2019 8:58 pm
by infratec
I converted the complete stuff (above)
viewtopic.php?p=538242#p538242