ken82m Posted May 7, 2009 Share Posted May 7, 2009 Is it possible to detect when windows is shutting down, restarting, or logging off. I have two applications that don't seem to be able to figure that out, and it causes all kinds of errors during the above events. So I'd like to have a little script running in the background that will detect the event and kill the two processes. Thanks, Kenny "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
monoceres Posted May 7, 2009 Share Posted May 7, 2009 Windows sends the WM_EndSession to all desktop windows when it is about to shutdown.You can catch it with the GUIRegisterMsg() function. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
monoceres Posted May 7, 2009 Share Posted May 7, 2009 You might as well read up on this message as well. It's closely realted to WM_EndSession. Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
LoWang Posted November 15, 2010 Share Posted November 15, 2010 but it seems that this works only for programs with GUI. If I have a process without window then the message is not sent to it or GUIRegisterMsg does not receive it... Too bad Link to comment Share on other sites More sharing options...
KaFu Posted November 15, 2010 Share Posted November 15, 2010 Add a dummy GUI to catch the Windows Messages and don't show it. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Juvigy Posted November 15, 2010 Share Posted November 15, 2010 expandcollapse popupThere were several "intercept shutdown" examples in the forum. This is one of them: GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown") GUICreate("PreventShutdownGUI") GUISetSTate(@SW_HIDE) ; set highest notification level If Not _SetProcessShutdownParameters(0xFFF) Then ; MSDN says maximum is 0x4FF, but it worked for me If Not _SetProcessShutdownParameters(0x4FF) Then ; MSDN says this is reserved for System, but worked for me _SetProcessShutdownParameters(0x3FF) ; highest not reserved number, if everything else does not work EndIf EndIf Global $b_ShutdownInitiated = False While 1 If $b_ShutdownInitiated = True then $b_ShutdownInitiated = False MsgBox(48 + 8192 + 262144, "Installer", "Ending your user session has been disabled to allow the installation to complete." _ & @CRLF & @CRLF & "You will be able to shutdown/reboot/logoff once the installation process has completed." , 8) EndIf sleep(10) WEnd Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam) $b_ShutdownInitiated = True ; DO NOT ADD A MSGBOX HERE ; Windows shows a not responding box after ~5 secs and allows to kill your app. Return False EndFunc Func _SetProcessShutdownParameters($dwLevel, $dwFlags=0) ; http://msdn.microsoft.com/en-us/library/ms686227%28VS.85%29.aspx ; Prog@ndy Local $aResult = DllCall("Kernel32.dll", "int", "SetProcessShutdownParameters", "dword", $dwLevel, "dword", $dwFlags) If @error Then Return SetError(1,0,0) Return $aResult[0] EndFunc Link to comment Share on other sites More sharing options...
LoWang Posted November 15, 2010 Share Posted November 15, 2010 thanks I will test it, but it will be interesting yet, because actually I have a service running which needs to know this so it does not start doing some stuff during shutdown. So I will have to make this other process maybe write some value into registry and the service will check it before running the risky functions... Link to comment Share on other sites More sharing options...
LoWang Posted November 29, 2010 Share Posted November 29, 2010 and how do the normal windows services do it? You think they have to be programmed that it does not matter if they are ended anytime or is there some programming interface which we don't have in autoit? 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