Sign in to follow this  
Followers 0
apstanto

How does the Hibernate code work?

6 posts in this topic

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!

Share this post


Link to post
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


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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!?!?

Share this post


Link to post
Share on other sites

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!?!?

without seeing the code, i can't tell you why it's not working

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

Any ideas?

Share this post


Link to post
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
Sign in to follow this  
Followers 0