I have spent quite many hours now trying to figure out how to make this script work as good on Win7 as it does on XP as well. Instead of
PBT_APMQUERYSUSPEND and
BROADCAST_QUERY_DENY := 1112363332
the documentation says i should use
SetThreadExecutionState (Enables an application to inform the system that it is in use, thereby preventing the system from entering sleep or turning off the display while the application is running.)
, but I do not find any wParam value for that and I dont really understand how to use it, since it is quite different from the PBT_APMQUERYSUSPEND (Requests permission to suspend the computer). Can somebody clear this up for me?
Here is my WinXP adapted code so far:
#NoTrayIcon #Persistent OnMessage(0x0218, "OnPBMsg") hibernate = 0 Return OnPBMsg(wParam, lParam, msg, hwnd) { global hibernate If (wParam = 0 or wParam=4) { ;PBT_APMQUERYSUSPEND If (lParam & 1) ;Check action flag { if (hibernate = 0) { SetTimer, InterceptPBMSG, -1 Return 1112363332 } else Return 4 } } ;Must return True after message is processed Return True } InterceptPBMSG: Secs := 20 SetTimer, CountDown, 1000 MsgBox, 262148, System Hibernation in 20 seconds, Your HTPC is about to be Hibernated.`nAllow it?, %Secs% SetTimer, CountDown, Off IfMsgBox, Yes { hibernate = 1 DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0) hibernate = 0 Return } IfMsgBox, Timeout { hibernate = 1 DllCall("PowrProf\SetSuspendState", "int", 1, "int", 0, "int", 0) hibernate = 0 Return } IfMsgBox No { hibernate = 0 return } Return CountDown: Secs -= 1 WinSetTitle, System Hibernation in,, System Hibernation in %Secs% seconds Return