Jump to content

How does the Hibernate code work?


apstanto
 Share

Recommended Posts

I've been using bastel123's code for putting a laptop into Hibernate (or standby), and then having it resume automatically. I'd like some insight into how the code works, because I'm having trouble with it on XP and not other platforms. What is different about XP that would cause:

1) The timer to not work correctly. It works the first iteration, but after that it stays in the powersave mode for only one second and then resumes.

2) Sometimes it gets stuck in hibernate and never resumes.

I don't have any of these problems with Windows 7 or Vista. Whats different about XP?

Thanks in advance!

Link to comment
Share on other sites

it looks like the issue is in your implementation rather than his code, most likely you're not recalling the SetWakeUpTime() function on subsequent iterations, so it's using the same wake time which will have already passed

Thanks for the reply! I do a SetWakeUpTime() for each new iteration. I know the implementation is correct, because it works in Win7 and Vista. Unless there is something different/special I need to do for XP!?!?

Link to comment
Share on other sites

SetWakeUpTime() and SetSuspend() are the same as bastel123's code. And like I said, this works perfectly in Windows 7 and Vista. $MinutesToWake = 1. I call the following in a loop:

#cs *********************************************************************************************************
Function Name:  PowerSave
Author:         Andrew Stanton - apstanto@gmail.com

Description:    Sends the system into the sleep state for the amount of time spcified in the .ini file



Requirement(s): PowrProf.dll, kernel32.dll (note: these dll files are found in C:\Windows\System32
                folder of all Windows versions tested.)

Input:          none

Return:         1 on success
                0 on failure

#ce *********************************************************************************************************
Func PowerSave()

    Trace("PowerSave", $TRACE_FUNC_START)

    ; Show Standby message
    $button = MsgBox(1, "Host Automation Tester", "Going to " & $State & " for " & $MinutesToWake & " minute(s) ...", 2)
    If $button = 2 Then
        Return 0
    EndIf

    ; Set wakeup time
    If Not SetWakeUpTime(@HOUR, @MIN + $MinutesToWake) Then
        If not @extended = 0 Then
            Trace("Unknown error occured in SetWakeUpTime()!!!  @error = " & @extended , $TRACE_ERROR)
        EndIf
    EndIf

    ; Power save
    If $SleepState = $HIBERNATE Then
        Trace ("Hibernate at " & @HOUR&":"&@MIN&":"&@SEC&@CRLF, $TRACE_MSG)
        SetSuspend(True)

    ElseIf $SleepState = $STANDBY Then
        Trace ("Standby at " & @HOUR&":"&@MIN&":"&@SEC&@CRLF, $TRACE_MSG)
        SetSuspend(False)
    Else
        Trace("Unknown Sleep State: " & $SleepState, $TRACE_ERROR)
        Trace("PowerSave", $TRACE_FUNC_END)
        Return 0
    EndIf

    ; Resume
    Trace ("Resumed at " & @HOUR & ":" & @MIN & ":" & @SEC & @CRLF, $TRACE_MSG)
    _Monitor_ON()

    ; wait for applications to start
    sleep ($APP_DELAY_SHORT * 1000)

    If @error = 0 Then
        Trace("PowerSave", $TRACE_FUNC_END)
        Return 1
    Else
        Trace ("**** Failed to powersave!****", $TRACE_MSG)
        MsgBox(1, "Powersave Error", "Failed to powersave. " & @LF & @LF & _
                            "Error Code: " & @error & @LF & " Key: " & _
                            "1 unable to use the DLL file" & @LF & _
                            "2 unknown return type" & @LF & _
                            "3 function not found in the DLL file" & @LF & _
                            "4 bad number of parameters." & @LF & @LF & _
                            "See AutoIt DllCall() for more informationl.")

        Trace("PowerSave", $TRACE_FUNC_END)
        Return 0
    EndIf
EndFunc

I hope that's enough to see the general picture!

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...