PureBasic Forum
http://forums.purebasic.com/english/

does it exist an API for windows 10 to change the power plan
http://forums.purebasic.com/english/viewtopic.php?f=13&t=73022
Page 1 of 1

Author:  Maitre_Kanter [ Fri Jun 14, 2019 6:53 am ]
Post subject:  does it exist an API for windows 10 to change the power plan

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

Author:  chi [ Fri Jun 14, 2019 7:31 am ]
Post subject:  Re: does it exist an API for windows 10 to change the power

You could use RunProgram with:
Code:
powercfg -list (get power scheme GUID)
powercfg -setactive GUID

Author:  Maitre_Kanter [ Sun Jun 16, 2019 4:34 pm ]
Post subject:  Re: does it exist an API for windows 10 to change the power

Thanks a lot !

Author:  infratec [ Sun Jun 16, 2019 10:00 pm ]
Post subject:  Re: does it exist an API for windows 10 to change the power

You need a wrapper for powrprof.dll

Like done here:

https://github.com/Ravatsaas/PowerManagerAPI

Author:  infratec [ Sun Jun 16, 2019 10:19 pm ]
Post subject:  Re: does it exist an API for windows 10 to change the power

As a starting point:
Code:
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

Author:  infratec [ Mon Jun 17, 2019 12:49 pm ]
Post subject:  Re: does it exist an API for windows 10 to change the power

I could not resist:

viewtopic.php?p=538242#p538242

Author:  chi [ Mon Jun 17, 2019 5:14 pm ]
Post subject:  Re: does it exist an API for windows 10 to change the power

Nice one, thanks!

Author:  infratec [ Wed Jun 19, 2019 12:50 pm ]
Post subject:  Re: does it exist an API for windows 10 to change the power

I extended the version above.

Author:  infratec [ Wed Jun 19, 2019 8:58 pm ]
Post subject:  Re: does it exist an API for windows 10 to change the power

I converted the complete stuff (above)

viewtopic.php?p=538242#p538242

:mrgreen:

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/