Jump to content

Inactivity Suspend while running a Script


Recommended Posts

I'm trying to code a script that needs to let the computer go to sleep when it's running (wierd I know).

The problem is that it seems like if an AutoIT script is running, the computer won't fall into standby.

The script sets the idle suspend time (to 1 min at the moment), and then waits for 2 minutes.

It doesn't seem like it matters whether it waits via Sleep(120) or a MsgBox or a Splash,

the computer won't do "inactivity suspend" while the script is running.

Is there some hidden setting/option for allowing power save features to be active when the script's running?

Link to comment
Share on other sites

I'm trying to code a script that needs to let the computer go to sleep when it's running (wierd I know).

The problem is that it seems like if an AutoIT script is running, the computer won't fall into standby.

The script sets the idle suspend time (to 1 min at the moment), and then waits for 2 minutes.

It doesn't seem like it matters whether it waits via Sleep(120) or a MsgBox or a Splash,

the computer won't do "inactivity suspend" while the script is running.

Is there some hidden setting/option for allowing power save features to be active when the script's running?

Can you show some code?

How do you try to set the suspend time to 1 minute?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

; open Power Options
Send('#r')
WinWaitActiv("Run", '', 15)
ControlSetText("Run, '', "[CLASSNN:Edit1]", "powercfg.cpl")
Sleep(250)
ControlClick("Run", '', "[CLASSNN:Button2]", left)
WinWaitActive("Power Options", '', 30)

; Set Suspend timout to 1 minute (there are seperate settings for when on AC and on Battery)
ControlFocus("Power Options", '', "[CLASSNN:ComboBox6]")
If (ControlGetFocus("Power Options", '', "[CLASSNN:ComboBox6]") Then Send('{Home}')
ControlFocus("Power Options", '', "[CLASSNN:ComboBox7]")
If (ControlGetFocus("Power Options", '', "[CLASSNN:ComboBox7]") Then Send('{Home}')

; click the OK button to confirm changes
ControlClick("Power Options", '', "[TEXT:OK]")

; computer should go to sleep here
Sleep(120 * 1000)

; splash to be shown after/before resume (computer doesn't go to sleep even when waiting for user input here)
SplashImageOn("Splash", "c:\Yellow.bmp", @DesktopWidth, @DesktopHeight, 0, 0, 1)
MsgBox(262144, "Suspend Set", "Ready for Inactivity Suspend")
SplashOff()

Link to comment
Share on other sites

; open Power Options
Send('#r')
WinWaitActiv("Run", '', 15)
ControlSetText("Run, '', "[CLASSNN:Edit1]", "powercfg.cpl")
Sleep(250)
ControlClick("Run", '', "[CLASSNN:Button2]", left)
WinWaitActive("Power Options", '', 30)

; Set Suspend timout to 1 minute (there are seperate settings for when on AC and on Battery)
ControlFocus("Power Options", '', "[CLASSNN:ComboBox6]")
If (ControlGetFocus("Power Options", '', "[CLASSNN:ComboBox6]") Then Send('{Home}')
ControlFocus("Power Options", '', "[CLASSNN:ComboBox7]")
If (ControlGetFocus("Power Options", '', "[CLASSNN:ComboBox7]") Then Send('{Home}')

; click the OK button to confirm changes
ControlClick("Power Options", '', "[TEXT:OK]")

; computer should go to sleep here
Sleep(120 * 1000)

; splash to be shown after/before resume (computer doesn't go to sleep even when waiting for user input here)
SplashImageOn("Splash", "c:\Yellow.bmp", @DesktopWidth, @DesktopHeight, 0, 0, 1)
MsgBox(262144, "Suspend Set", "Ready for Inactivity Suspend")
SplashOff()
Your ControlGetFocus should be like this

If ControlGetFocus("Power Options", '') = "ComboBox6" Then Send('{Home}')

so I don't see how that would run. Even so, I don't know why the suspend doesn't operate after 1 minute.

Have you tried the Shutdown function?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I'm not sure what OS you are using - but for my XP Pro SP3, I had to restart the OS to get it to pay attention to any such changes - even ones made manually without the script.

I hibernate the laptop most of the time - once I changed to 1 minute and restarted the OS, the script below worked. The TrayTip resumed counting after I woke the OS up from standby.

Also, the OS "listened to" the script changing the standby setting back to "Never".

I tested toggling between "1 minute" and "Never" several times - it worked each time after that first restart.

Run("control.exe powercfg.cpl")
WinWait("Power Options")
WinActivate("Power Options")
WinWaitActive("Power Options")
ControlFocus("Power Options", '', "[CLASSNN:ComboBox6]")
If ControlGetFocus("Power Options", '') = "ComboBox6" Then Send('{HOME}')
Sleep(1000)
ControlClick("Power Options", '', "[TEXT:OK]")
Sleep(1000)

Run("control.exe powercfg.cpl")
WinWait("Power Options")
WinActivate("Power Options")
WinWaitActive("Power Options")
Sleep(3000)
Send("{ESC}")

For $i = 1 To 120
    TrayTip("", $i, 1)
    Sleep(1000)
Next

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Thanks for the fast replys.

The only inactivity power save features I can find are for Standby and Hibernate.

I tried manually enabling the Standby after 1 minute and running a script that contained only a looped Sleep statement. The inactivity standby worked then, though it activated a little after 2 minutes (instead of 1 minute)

I then tried the same but with adding a splash screen around the sleep loop and standby never activated.

Standby also never activated when I ran a script that was just a MsgBox.

I tried the original script again with a longer sleep time (4*60*1000), and standby still never activated.

I tried replacing the sleep with a loop waiting for user to give input (move mouse or use keyboard) using PsaltyDS's _Timer_GetIdleTime(), and standby never activated.

plato, I don't know why, but your script didn't work on this box. Also, even when setting the settings manually, they seem to stick the first time.

I'm working with Windows XP Tablet PC Edition 2005 Service Pack 2.

If keeping the script running doesn't work, is there a way to launch a script when the computer resumes from Standby or Hibernate?

Edited by nbanyan
Link to comment
Share on other sites

Thanks for the fast replys.

The only inactivity power save features I can find are for Standby and Hibernate.

I tried manually enabling the Standby after 1 minute and running a script that contained only a looped Sleep statement. The inactivity standby worked then, though it activated a little after 2 minutes (instead of 1 minute)

I then tried the same but with adding a splash screen around the sleep loop and standby never activated.

Standby also never activated when I ran a script that was just a MsgBox.

I tried the original script again with a longer sleep time (4*60*1000), and standby still never activated.

I tried replacing the sleep with a loop waiting for user to give input (move mouse or use keyboard) using PsaltyDS's _Timer_GetIdleTime(), and standby never activated.

plato, I don't know why, but your script didn't work on this box. Also, even when setting the settings manually, they seem to stick the first time.

I'm working with Windows XP Tablet PC Edition 2005 Service Pack 2.

If keeping the script running doesn't work, is there a way to launch a script when the computer resumes from Standby or Hibernate?

Yes, you can try this, and you can test it by setting the PC to sleep (after starting this script) then waking it up.

Global Const $WM_POWERBROADCAST = 0x218, $PBT_APMRESUMEAUTOMATIC = 0x12

GUICreate("wake up test")
GUISetState()
GUIRegisterMsg($WM_POWERBROADCAST, "awake")
$sleeping = True
While $sleeping
    Sleep(200)
WEnd

MsgBox(262144, 'Information', 'woken up')

Func awake($hWnd, $Msg, $wParam, $lParam)
    If $wParam = $PBT_APMRESUMEAUTOMATIC Then $sleeping = False
EndFunc
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks for all your help guys.

I think half my problem was that I was running the scripts remotely (from a server) because the server is where I develop the scripts even though the tablet is where they need to run.

It seems that Windows doesn't use the power saver settings when a remote application is running.

Beyond that, I don't know why it was being picky, but for the moment at least it seems like using martin's code will work.

Thanks again.

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...