Sign in to follow this  
Followers 0
jjj

run program on wake from standby?

14 posts in this topic

Does anyone know if winXP has something built in that can run a program when the computer wakes up from standby? (just like it does for startup?)

If not, is there a way to do this with Autoit?

Thanks!

Share this post


Link to post
Share on other sites



:) Sorry RunOnce and RunOnceEx don't work.

Try TaskSheduler for the time you computer wake up

Share this post


Link to post
Share on other sites

Hi,

what do you want to achieve? Maybe you can start program before "going to sleep" and then the program should still run if pc awakes.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

ok, I'll explain the situation a bit. I run a pvr on my comuter, and it wakes itself up to record tv shows. I want to run an autoit script that updates the router to forward a port to the pvr computer whenever it wakes up from standby.

I would rather that the script does not run all of the time, but only once when the coputer wakes up.

Any more ideas?

Share this post


Link to post
Share on other sites

Maybe this works:

Dim $check, $i = 0, $time = 60

$check = PixelChecksum( 0, 0, @DesktopWidth, @DesktopHeight)

While $check
    Sleep(1000)
    $i = $i + 1
WEnd

If $i > $time Then
;~  Your Code in here
        Exit
Else 
    Exit
EndIf


;~ $time = Your time in minutes after standby

You just have to run it before pcs goes to standby


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

Maybe this works:

Dim $check, $i = 0, $time = 60

$check = PixelChecksum( 0, 0, @DesktopWidth, @DesktopHeight)

While $check
    Sleep(1000)
    $i = $i + 1
WEnd

If $i > $time Then
;~  Your Code in here
        Exit
Else 
    Exit
EndIf
;~ $time = Your time in minutes after standby

You just have to run it before pcs goes to standby

Have you tried that on anything?

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

No i dont know how standby works and so ^^

try it out yourself


--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

No i dont know how standby works and so ^^

try it out yourself

That wasn't my point. You only check for a pixel before the While/WEnd loop, then never check it again, how is the While/WEnd supposed to know if $check is different? That's all I was saying, you have an infinite loop that will never exit. Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Give this a try ... requires BETA:

#include <GUIConstants.au3>
;~ #define PBT_APMQUERYSUSPEND             0x0000
;~ #define PBT_APMQUERYSTANDBY             0x0001
;~ #define PBT_APMQUERYSUSPENDFAILED       0x0002
;~ #define PBT_APMQUERYSTANDBYFAILED       0x0003
;~ #define PBT_APMSUSPEND                  0x0004
;~ #define PBT_APMSTANDBY                  0x0005
;~ #define PBT_APMRESUMECRITICAL           0x0006
;~ #define PBT_APMRESUMESUSPEND            0x0007
;~ #define PBT_APMRESUMESTANDBY            0x0008
;~ #define PBTF_APMRESUMEFROMFAILURE       0x00000001
;~ #define PBT_APMBATTERYLOW               0x0009
;~ #define PBT_APMPOWERSTATUSCHANGE        0x000A
;~ #define PBT_APMOEMEVENT                 0x000B
;~ #define PBT_APMRESUMEAUTOMATIC          0x0012
;
Global $WM_POWERBROADCAST     = 536
Global $PBT_APMRESUMESUSPEND  =  0x0007

$hGUI       = GUICreate("Test", 100, 100,1,1)
GUIRegisterMsg($WM_POWERBROADCAST, "Standby")
GUISetState()
While 1
    $GUIMsg = GUIGetMsg()
    Switch $GUIMsg
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
;
Exit
;
Func Standby($hWnd, $Msg, $wParam, $lParam)
    If $wParam = $PBT_APMRESUMESUSPEND Then
        MsgBox(0,"Hello Back", " You just woke up")
    EndIf
EndFunc
Edited by JdeB
1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Edit 1: Height of combobox to 120 for W2k

Tested only Windows XP Sp2

Hello all i've modified one of my first program called minialarm

http://www.autoitscript.com/forum/index.ph...518entry74518

Now it can wake up the pc and start a program at select time :(

TIP: Set your Poweroption to no Password resume from standby

code not clean but it works :)

; AutoIt Version: 3.1.1.103 Beta
; Author:  Micha1405
; Date: 14.03.2005
; Script Function: Alarmtimer & sheduler start application or shutdown
; when the gui lost focus it minimize to tray
; 21.05.2006 add wake from standby and run application after standby
; ----------------------------------------------------------------------------

; Set Variablen
#include <GUIConstants.au3>
#include <constants.au3>
#include <date.au3>
#include<Date.au3>
Global $Sec, $Min, $Hour, $Time
Opt ("TrayAutoPause", 0)
Opt ("TrayMenuMode", 1)
Opt("GUICloseOnESC", 0)
opt("TrayAutoPause",0)
$WinTitel="MiniAlarm"
$aFlag=0;Alarm Timer Flag 0=not activ 1=play sound 2=start app 3=shutdown 4=wakeup @time 5=wakeup @time and start app
$font="Comic Sans MS"

; -----------------------------------------------------------------------------
; Build GUI 
$guiApp=GUICreate($winTitel, 200, 150)
GUISetFont (14, 400, 0, $font) 
$currTime=GUICtrlCreateLabel(@Hour & ":" & @Min & ":" &@SEC , 25, 8)
$font="Arial"
GUISetFont (8, 400, 0, $font) 
$alarmbutton = GUICtrlCreateButton("Set Alarm Time", 10, 120, 110,20)
$aCombo=GUICtrlCreateCombo ("Alarm", 10,60,150,120); create first item
$alabel1=GUICtrlCreateLabel ("Choose Action", 10,35,120);

GUICtrlSetData($aCombo,"Start App|Shutdown PC|Wake from Standby|Wake from Standby & run","Alarm"); add other item snd set a new default
$Apps = GUICtrlCreateLabel ( "Start @", 10,  90, 145, 20)
GUISetIcon ("shell32.dll",20) 
TraySetIcon("shell32.dll",20)
TraySetToolTip("Click to restore")
GUISetState()
$appState = @SW_SHOW
Do
  $msg = GUIGetMsg()
  $trayMsg  = TrayGetMsg()
        if Not WinActive($winTitel) And $appState = @SW_SHOW Then;lost focus minimize window
        _ToggleAppState()
        EndIf
   Select
        case $trayMsg = $TRAY_EVENT_PRIMARYDOWN
            _ToggleAppState()
    
        Case $msg = $alarmbutton
            $varT=InputBox("Set Time", "Set Time 'hh:mm':","00:00")
            if @error then
            MsgBox(64,"Error","Input canceled")
            $aFlag=0
            GUICtrlSetState($aCombo,$GUI_Enable) 
            Else
;Check for valid input
                If StringLen($varT)<5 or StringMid($varT, 3, 1)<> ":"then 
                    MsgBox(64,"Miniarlam","Incorrect format : 01:05")
                $aFlag=0
                Else
                $aFlag=1;set timer flag activ
                GUICtrlSetData($alarmbutton, "Alarm at " & $varT)
                GUICtrlSetState($alarmbutton,$GUI_DISABLE) 
                GUICtrlSetState($aCombo,$GUI_DISABLE)
    ;if Standby is active then get time -1 min and set Standby time
                
                EndIf
            EndIf
;check action to do, read value of combobox
            $ComboValue=GUICtrlRead($aCombo,0)
        Select
                Case $ComboValue="Alarm" and $aFlag>0
        ;do Nothing
        ;$aFlag=1
                Case $ComboValue="Start App"and $aFlag>0  OR $ComboValue="Wake from Standby & run" and $aFlag>0
                    GUISetState($Apps,$GUI_enable)
                    $a_apps=FileOpenDialog("Choose Applikation to start at alarmtime",@ProgramFilesDir, "Apps (*.exe;*.cmd)", 1 + 4)
                            If @error Then
                                MsgBox(4096,"","No App select")
                                $aFlag=0
                                $fvar = EnableButtons()
                            Else
                            GUICtrlSetData($apps,$a_apps)
                            GUICtrlSetData($alarmbutton,"Start @ " &$varT)                      
                        EndIf
                        if $ComboValue="Wake from Standby & run" Then
                            $aflag=5
                ;reduce time for 2 minutes for systemstartup
                            $Sec="00"
                            $Min=StringRight($varT,2)
                            $Hour=StringLeft($varT,2)
                            $var=_TimeToTicks($Hour,$Min,$Sec)
                            $var1=$var -2 * 60 * 1000
                            _TicksToTime($var1,$Hour,$Min,$Sec)
                            SetWakeUpTime($Hour,$Min); wakeup the system
                            Sleep(1000)
                            SetSuspend()
                            Else
                            $aFlag=2
                        EndIf
                case $ComboValue="Shutdown PC" and $aFlag>0
                    $aFlag=3
                    Case $ComboValue="Wake from Standby" and $aFlag>0
                    $aFlag=4
                    SetWakeUpTime(Stringleft($varT,2),StringRight($varT,2)); wakeup the system
                    Sleep(1000)
                    SetSuspend()
        EndSelect   

    EndSelect
        SLEEP(60)
        GuiCtrlSetData($currTime,  @Hour & ":" & @Min & ":" & @Sec)
        if $Aflag >=1 Then
            if @Hour & ":" & @Min = $varT then  
            Select
                case $aflag=1
                    If FileExists(@ScriptDir & "\alarm.wav") Then
                        SoundPlay(@ScriptDir & "\alarm.wav",0)
                        Else
                        MsgBox(64,$winTitel,"alarm.wav missing in programdir",3)
                    EndIf
                    $aFlag= 0; Set Timer Flag back to 0
                    $fvar = EnableButtons()
                Case $aflag=2 or $aflag=5
        ;Start apps
                    Run ( $a_apps )
                    $aflag=0
                    $fvar = EnableButtons()
                Case $aflag=3
                    $start=RunWait(@ComSpec & " /c " & 'shutdown -s -t 00', "", @SW_HIDE);shutdown
                    $aflag=0
                    $fvar = EnableButtons()
            EndSelect
        EndIf
    EndIf
until $msg = $GUI_EVENT_CLOSE

;---------------------------------------------------------------
; Userdefined Functions
Func EnableButtons()
            GUICtrlSetState($alarmbutton,$GUI_Enable) 
            GUICtrlSetData($alarmbutton, "Set Alarm Time")
            GUICtrlSetState($aCombo,$GUI_Enable)
            GUICtrlSetData($apps,"Start @")
EndFunc
        
; User defined function minimize and restore the gui
Func _ToggleAppState()
    if $appState = @SW_HIDE then
        $appState = @SW_SHOW
        GUISetState(@SW_SHOW, $guiApp)
    Else
        $appState = @SW_HIDE
        GUISetState(@SW_HIDE, $guiApp)
    EndIf
EndFunc

;===============================================================================
;
; Description:    Sets a wakeup time to wake it up if the system / computer is hibernating or standby
; Parameter(s):  $Hour   - Hour Values  : 0-23
;                   $Minute - Minutes Values: 0-59
;                   $Day    - Days Values   : 1-31  (optional)
;                  $Month    - Month Values : 1-12   (optional)
;                  $Year     - Year Values  : > 0    (optional)
;
; Requirement(s):   DllCall
; Return Value(s):  On Success - 1
;                  On Failure - 0 sets @ERROR = 1 and @EXTENDED (Windows API error code)
;
; Error code(s):     [url=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp]http://msdn.microsoft.com/library/default....error_codes.asp[/url]
;
; Author(s):        Bastel123 aka Sebastian
; Note(s):        -
;
;===============================================================================
func SetWakeUpTime($Hour,$Minute,$Day=@mday,$Month=@mon,$Year=@YEAR)

$SYSTEMTIME = DllStructCreate("ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort")
$lpSYSTEMTIME = DllStructGetPtr($SYSTEMTIME)
$LOCALFILETIME=DllStructCreate("dword;dword")
$lpLOCALFILETIME = DllStructGetPtr($LOCALFILETIME)
$DueTime=DllStructCreate("dword;dword")
$lpDueTime=DllStructGetPtr($DueTime)

DllStructSetData($SYSTEMTIME, 1, $Year)
DllStructSetData($SYSTEMTIME, 2, $Month)
DllStructSetData($SYSTEMTIME, 3, _DateToDayOfWeek($Year,$Month,$Day)-1)
DllStructSetData($SYSTEMTIME, 4, $Day)
DllStructSetData($SYSTEMTIME, 5, $Hour)
DllStructSetData($SYSTEMTIME, 6, $Minute)
DllStructSetData($SYSTEMTIME, 7, 0)
DllStructSetData($SYSTEMTIME, 8, 0)

$result = DllCall("kernel32.dll", "long", "SystemTimeToFileTime", "ptr", $lpSystemTime, "ptr", $lpLocalFileTime)
If $result[0] = 0 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError[0])
    SetError(1)
    Return 0
EndIf
$result = DllCall("kernel32.dll", "long", "LocalFileTimeToFileTime", "ptr", $lpLocalFileTime, "ptr", $lpLocalFileTime)
If $result[0] = 0 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError[0])
    SetError(1)
    Return 0
EndIf
$result = DllCall("kernel32.dll", "long", "CreateWaitableTimer", "long", 0, "long", True, "str", "")
If $result[0] = 0 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError[0])
    SetError(1)
    Return 0
EndIf
DllCall("kernel32.dll", "none", "CancelWaitableTimer", "long",$result[0])

DllStructSetData($DueTime, 1, DllStructGetData($LocalFILETIME, 1))
DllStructSetData($DueTime, 2, DllStructGetData($LocalFILETIME, 2))

$result = DllCall("kernel32.dll", "long", "SetWaitableTimer", "long",$result[0], "ptr", $lpDueTime, "long", 1000, "long", 0, "long", 0, "long", true)
If $result[0] = 0 Then
    Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
    SetExtended($lastError[0])
    SetError(1)
    Return 0
EndIf
return 1
EndFunc

;===============================================================================
;
; Description:    Set the computer in Hibernate or Standby Status
; Parameter(s):  $Mode   - Suspend mode : True=Hibernate, False=Suspend
;                   $Force  - Force-Mode    : True=the system suspends operation immediately
;                                             False=FALSE, the system broadcasts a PBT_APMQUERYSUSPEND event to each application to request permission to suspend operation 
;
; Requirement(s):   DllCall
;
; Author(s):        Bastel123 aka Sebastian
; Note(s):        If the system does not support hibernate use the standby mode       -
;
;===============================================================================
Func SetSuspend($mode=False,$force=true)
    $result = DllCall("PowrProf.dll", "long", "SetSuspendState", "long",$mode, "long",$force, "long", false)
EndFunc
Edited by Micha1405

Share this post


Link to post
Share on other sites

Global $WM_POWERBROADCAST     = 536
Global $PBT_APMRESUMESUSPEND  =  0x0007
GUIRegisterMsg($WM_POWERBROADCAST, "Standby")
Func Standby($hWnd, $Msg, $wParam, $lParam)
    If $wParam = $PBT_APMRESUMESUSPEND Then
        MsgBox(0,"Hello Back", " You just woke up")
    EndIf
EndFunc
JdeB,

THANKS! I was just looking for this very thing (for a similar reason: want to do something with my router on resume).

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