Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Written in AutoIt - www.autoitscript.com
- Global $hWnd, Const $WM_QUERYENDSESSION = 0x11
- ; Register Shutdown Message Handler - see
- ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa376890%28v=vs.85%29.aspx
- GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown")
- ; Create Block-Reason
- $hWnd = GUICreate("PreventShutdownGUI")
- _ShutdownBlockReasonCreate($hWnd, "Sorry, AutoIt > Windows")
- ; Register Cleanup Function
- OnAutoItExitRegister('_Cleanup')
- ; Show Info in Taskbar
- TrayTip("Shutdown Blocker - Started", "Denies shutdowns from now on.", 20)
- ; Idle around..
- While Sleep(1000)
- WEnd
- Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam)
- ; Since we should return to the operating system asap,
- ; we register an adlib function, wich will be called in 50ms.
- AdlibRegister("Cancel_ShutdownResolver", 50)
- Return False
- EndFunc ;==>Cancel_Shutdown
- Func Cancel_ShutdownResolver()
- Local $iOldOption. $hWnd
- $iOldOption = Opt("WinTitleMatchMode", 4)
- $hWnd = WinGetHandle("[CLASS:BlockedShutdownResolver]")
- Opt("WinTitleMatchMode", $iOldOption)
- If $hWnd Then
- ; unregister adlib function.
- AdlibUnRegister("Cancel_ShutdownResolver")
- ; Click the cancel button.
- If @OSVersion = "WIN_7" Then ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:1]")
- If @OSVersion <> "WIN_7" Then ControlClick($hWnd, "", "[CLASS:Button; INSTANCE:2]")
- ; Show Info in Tray
- TrayTip("Shutdown Blocker - Shutdown denied", "Denied shutdown successfull!", 5)
- ; ===================================|
- ; Call your user defined function... |
- _YourFunction() ; <================|
- ; ===================================|
- EndIf
- EndFunc ;==>Cancel_ShutdownResolver
- Func _YourFunction()
- ;MsgBox(0,"","Do whatever you want here...")
- EndFunc ;==>_YourFunction
- Func _Cleanup()
- _ShutdownBlockReasonDestroy($hWnd)
- EndFunc ;==>_Cleanup
- Func _ShutdownBlockReasonCreate($hWnd, $wStr)
- ; http://msdn.microsoft.com/en-us/library/ms...28VS.85%29.aspx
- ; Prog@ndy
- Local $aResult = DllCall("User32.dll", "int", "ShutdownBlockReasonCreate", "hwnd", $hWnd, "wstr", $wStr)
- If @error Then Return SetError(1, 0, 0)
- Return $aResult[0]
- EndFunc ;==>_ShutdownBlockReasonCreate
- Func _ShutdownBlockReasonDestroy($hWnd)
- Local $aResult = DllCall("User32.dll", "int", "ShutdownBlockReasonDestroy", "hwnd", $hWnd)
- If @error Then Return SetError(1, 0, 0)
- Return $aResult[0]
- EndFunc ;==>_ShutdownBlockReasonDestroy
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement