Jump to content

How can abort a shutdown process in vista and XP


Recommended Posts

Can someone please explain me if there is a way to tell windows that stop shutdown process, so I can run another program (backup and Sync) and when finished then tell windows to shutdown normally.

I know you can do a program in autoit that can execute and wait until the program finish an then it can shutdown the PC. But some times there are other peoples that use the PC an they don't know or they forgot to execute the porgram and the Backup and syncronization can't be executed.

I also know that you can register WM_QUERYENDSESSION message but when return false from the function registered In windows vista appears a black screen asking if you want to kill the program. So this didn't tell to stop shutdown at all.

Thanks in advance.

Link to comment
Share on other sites

Sorry but "shutdown - a" seems that doesn't work.

see code below

#RequireAdmin
HotKeySet("{ESC}", "_Quit") ; exit demo
#include <File.au3>
Global $logfile
Global Const $WM_QUERYENDSESSION = 0x0011
Global $ShuttingDown = False

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
    if $ShuttingDown Then
        CancelShutDown()
        RunOtherPrograms()
        AskForShutDown()
    EndIf
    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
    $ShuttingDown = True
    ;Beep(1000,5)
    
    _FileWriteLog($logfile, "Logoff or Shutdown Event  - Exiting" & @CRLF)
    Return False ; acknowledges system shutdown command, responds to system with 'True'
EndFunc   ;==>_ShutdownInitiated

Func _Quit()
    Exit
EndFunc

Func CancelShutDown()
    Run(@ComSpec & " /c Shutdown -a")
EndFunc

Func RunOtherPrograms()
    MsgBox(64,"Running", "Here is where you execute others programs")
EndFunc

Func AskForShutDown()
    $Result = MsgBox(35, "Pregunta", "Are you sure want to exit?", 15)
    if $Result = 6 or $Result = -1 Then ; Yes Shutdown
        Shutdown(1)
        Exit
    ElseIf $Result = 2 then ; Cancel Stop this program
        Exit
    EndIf
EndFunc

Any other solution?

Thanks in advance

Edited by GioVit
Link to comment
Share on other sites

  • 1 year later...

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