Sign in to follow this  
Followers 0
gertsolo

Running a program after computer wake up

13 posts in this topic

Hey all,

I usually put my computer in standby when I am not working on it. It would like to run a program each time I wake the computer up. How can I do this?

thx.


The more you learn, the less you know.

Share this post


Link to post
Share on other sites



Hey all,

I usually put my computer in standby when I am not working on it. It would like to run a program each time I wake the computer up. How can I do this?

thx.

Maybe there is a solution via WMI, I don't know.

Or code a program that overwrites periodically a TXT file with the value of _nowcalc(). Then read it again at the beginning of the next loop. In case the difference is e.g. more than 3 times of the delay you coded, assume that the computer was not up, then do, what you want.

If it shall do it's job even when no current logon is active, use srvany.exe / instsrv.exe to run it as a service.

REgards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

I don't know any WMI functionality that can do this.


The more you learn, the less you know.

Share this post


Link to post
Share on other sites

Hi.

I don't know any WMI functionality that can do this.

Then use the TXT file solution I mentioned above :)

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi gertsolo

I took rudi's suggestion twisted it a little and made this.

;Script to check if computer was put to sleep
#include <Date.au3>

Local $interval = 30 ; Seconds
Local $intervalMilliSeconds = $interval * 1000

Local $now = _NowCalc()
While 1
    Sleep($intervalMilliSeconds)
    ConsoleWrite(_DateDiff("s", $now, _NowCalc()) & @cr)
    If _DateDiff("s", $now, _NowCalc()) > ($interval + 10) Then
        ; Gave a 10 second margine for error
        MsgBox(0, "Wakey Wakey", "I feel so refreshed :-)")
    EndIf
    $now = _NowCalc()
WEnd

As long as you don't mind the script staying memory resident it will sleep for $interval seconds (So isn't CPU intensive).

When it exits the sleep it does a quick check to make sure no more than $interval seconds have passed (With 10 seconds margin) and if it has...WAKEY WAKEY :-)

Not exactly a world shattering piece of code but should do what you want.

Good Luck

Edited by storme

Share this post


Link to post
Share on other sites

Posted this before, but just run it and go into standby. Returning from standby you will get a MsgBox()

#include <GUIConstants.au3>
#include <date.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
Global $PBT_APMRESUMESTANDBY  =  0x0008

$hGUI       = GUICreate("Test", 100, 100,1,1)
GUIRegisterMsg($WM_POWERBROADCAST, "Standby")
;~ GUISetState()
While 1
    Sleep(10)
;~ $GUIMsg = GUIGetMsg()
;~     Switch $GUIMsg
;~         Case $GUI_EVENT_CLOSE
;~             ExitLoop
;~     EndSwitch
WEnd
;
Exit
;
Func Standby($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite(_NowTime() & ": " & $wParam & @LF)
    Select
        Case $wParam = $PBT_APMRESUMESUSPEND 
            ConsoleWrite(" You just woke up from Suspend." & @LF)
            MsgBox(0,"Hello Back", " You just woke up from Suspend")
        Case $wParam = $PBT_APMRESUMESTANDBY 
            ConsoleWrite(" You just woke up from Standby." & @LF)
            MsgBox(0,"Hello Back", " You just woke up from Standby")
        Case Else
    EndSelect
EndFunc

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

Hi Jos.

Posted this before, ...

GUIRegisterMsg()

I wasn't aware of this 'Windows Message ID (WM_MSG).'

Do you know a URL of all the available WM_MSG's? At MS Developers pages I couldn't find such a list, nor with Dr. Google: Just articles describing basic lists.

Thanks for sharing, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

Posted this before, but just run it and go into standby. Returning from standby you will get a MsgBox()

Now see I knew that would happen. The thread sits arounds for 2 days with no answer I jump in wiht a bit of quick code and in comes someone else with a more elegant solution....grrrrrrr :)

Thanks Jos I've been looking for something like this for myself which is why I thought I'd have a go.

Don't tell anyone but I like your solution better. :)

Thanks

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

thanks all, I will try it right away.

greetz

I tried it but don't seem to get it working. Is the code good as it is or should I change or add something?

btw I get these parameters

17:18:48: 0x00000004

17:28:15: 0x00000012

17:30:56: 0x00000000

17:30:57: 0x00000004

17:32:25: 0x00000012

Edited by gertsolo

The more you learn, the less you know.

Share this post


Link to post
Share on other sites

\I tried it but don't seem to get it working. Is the code good as it is or should I change or add something?

btw I get these parameters

17:18:48: 0x00000004

17:28:15: 0x00000012

17:30:56: 0x00000000

17:30:57: 0x00000004

17:32:25: 0x00000012

I would say that you seem to have to Test for PBT_APMRESUMEAUTOMATIC ?

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

I would say that you seem to have to Test for PBT_APMRESUMEAUTOMATIC ?

Would do you mean with that Jos?


The more you learn, the less you know.

Share this post


Link to post
Share on other sites

Would do you mean with that Jos?

#include <GUIConstants.au3>
#include <date.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
Global $PBT_APMRESUMESTANDBY  =  0x0008
Global $PBT_APMRESUMEAUTOMATIC  =  0x0012

$hGUI       = GUICreate("Test", 100, 100,1,1)
GUIRegisterMsg($WM_POWERBROADCAST, "Standby")
;~ GUISetState()
While 1
    Sleep(10)
;~ $GUIMsg = GUIGetMsg()
;~     Switch $GUIMsg
;~         Case $GUI_EVENT_CLOSE
;~             ExitLoop
;~     EndSwitch
WEnd
;
Exit
;
Func Standby($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite(_NowTime() & ": " & $wParam & @LF)
    Select
        Case $wParam = $PBT_APMRESUMESUSPEND 
            ConsoleWrite(" You just woke up from Suspend." & @LF)
            MsgBox(0,"Hello Back", " You just woke up from Suspend")
        Case $wParam = $PBT_APMRESUMESTANDBY 
            ConsoleWrite(" You just woke up from Standby." & @LF)
            MsgBox(0,"Hello Back", " You just woke up from Standby")
        Case $wParam = $PBT_APMRESUMEAUTOMATIC
            ConsoleWrite(" You just woke up from ????." & @LF)
            MsgBox(0,"Hello Back", " You just woke up from ??????")
        Case Else
    EndSelect
EndFunc

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

#include <GUIConstants.au3>
#include <date.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
Global $PBT_APMRESUMESTANDBY  =  0x0008
Global $PBT_APMRESUMEAUTOMATIC  =  0x0012

$hGUI       = GUICreate("Test", 100, 100,1,1)
GUIRegisterMsg($WM_POWERBROADCAST, "Standby")
;~ GUISetState()
While 1
    Sleep(10)
;~ $GUIMsg = GUIGetMsg()
;~     Switch $GUIMsg
;~         Case $GUI_EVENT_CLOSE
;~             ExitLoop
;~     EndSwitch
WEnd
;
Exit
;
Func Standby($hWnd, $Msg, $wParam, $lParam)
    ConsoleWrite(_NowTime() & ": " & $wParam & @LF)
    Select
        Case $wParam = $PBT_APMRESUMESUSPEND 
            ConsoleWrite(" You just woke up from Suspend." & @LF)
            MsgBox(0,"Hello Back", " You just woke up from Suspend")
        Case $wParam = $PBT_APMRESUMESTANDBY 
            ConsoleWrite(" You just woke up from Standby." & @LF)
            MsgBox(0,"Hello Back", " You just woke up from Standby")
        Case $wParam = $PBT_APMRESUMEAUTOMATIC
            ConsoleWrite(" You just woke up from ????." & @LF)
            MsgBox(0,"Hello Back", " You just woke up from ??????")
        Case Else
    EndSelect
EndFunc

Thanks Jos, that did the trick.

The more you learn, the less you know.

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