Jump to content

how to see if computer is going to be shutdown


Swift
 Share

Recommended Posts

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

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

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

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...