wraithdu Posted August 21, 2015 Share Posted August 21, 2015 (edited) Contrary to what Microsoft says here about WM_ENDSESSIONhttps://msdn.microsoft.com/en-us/library/windows/desktop/aa376889(v=vs.85).aspxI am not receiving the message on shutdown on any of Windows 7 / 8.1 / 10, if I return TRUE (1) to WM_QUERYENDSESSION. I'm only receiving WM_ENDSESSION if I return FALSE (0) to WM_QUERYENDSESSION. This is rather annoying, as I don't want to halt shutdown, just do some application cleanup. And according to MS, that should be done in WM_ENDSESSION, not the former.For now I can work around this in 1 of 2 ways:1) If my app has a GUI, do the cleanup in WM_QUERYENDSESSION2) If my app does not have a GUI (note I must create a hidden GUI to receive the messages), I return FALSE to QUERY and do my cleanup in END. Also note that Windows does NOT display the Cancel shutdown dialog after returning FALSE to QUERY if there is no visible GUI window.See my simple sample code below. Try it with or without displaying the GUI and varying the return of QUERY, and see when and where things are logged. Really I'm just looking for confirmation that MS is full of crap and things don't really work the way they say they should. You can just log out instead of a full shutdown, the result is the same.expandcollapse popup#include <WinAPISys.au3> #include <WindowsConstants.au3> Global $hGui Global $bExit = False _Main() Func _Main() _WinAPI_SetProcessShutdownParameters(0x3FF) $hGui = GUICreate("") GUIRegisterMsg($WM_QUERYENDSESSION, QUERY) GUIRegisterMsg($WM_ENDSESSION, END) GUISetState(@SW_SHOW) While 1 Sleep(50) If $bExit Then ExitLoop WEnd EndFunc Func QUERY($hWnd, $iMsg, $wParam, $lParam) FileWriteLine(@DesktopDir & "\QUERY.txt", @HOUR & ":" & @MIN & ":" & @SEC & @TAB & _ $hWnd & " : " & $iMsg & " : " & $wParam & " : " & $lParam) Return 1 EndFunc Func END($hWnd, $iMsg, $wParam, $lParam) FileWriteLine(@DesktopDir & "\END.txt", @HOUR & ":" & @MIN & ":" & @SEC & @TAB & _ $hWnd & " : " & $iMsg & " : " & $wParam & " : " & $lParam) $bExit = True Return 0 EndFunc Edited August 21, 2015 by wraithdu 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