Sign in to follow this  
Followers 0
Swift

how to see if computer is going to be shutdown

14 posts in this topic

Does anyone know how exactly?

Share this post


Link to post
Share on other sites



Your GUI is sent the WM_QUERYENDSESSION message.

Try registering an event to that.

Share this post


Link to post
Share on other sites

Not Using A GUI :)

So..

In my loop...how...? will I do this?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by Swift

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Will this work...if user logged off...shutdown...or restart?

Share this post


Link to post
Share on other sites

#10 ·  Posted (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 by rover

I see fascists...

Share this post


Link to post
Share on other sites

Thanks :) I got that part now...It works...but what i'm asking is...will this WM_QUERYENDSESSION work with restart?

Share this post


Link to post
Share on other sites

Should I just use AdLibEnable() for that?

Share this post


Link to post
Share on other sites

#14 ·  Posted (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 by rover

I see fascists...

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