Sign in to follow this  
Followers 0
zone97

Advanced Power settings

13 posts in this topic

Is there a way to edit the advanced power settings without opening the power profile dialog, say like with the registry.

I would like to write a program that changes the "what to do when the lid closes" function as a toggle from do nothing to stand by.... so its just a single click away from changing.


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have only tested this on XP, it will probably work on 2000 and vista,

But I suggest you back up the registry key before trying it on them.

(HKCU\Control Panel\PowerCfg\GlobalPowerPolicy)

-Kenny

; 00 =  Do Nothing / 02 = Standby / 03 = Hibernate
Func _SetLidPowerAction($sAction)
    If $sAction <> 00 AND $sAction <> 02 AND $sAction <> 03 Then Return 3; Invalid Parms
    $Key = RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies")
    If $Key = "" Then Return 2; Could not read current settings
    $Key = StringReplace($Key, 106, $sAction)
    $Key = StringReplace($Key, 130, $sAction)
    If $sAction <> 00 Then
        $Key = StringReplace($Key, 127, 00)
        $Key = StringReplace($Key, 151, 00)
    Else
        $Key = StringReplace($Key, 127, 80)
        $Key = StringReplace($Key, 151, 80)
    EndIf
    If $Key <> "" Then
        If RegWrite("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies", "REG_BINARY", $Key) = 1 Then;Write new settings
            RunWait(@ComSpec & " /c rundll32.exe powrprof.dll,LoadCurrentPwrScheme", @SystemDir, @SW_HIDE);Refresh power settings
            Return 0;Success
        EndIf
    EndIf
    Return 1;Could not write new settings to registry
EndFunc
Edited by ken82m

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

this worked great on xp, i will develop this further to create a toggle effect as well as a user defined option.

thank you.


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

Your welcome.

If you want to control any other advanced options use this:

FileWriteLine("C:\Reg.txt", RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies") )
MsgBox(0,"","Click OK After Changing Option")
FileWriteLine("C:\Reg.txt", RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies") & @CR)

You'll just have to go through them and find the changes, just keep in mind there may be more than one change.

Kenny


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

well i have to do a retraction.. :)

The code works, and shows under the advanced tab that the setting has changed, but when you close the lid, it still goes into stand by. Maybe there is another registry area where the actual work is change, not just the lable?


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

You can try broadcasting the WM_SETTINGCHANGE message. Try calling EnvUpdate() after you write your change to the registry. EnvUpdate() broadcasts WM_SETTINGCHANGE. However, if that does not work, you're basically out of luck and will just have to automate the power settings window to get the changes to take effect (The window can be hidden and still automated).

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You can try broadcasting the WM_SETTINGCHANGE message. Try calling EnvUpdate() after you write your change to the registry. EnvUpdate() broadcasts WM_SETTINGCHANGE. However, if that does not work, you're basically out of luck and will just have to automate the power settings window to get the changes to take effect (The window can be hidden and still automated).

Didn't work, the other option maybe possible but how do you call the configuration window, there is no "program" to launch to get the window, there is a control panel icon, which when you create a shortcut on the desktop, the target field is blank.

Edit:

never mind, found powercfg.cpl

Edited by zone97

 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

I'll admit I didn't test the code beyone verifying the change in the control panel.

But after seeing your post I just tested it and it worked fine on my laptop.

I just closed my lid and the action I just set with the script worked as it should.

What brand is your laptop?

Do you have anything else running on your PC that might be managing your power settings?

-Kenny


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

this is a eeepc 1000h, i dont think anything else is dealing with the power. it shows the change in the power profile but it doesnt act. I can change it manually and to works fine?

here is my code.

;#! AutoIt
;##############################################################################
;# Options

#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>
#AutoIt3Wrapper_icon=power.ico

Opt("TrayOnEventMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)
Opt("WinWaitDelay", 750)

_Check()
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_Toggle")
TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "_Quit")

;##############################################################################
;# Declared Varables

Dim $Value
Dim $New

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@ Program Start

While 1
    Sleep(250)
    _Check()
    $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

;##############################################################################
;# Functions

; FUNC: Minimize to tray.

Func _Check()
    $value = RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Toggle")

    if $Value = "00" Then 
        TraySetIcon("off.ico")
    else 
        TraySetIcon("on.ico")
    EndIf
EndFunc

Func _Toggle()
    $value = RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Toggle")

    if $Value = "00" Then 
        $New = "02"
        TraySetIcon("on.ico")
        _SetLidPowerAction(02)
    else 
        $New = "00"
        TraySetIcon("off.ico")
        _SetLidPowerAction(00)
    EndIf
    RegWrite("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Toggle", "REG_BINARY", $New) 
EndFunc

Func _SetLidPowerAction($sAction)
    If $sAction <> 00 AND $sAction <> 02 AND $sAction <> 03 Then Return 3; Invalid Parms
    $Key = RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies")
    If $Key = "" Then Return 2; Could not read current settings
    $Key = StringReplace($Key, 130, $sAction)
    $Key = StringReplace($Key, 154, $sAction)
    If $Key <> "" Then
        If RegWrite("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies", "REG_BINARY", $Key) = 1 Then;Write new settings
            RunWait(@ComSpec & " /c rundll32.exe powrprof.dll,LoadCurrentPwrScheme", @SystemDir, @SW_HIDE);Refresh power settings
            Return 0;Success
        EndIf
    EndIf
    Return 1;Could not write new settings to registry
EndFunc

Func _Quit()
    Exit
EndFunc

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@ Program End
Edited by zone97

 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

hmm it works alright but not when I'm plugged into the charger. Let me take another look at the string.


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

Ok I found it. I had missed one flag. I also changed the first two lines in your two functions

This way they can pull the the live status directly registry rather than relying on a reg val your setting.

Kenny

;#! AutoIt
;##############################################################################
;# Options

#NoTrayIcon
#include <GuiConstants.au3>
#include <Constants.au3>
;#AutoIt3Wrapper_icon=power.ico

Opt("TrayOnEventMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayMenuMode", 1)
Opt("WinWaitDelay", 750)

_Check()
TraySetOnEvent($TRAY_EVENT_PRIMARYUP, "_Toggle")
TraySetOnEvent($TRAY_EVENT_SECONDARYUP, "_Quit")

;##############################################################################
;# Declared Varables

Dim $Value
Dim $New

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@ Program Start

While 1
    Sleep(250)
    _Check()
    $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

;##############################################################################
;# Functions

; FUNC: Minimize to tray.

Func _Check()
    $value = StringMid(RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies"), 130, 2)
    
    if $Value = "00" Then 
        TraySetIcon("off.ico")
    else 
        TraySetIcon("on.ico")
    EndIf
EndFunc

Func _Toggle()
    $value = StringMid(RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies"), 130, 2)
    
    if $Value = "00" Then 
        $New = "02"
        TraySetIcon("on.ico")
        _SetLidPowerAction(02)
    else 
        $New = "00"
        TraySetIcon("off.ico")
        _SetLidPowerAction(00)
    EndIf
EndFunc

Func _SetLidPowerAction($sAction)
    If $sAction <> 00 AND $sAction <> 02 AND $sAction <> 03 Then Return 3; Invalid Parms
    $Key = RegRead("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies")
    If $Key = "" Then Return 2; Could not read current settings
    $Key = StringReplace($Key, 106, $sAction)
    $Key = StringReplace($Key, 130, $sAction)
    If $sAction <> 00 Then
        $Key = StringReplace($Key, 127, 00)
        $Key = StringReplace($Key, 151, 00)
    Else
        $Key = StringReplace($Key, 127, 80)
        $Key = StringReplace($Key, 151, 80)
    EndIf
    If $Key <> "" Then
        If RegWrite("HKCU\Control Panel\PowerCfg\GlobalPowerPolicy", "Policies", "REG_BINARY", $Key) = 1 Then;Write new settings
            RunWait(@ComSpec & " /c rundll32.exe powrprof.dll,LoadCurrentPwrScheme", @SystemDir, @SW_HIDE);Refresh power settings
            Return 0;Success
        EndIf
    EndIf
    Return 1;Could not write new settings to registry
EndFunc

Func _Quit()
    Exit
EndFunc

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
;@ Program End

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
Share on other sites

that did it, thank you very much once more.


 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

Your welcome :)


My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Share this post


Link to post
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
Sign in to follow this  
Followers 0