Swift Posted February 20, 2008 Share Posted February 20, 2008 Does anyone know how exactly? Link to comment Share on other sites More sharing options...
evilertoaster Posted February 21, 2008 Share Posted February 21, 2008 Your GUI is sent the WM_QUERYENDSESSION message. Try registering an event to that. Link to comment Share on other sites More sharing options...
Swift Posted February 21, 2008 Author Share Posted February 21, 2008 Not Using A GUI So.. In my loop...how...? will I do this? Link to comment Share on other sites More sharing options...
evilertoaster Posted February 21, 2008 Share Posted February 21, 2008 autoit is a gui application (wether you make use of it's windows or not) so the message gets set to the main windows event handler. If you actually did custom link your script to be a console application, you'd have to use SetConsoleCtrlHandler() from kernal32.dll to register an event. If your application is recongized by windows as a service, you'll have to use RegisterServiceCtrlHandlerEx() from Advapi32.dll. I don't have exmaples in autoit of the later two. Link to comment Share on other sites More sharing options...
Swift Posted February 21, 2008 Author Share Posted February 21, 2008 autoit is a gui application (wether you make use of it's windows or not) so the message gets set to the main windows event handler. If you actually did custom link your script to be a console application, you'd have to use SetConsoleCtrlHandler() from kernal32.dll to register an event.If your application is recongized by windows as a service, you'll have to use RegisterServiceCtrlHandlerEx() from Advapi32.dll.I don't have exmaples in autoit of the later two.Thats outa my league...lol.... Link to comment Share on other sites More sharing options...
evilertoaster Posted February 21, 2008 Share Posted February 21, 2008 sth like this- GUICreate("dummy") GUIRegisterMsg (0x0011, "someFunc" ) while 1 Sleep(1000) WEnd func someFunc() MsgBox(0,"","Waiting on you...") EndFunc Link to comment Share on other sites More sharing options...
Swift Posted February 21, 2008 Author Share Posted February 21, 2008 (edited) Will that work without a GUI? (Oops...lol) It works great...will it do the same for restart? thanks...I had to test it. Edited February 21, 2008 by Swift Link to comment Share on other sites More sharing options...
evilertoaster Posted February 21, 2008 Share Posted February 21, 2008 you need to set somthing up to receive the messsage. You can use a gui window and simply not show it like I did above. Link to comment Share on other sites More sharing options...
Swift Posted February 21, 2008 Author Share Posted February 21, 2008 Will this work...if user logged off...shutdown...or restart? Link to comment Share on other sites More sharing options...
rover Posted February 21, 2008 Share Posted February 21, 2008 (edited) you need the message handling function for the WM_QUERYENDSESSION message run this, shutdown pc or logoff and check the log file HotKeySet("{ESC}", "_Quit") ; exit demo #include <File.au3> Global $logfile Global Const $WM_QUERYENDSESSION = 0x0011 If @Compiled Then ; log file location same as script $logfile = StringReplace(@AutoItExe, ".exe", ".log") Else ; for SciTe console testing only $logfile = StringReplace(@ScriptName, ".au3", ".log") Endif GUICreate("",1,1) ; dummy gui for shutdown message GUIRegisterMsg($WM_QUERYENDSESSION, "_ShutdownInitiated") Local $timer = TimerInit() While 1 Sleep(100) ToolTip(Round(TimerDiff($timer))&" ms", @DesktopWidth /2 , @DesktopHeight /2, "Message Loop - 'ESC' to exit") WEnd Func _ShutdownInitiated($hWndGUI, $MsgID, $WParam, $LParam) ; windows message handler for WM_QUERYENDSESSION. ; For user logoff or system shutdown Beep(1000,5) _FileWriteLog($logfile, "Logoff or Shutdown Event - Exiting" & @CRLF) Return True ; acknowledges system shutdown command, responds to system with 'True' EndFunc ;==>_ShutdownInitiated Func _Quit() Exit EndFunc Edited February 21, 2008 by rover I see fascists... Link to comment Share on other sites More sharing options...
Swift Posted February 21, 2008 Author Share Posted February 21, 2008 Thanks I got that part now...It works...but what i'm asking is...will this WM_QUERYENDSESSION work with restart? Link to comment Share on other sites More sharing options...
JustinReno Posted February 21, 2008 Share Posted February 21, 2008 Why not just do this:???? While 1 Sleep(10) WEnd Func OnAutoItExit() If @ExitMethod = 4 Then MsgBox(64, "Shutdown", "Bye-Bye!") EndFunc This is way easier than the others, and much more efficent. Link to comment Share on other sites More sharing options...
Swift Posted February 21, 2008 Author Share Posted February 21, 2008 Should I just use AdLibEnable() for that? Link to comment Share on other sites More sharing options...
rover Posted February 21, 2008 Share Posted February 21, 2008 (edited) the reason for using the WM_QUERYENDSESSION message handler was due to OnAutoItExit not always responding to shutdown events I'll look up the post by ChrisL on that Here will this WM_QUERYENDSESSION work with restart?yes Edited February 21, 2008 by rover I see fascists... 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