Jump to content

Changing Power Setting And Committing


Recommended Posts

I'm using the following script to change the power settings so that when the notebook lid is closed, it is set to "Do Nothing." The script works and the setting is visibly changed, but the setting doesn't seem to commit and doesn't take effect unless I manually change it and save.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
Global $REG_POWERSCHEMES
;~ Change this option to one of the following:
;~ 0 - Power Option: Do Nothing
;~ 1 - Power Option: Sleep
;~ 2 - Power Option: Hibernate
;~ 3 - Power Option: Shutdown
Global $VAR_POWEROPTIONS = 0
   Switch $VAR_POWEROPTIONS
      Case 0
         ;~ Power Option: Do Nothing
         $REG_POWERSCHEMES = 0
      Case 1
         ;~ Power Option: Sleep
         $REG_POWERSCHEMES = 1
      Case 2
         ;~ Power Option: Hibernate
         $REG_POWERSCHEMES = 2
      Case 3
         ;~ Power Option: Shutdown
         $REG_POWERSCHEMES = 3
      Case Else
         Exit
   EndSwitch
;~ Create list of PowerSchemes
FNC_POWERSCHEMES('HKLMSYSTEMCurrentControlSetControlPowerUserPowerSchemes')
Func FNC_POWERSCHEMES($PAR_ENUMERATEKEY)
   If StringRight($PAR_ENUMERATEKEY, 1) = '' Then $PAR_ENUMERATEKEY = StringTrimRight($PAR_ENUMERATEKEY, 1)
   Local $x = 1
   Local $REG_ENUMERATEKEY
   While 1
      $REG_ENUMERATEKEY = RegEnumKey($PAR_ENUMERATEKEY, $x)
         If @error <> 0 Then ExitLoop
      ;~ Using PowerCFG.exe Set AC Lid Settings
      RunWait('POWERCFG.EXE  -SETACVALUEINDEX ' & $REG_ENUMERATEKEY & ' 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 ' & $REG_POWERSCHEMES, '', @SW_HIDE)
      ;~ Using PowerCFG.exe Set DC Lid Settings
      RunWait('POWERCFG.EXE  -SETDCVALUEINDEX ' & $REG_ENUMERATEKEY & ' 4f971e89-eebd-4455-a8de-9e59040e7347 5ca83367-6e45-459f-a27b-476b1d01c936 ' & $REG_POWERSCHEMES, '', @SW_HIDE)
      $x += 1
   WEnd
EndFunc

I saw a AutoIt post the other day that was doing a similar thing and it called [tt]LoadPowerScheme[/tt] from the rundll32 library, so I tried adding that line of code in, but it still doesn't work.

RunWait(@ComSpec & " /c rundll32.exe powrprof.dll,LoadCurrentPwrScheme", @SystemDir, @SW_HIDE)

Does anyone have any ideas?

Edited by weirddemon
Link to comment
Share on other sites

What kind of laptop is it? Some require a change in the BIOS settings for this, others use the OS power settings.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...