does it exist an API for windows 10 to change the power plan

Just starting out? Need help? Post your questions and find answers here.
Maitre_Kanter
User
User
Posts: 84
Joined: Mon Sep 06, 2010 3:05 pm

does it exist an API for windows 10 to change the power plan

Post 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
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: does it exist an API for windows 10 to change the power

Post by chi »

You could use RunProgram with:

Code: Select all

powercfg -list (get power scheme GUID)
powercfg -setactive GUID
Et cetera is my worst enemy
Maitre_Kanter
User
User
Posts: 84
Joined: Mon Sep 06, 2010 3:05 pm

Re: does it exist an API for windows 10 to change the power

Post by Maitre_Kanter »

Thanks a lot !
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: does it exist an API for windows 10 to change the power

Post by infratec »

You need a wrapper for powrprof.dll

Like done here:

https://github.com/Ravatsaas/PowerManagerAPI
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: does it exist an API for windows 10 to change the power

Post 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
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: does it exist an API for windows 10 to change the power

Post by infratec »

I could not resist:

viewtopic.php?p=538242#p538242
Last edited by infratec on Wed Jun 19, 2019 9:02 pm, edited 4 times in total.
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: does it exist an API for windows 10 to change the power

Post by chi »

Nice one, thanks!
Et cetera is my worst enemy
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: does it exist an API for windows 10 to change the power

Post by infratec »

I extended the version above.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: does it exist an API for windows 10 to change the power

Post by infratec »

I converted the complete stuff (above)

viewtopic.php?p=538242#p538242

:mrgreen:
Post Reply