none
Change Power Button Action via script or API call

    Question

  • Hi, I was wondering if there was an automated way to run a script to change the power settings in Windows XP Home/Pro via a single script. Powercfg.exe works for general power settings, but can't change advanced options, like what to do when the user presses the power button. I'd like to make a script, or if I have to, write a program to call some Windows API that can change this setting. I've searched all over to no avail... This will be executed under an Administrator account, and I'm not looking for solutions using Group Policies (unless I can double click a script that will do everything automatically). Thanks for any help!

    -Eric

    Saturday, March 20, 2010 1:05 AM

Answers

  • Do not know if you are still looking for a solution. I needed something to change the Power Button setting from the default "Shutdown" to "Do nothing", so I wrote this vbscript.

    <code>

     '***************************************************************************************
    ' File:             pwrDoNothing.vbs
    ' Author:           Joe Rawlins
    ' Purpose:          Set system Power Button to 'Do nothing'
    '                   
    '
    ' Notes:            Requires button to be held for 5 seconds to initiate shutdown
    '                   
    '                   
    '                   
    '
    ' Last Modified:    06/25/2010  jtr Initial creation
    '                   
    '***************************************************************************************
    OptionExplicit

    Dim objShell, WshShell

    Set objShell = CreateObject("Shell.Application")
    Set WshShell = CreateObject("WScript.Shell")

    objShell.ControlPanelItem("powercfg.cpl")

    WScript.Sleep500
    WshShell.SendKeys"+{TAB}"
    WScript.Sleep500
    WshShell.SendKeys"{RIGHT}"
    WScript.Sleep500
    WshShell.SendKeys"{TAB 2}"
    WScript.Sleep500
    WshShell.SendKeys"{UP 2}"
    WScript.Sleep500
    WshShell.SendKeys"{ENTER}"


    <end code>

     

    Friday, June 25, 2010 5:34 PM

All replies

  • Do not know if you are still looking for a solution. I needed something to change the Power Button setting from the default "Shutdown" to "Do nothing", so I wrote this vbscript.

    <code>

     '***************************************************************************************
    ' File:             pwrDoNothing.vbs
    ' Author:           Joe Rawlins
    ' Purpose:          Set system Power Button to 'Do nothing'
    '                   
    '
    ' Notes:            Requires button to be held for 5 seconds to initiate shutdown
    '                   
    '                   
    '                   
    '
    ' Last Modified:    06/25/2010  jtr Initial creation
    '                   
    '***************************************************************************************
    OptionExplicit

    Dim objShell, WshShell

    Set objShell = CreateObject("Shell.Application")
    Set WshShell = CreateObject("WScript.Shell")

    objShell.ControlPanelItem("powercfg.cpl")

    WScript.Sleep500
    WshShell.SendKeys"+{TAB}"
    WScript.Sleep500
    WshShell.SendKeys"{RIGHT}"
    WScript.Sleep500
    WshShell.SendKeys"{TAB 2}"
    WScript.Sleep500
    WshShell.SendKeys"{UP 2}"
    WScript.Sleep500
    WshShell.SendKeys"{ENTER}"


    <end code>

     

    Friday, June 25, 2010 5:34 PM
  • I'm looking to change defalt Advanced Power Options Properties. Here I need to change Power buttongs setting to Stand By mode. So can you please provide me vbscript which can perform this task without any promt.

    Thanks,

    Dinesh Kashyap

    Friday, March 09, 2012 1:41 PM
  • Why script when you can just use Group Policies to achieve the same. 

    You can find the correct policy at: Computer Configuration\Policies\Administrative Templates\System\Power Management/Button Settings

    That would be the recommend way to configure this setting.

    Here is a nice article that explains your options: http://blogs.technet.com/b/grouppolicy/archive/2009/06/16/power-management.aspx

    Friday, March 09, 2012 2:06 PM
  • Hi,

    I have a similar request, but I dont have access to Group Policies as I only have Win 7 Home Premium. I had a look at the VB Script, but find it to be a bit of a roundabout approach.

    I have been searching for other methods (registry of .dll file changes) and keep coming back to the powerprof.dll file. Not sure if this is where power profile changes are saved? Has anyone has success in manipulating this file? I'm looking for a one-liner command/script that can change the power button setting from "Sleep" to "Do Nothing". (My one year old boy has a fascination with the Power Button and I need to set it that it Does Nothing when he watches his programs, but Sleep the rest of the time).

    Thank you.

    Barend

    Thursday, January 09, 2014 12:36 PM