Windows 7可防止关机

时间:2012-06-16 22:01:20

标签: windows administration shutdown autoit system-administration

我希望能够阻止Windows 7上的常规关闭。我发现了这个AutoIt脚本,但它没有真正点击强制关闭对话框上的CANCEL按钮。

有人可以测试它并告诉我什么是错误的吗?

$WM_QUERYENDSESSION = 0x11
GUIRegisterMsg($WM_QUERYENDSESSION, "Cancel_Shutdown")
$Hwnd = GUICreate("PreventShutdownGUI")
;~ GUISetSTate(@SW_SHOW)


_ShutdownBlockReasonCreate($hwnd, "Sorry, AutoIt > Windows")
TrayTip("Shutdown Blocker - Started", "Denies shutdowns from now on.", 20)
While Sleep(100)
WEnd
_ShutdownBlockReasonDestroy($hwnd)

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

Func _ShutdownBlockReasonDestroy($Hwnd)
    Local $aResult = DllCall("User32.dll", "int", "ShutdownBlockReasonDestroy", "hwnd", $Hwnd)
    If @error Then Return SetError(1,0,0)
    Return $aResult[0]
EndFunc

Func Cancel_Shutdown($hWndGUI, $MsgID, $WParam, $LParam)
    ; This HAS to be here to capture the endsession...
    AdlibRegister("Cancel_ShutdownResolver",50)
    Return False
EndFunc

Func Cancel_ShutdownResolver()
    Local $iOpt = Opt("WinTitleMatchMode",4),$hwnd = WinGetHandle("[CLASS:BlockedShutdownResolver]")
    Opt("WinTitleMatchMode",$iOpt)
    If $hwnd Then
        If @OSVersion = "WIN_7" Then ControlClick($hwnd,"","[CLASS:Button; INSTANCE:1]")
        If @OSVersion <> "WIN_7" Then ControlClick($hwnd,"","[CLASS:Button; INSTANCE:2]")
        AdlibUnRegister("Cancel_ShutdownResolver")
        TrayTip("Shutdown Blocker - Shutdown denied", "Denied shutdown successfull!", 5)
        _DeineFunktion()  ; <================ Hier musst du deine Funktion einfügen
    EndIf
EndFunc

Func _DeineFunktion()
    MsgBox(0,"","Das hier ist deine Funktion ;) - Danach musst du erneut _ShutdownBlockReasonDestroy($hwnd) aufrufen, und einen neuen Shutdown machen.")
EndFunc

1 个答案:

答案 0 :(得分:2)

在我看来,这是一种阻止autoit函数被杀的方法..

_deineFunction()(函数的德语)是你不想被杀的函数。