gertsolo Posted July 22, 2009 Share Posted July 22, 2009 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. Link to comment Share on other sites More sharing options...
rudi Posted July 22, 2009 Share Posted July 22, 2009 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! Link to comment Share on other sites More sharing options...
gertsolo Posted July 22, 2009 Author Share Posted July 22, 2009 I don't know any WMI functionality that can do this. The more you learn, the less you know. Link to comment Share on other sites More sharing options...
rudi Posted July 23, 2009 Share Posted July 23, 2009 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! Link to comment Share on other sites More sharing options...
storme Posted July 23, 2009 Share Posted July 23, 2009 (edited) Hi gertsoloI 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() WEndAs 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 July 23, 2009 by storme Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
Developers Jos Posted July 23, 2009 Developers Share Posted July 23, 2009 Posted this before, but just run it and go into standby. Returning from standby you will get a MsgBox() expandcollapse popup#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 SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
rudi Posted July 23, 2009 Share Posted July 23, 2009 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! Link to comment Share on other sites More sharing options...
storme Posted July 23, 2009 Share Posted July 23, 2009 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 Some of my small contributions to AutoIt Browse for Folder Dialog - Automation SysTreeView32 | FileHippo Download and/or retrieve program information | Get installedpath from uninstall key in registry | RoboCopy function John Morrison aka Storm-E Link to comment Share on other sites More sharing options...
gertsolo Posted August 9, 2009 Author Share Posted August 9, 2009 (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 August 9, 2009 by gertsolo The more you learn, the less you know. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 9, 2009 Developers Share Posted August 9, 2009 \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 parameters17:18:48: 0x0000000417:28:15: 0x0000001217:30:56: 0x0000000017:30:57: 0x0000000417:32:25: 0x00000012I would say that you seem to have to Test for PBT_APMRESUMEAUTOMATIC ? SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
gertsolo Posted August 9, 2009 Author Share Posted August 9, 2009 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. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 9, 2009 Developers Share Posted August 9, 2009 Would do you mean with that Jos? expandcollapse popup#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 SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
gertsolo Posted August 9, 2009 Author Share Posted August 9, 2009 expandcollapse popup#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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now