Jump to content

Trigger before STANDBY in W7/Vista


bentom
 Share

Recommended Posts

Hi,

For the described problem I did not find a solution yet. Would be great if someone could help me out.

I use my Pc for Recording TV. This works very good. After recording the Computer is triggered to standby. Unfortunately another application has to be closed otherwise it does not work properly after wakeup.

I found a (Microsoft) documented code that could trigger a certain event before standby. This is the part of the code

Case $PBT_APMSUSPEND
            ConsoleWrite("SUSPEND" & @CRLF)
            WinClose("APP")

My problem is that this works perfectly under XP but with VISTA/W7 this event does not stop the standby process. Means that it could be (happens about 30%) that the time for the standby is not enough and after the wake up the app is still alive (which causes the error). So does anyone know how to handle this?

Thank you very much and Regards,

Alex

Global Const $WM_POWERBROADCAST = 0x218
Global Const $PBT_APMPOWERSTATUSCHANGE = 0xA ; Power status has changed.
Global Const $PBT_APMRESUMEAUTOMATIC = 0x12 ; Operation is resuming automatically from a low-power state. This message is sent every time the system resumes.
Global Const $PBT_APMRESUMESUSPEND = 0x7 ;Operation is resuming from a low-power state. This message is sent after PBT_APMRESUMEAUTOMATIC if the resume is triggered by user input, such as pressing a key.
Global Const $PBT_APMSUSPEND = 0x4 ; System is suspending operation.
Global Const $PBT_POWERSETTINGCHANGE = 0x8013 ; A power setting change event has been received.

;    Windows Server 2003, Windows XP, and Windows 2000:  The following event identifiers are also supported.
Global Const $PBT_APMBATTERYLOW = 0x9 ; Battery power is low. In Windows Server 2008 and Windows Vista, use PBT_APMPOWERSTATUSCHANGE instead.
Global Const $PBT_APMOEMEVENT = 0xB ; OEM-defined event occurred. In Windows Server 2008 and Windows Vista, this event is not available because these operating systems support only ACPI; APM BIOS events are not supported.
Global Const $PBT_APMQUERYSUSPEND = 0x0 ; Request for permission to suspend. In Windows Server 2008 and Windows Vista, use the SetThreadExecutionState function instead.
Global Const $PBT_APMQUERYSUSPENDFAILED = 0x2 ; Suspension request denied. In Windows Server 2008 and Windows Vista, use SetThreadExecutionState instead.
Global Const $PBT_APMRESUMECRITICAL = 0x6 ; Operation resuming after critical suspension. In Windows Server 2008 and Windows Vista, use PBT_APMRESUMEAUTOMATIC instead. 
Global Const $BROADCAST_QUERY_DENY = 0x424D5144


GUICreate("Event Receiver")
GUIRegisterMsg($WM_POWERBROADCAST,"MY_WM_POWERBROADCAST")
While 1
    Sleep(100)
WEnd
Func MY_WM_POWERBROADCAST($hWnd, $uMsg, $wParam, $lParam)
    ; Beschreibgungen auf http://msdn.microsoft.com/en-us/library/aa373247(VS.85).aspx
    Switch $wParam
        Case $PBT_APMRESUMEAUTOMATIC
            ConsoleWrite("RESUMEAUTOMATIC" & @CRLF)
            sleep(7000)
            Run(APP)
            ConsoleWrite("RESUMESUSPEND" & @CRLF)
        Case $PBT_APMSUSPEND
            ConsoleWrite("SUSPEND" & @CRLF)
            WinClose("APP")
    EndSwitch
EndFunc
Link to comment
Share on other sites

It appears you're not allowed to stop the power transition process anymore (all versions after XP). Quoting Handling OS events like Sleep, Stand-by, ... (Scroll down to "OS Events in Windows VISTA":

In Windows Vista, applications can no longer block in-progress sleep transitions. The PBT_APMQUERYSUSPEND event is not delivered to applications in VISTA and hence applications cannot deny/abort the suspend operation. As per Microsoft's recommendation that applications should not block in-progress sleep transitions on any version of Windows. In VISTA suspend transitions is pretty fast to increase the performance and hence applications handling the PBT_APMSUSPEND event must process it within 2 seconds. Applications have 2 seconds to finish processing the PBT_APMSUSPEND event before Windows continues with the sleep transition, If an application has not returned from the PBT_APMSUSPEND event after 2 seconds, the system will go ahead to sleep state and any remaining processing completes after the system resumes from the sleep state.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hi,

thank you very much. That's the reason for it. I feared someting like that.

As I understood there's no solution for this "problem", is it?

Whaht's the reason for such a strange idea ???

If anybody have an idea would be great to hear it

Regards,

Alex

I just found an article about this function: SetThreadExecutionState. Will have to look for this here in the forum perhaps this could be a solution

Edited by bentom
Link to comment
Share on other sites

I think SetThreadExecutionState might just prevent idle-timeout standby. I haven't been able to get it to block standby. When the computer is done recording can you get it to run an application instead of just going to standby? That way you could make a script to close the other program and send the machine to standby.

Edited by TurionAltec
Link to comment
Share on other sites

Hi,

thanks a lot for your answer. The problem is that the application does not provide a trigger when stopping a recording. It just send the computer to standby (or shutdown,restart).

Anyway, I will have a closer look in the mircrosoft forum, perhaps I'll find a way. Thanks again

And Regards,

Alex

Link to comment
Share on other sites

Hello again,

I had a closer look in several forums and microsoft documentaions but did not find any statement to this. I understood that it is possible to block the standby with this function but duid not get it to work.

E.G. the Windows Home Server control can block the standby (for backup) so there must be a function...but no documentation :-(

If someone has an idea would be very happy to hear it

Regards,

Alex

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...