【问题标题】:AutoIt - Detect System Shutdown/RebootAutoIt - 检测系统关闭/重启
【发布时间】:2013-10-29 15:38:24
【问题描述】:

我想让 AutoIt 在系统即将关闭或重新启动时显示一个消息框。 我试过这个:

#include <WindowsConstants.au3>

$hGUI = GuiCreate("") ; Create a GUI and don't show it
GuiRegisterMsg($WM_ENDSESSION, "WM_ENDSESSION")

; Do stuff here...
While 1 ; Loop does nothing
    Sleep(100)
WEnd

Func WM_ENDSESSION($hWnd, $Msg, $wParam, $lParam)
    MsgBox(0,"SystemShutdown", @HOUR & ":" & @MIN & ":" & @SEC & @TAB & "WM_ENDSESSION: " & $hWnd & ", " & $Msg & ", " & $wParam & ", " & $lParam & @CRLF)
EndFunc

但它不起作用?

【问题讨论】:

    标签: system autoit shutdown reboot


    【解决方案1】:

    试试这个:

        #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <date.au3>
    ;~ #define PBT_APMQUERYSUSPEND           0x0000
    ;~ #define PBT_APMQUERYSTANDBY           0x0001
    ;~ #define PBT_APMQUERYSUSPENDFAILED     0x0002
    ;~ #define PBT_APMQUERYSTANDBYFAILED     0x0003
    ;~ #define PBT_APMSUSPEND                0x0004
    ;~ #define PBT_APMSTANDBY                0x0005
    ;~ #define PBT_APMRESUMECRITICAL         0x0006
    ;~ #define PBT_APMRESUMESUSPEND      0x0007
    ;~ #define PBT_APMRESUMESTANDBY      0x0008
    ;~ #define PBTF_APMRESUMEFROMFAILURE     0x00000001
    ;~ #define PBT_APMBATTERYLOW             0x0009
    ;~ #define PBT_APMPOWERSTATUSCHANGE  0x000A
    ;~ #define PBT_APMOEMEVENT               0x000B
    ;~ #define PBT_APMRESUMEAUTOMATIC        0x0012
    Global $PBT_APMSUSPEND = 0x0004
    Global $PBT_APMRESUMESUSPEND = 0x0007
    Global $PBT_APMSTANDBY = 0x0005
    Global $PBT_APMRESUMESTANDBY = 0x0008
    
    $hGUI = GUICreate("Test", 100, 100, 1, 1)
    GUIRegisterMsg($WM_POWERBROADCAST, "Standby")
    GUIRegisterMsg($WM_QUERYENDSESSION, "_Shutdown")
    ;~ GUISetState()
    While 1
        Sleep(10)
    ;~ $GUIMsg = GUIGetMsg()
    ;~   Switch $GUIMsg
    ;~       Case $GUI_EVENT_CLOSE
    ;~           ExitLoop
    ;~   EndSwitch
    WEnd
    ;
    Exit
    ;
    Func Standby($hWnd, $Msg, $wParam, $lParam)
        ConsoleWrite(_NowTime() & ": " & $wParam & @LF)
        Select
            Case $wParam = $PBT_APMSUSPEND
                ConsoleWrite(" You going into Suspend." & @LF)
            Case $wParam = $PBT_APMRESUMESUSPEND
                ConsoleWrite(" You just woke up from Suspend." & @LF)
            Case $wParam = $PBT_APMRESUMESTANDBY
                ConsoleWrite(" You are going into Standby." & @LF)
            Case $wParam = $PBT_APMRESUMESTANDBY
                ConsoleWrite(" You just woke up from Standby." & @LF)
                ;MsgBox(0,"Hello Back", " You just woke up from Standby")
            Case Else
        EndSelect
    EndFunc   ;==>Standby
    
    Func _Shutdown()
        MsgBox(16, 'SHUTDOWN', ' oh oh shutting down ... ')
    EndFunc   ;==>_Shutdown
    

    【讨论】:

      猜你喜欢
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-09
      • 1970-01-01
      • 2019-12-19
      相关资源
      最近更新 更多