尝试这个 :
#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