Jump to content

Need help with Sleep test (Standby mode)


hambaba
 Share

Recommended Posts

Can anybody help me with this, I need to know if Autoit is able to put a system to sleep (Standby mode), then after few seconds, wake up the system, and then repeat the sequence for few times.

Is autoit able to do that.

Before I go to sleep, I need to have a cmd open and a "Ping -t some_IP_Address" in that command prompt going.

then system go to sleep.

then system wake up

check for the cmd interface and make sure the ping is still going and active.

go back to sleep.

repeat the above sequence for 20 times.

finish the test as pass if successful.

Thanks for your help.

Link to comment
Share on other sites

You dont actually want the system to "go to sleep" because you cannot wake it up from a program.

Here is a timed ping checker

$sleeptime = 8 ; hours to run over

For $i=1 To 20
    Ping("127.0.0.1",500)
    If @error Then
        ; do whatever you want if it fails
    EndIf
    Sleep($sleeptime*60*60*1000/20)
Next

_________[u]UDFs[/u]_________-Mouse UDF-Math UDF-Misc Constants-Uninstaller Shell

Link to comment
Share on other sites

You dont actually want the system to "go to sleep" because you cannot wake it up from a program.

I think you can if you know how to use SetWaitableTimer, though I don't.

You could use another PC to send a wakeup to the sleeping PC if you set it to wake on Lan.

If your PC can be woken from hibernate with a mouse move then you could use the WAKE technology developed in early, um.. 2010.

Find a box just big enough to hold your mobile phone which you set alarms on every 10 minutes for vibrate. Put the mouse on top of the phone and .. oh, you guessed.

(Windows Auto Kill hibernate Event)

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

lmao, martin, I like that technology. You should definitely patent that. If it wasn't critical for the system to go to sleep, and instead you could do it by rebooting... you could add the program to the start up list and do it that way, just have the script reset the computer, then like 20 seconds after it logs in (or a good amount of time to let things start up) run the cmd and ping?

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

  • 11 months later...

Can anybody help me with this, I need to know if Autoit is able to put a system to sleep (Standby mode), then after few seconds, wake up the system, and then repeat the sequence for few times.

Is autoit able to do that.

Before I go to sleep, I need to have a cmd open and a "Ping -t some_IP_Address" in that command prompt going.

then system go to sleep.

then system wake up

check for the cmd interface and make sure the ping is still going and active.

go back to sleep.

repeat the above sequence for 20 times.

finish the test as pass if successful.

Thanks for your help.

When you create a scheduled task you can start the pc when in sleep mode. Then the program can run and put the pc back into sleep.

Link to comment
Share on other sites

  • 2 weeks later...

When you create a scheduled task you can start the pc when in sleep mode. Then the program can run and put the pc back into sleep.

I hope this is the code you need. I extracted it from a bigger program that I use daily on my pc. Included in the code there is an GUI that will allow you to set sleeping and wake-up times. Lots of hints coming from the forum as always

The routing is currently tested on a win7 0x64

Global $SleepH = 01, $SleepM = 10, $WakeH = 07, $WakeM = 30     ;*********  ;SleepCycles
Func ReadyForStandby()
    Local $answ, $r, $snooze, $nMsg, $PostPoned
    Local $mode = True  ;True=Hibernate, False=Suspend
    Local $WT = String($WakeH) & ":" & String($WakeM)
    Local $ST = String($SleepH) & ":" & String($SleepM)
    
    Local $Form1 = GUICreate("Sleep and Wake up Time", 290, 200, 731, 229, $WS_SYSMENU, $WS_EX_TOPMOST)
    Local $Button1 = GUICtrlCreateButton("OK", 31, 110, 100, 34, 0)
    Local $Button2 = GUICtrlCreateButton("NO", 142, 110, 100, 34, 0)
    Local $SleepInput = GUICtrlCreateEdit("", 31, 84, 100, 21, $ES_WANTRETURN)
    Local $WakeInput = GUICtrlCreateEdit("", 145, 84, 100, 21, $ES_WANTRETURN)
    Local $Label1 = GUICtrlCreateLabel("The computer is about to go to sleep", 30, 4, 233, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x800000)
    Local $label2 = GUICtrlCreateLabel("Press OK to execute NOW ", 55, 20, 233, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x800000)
    Local $label2 = GUICtrlCreateLabel("Modify values and press OK to RESET ", 28, 36, 233, 20)
    GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x800000)
    Local $Label3 = GUICtrlCreateLabel("TIME DOWN", 36, 57, 91, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x800000)
    Local $Label4 = GUICtrlCreateLabel("TIME UP", 160, 57, 65, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x800000)
    
    _GUICtrlEdit_SetText ($SleepInput, $ST)
    _GUICtrlEdit_SetSel ($SleepInput, 0, -1)
    _GUICtrlEdit_SetText ($WakeInput, $WT)
    _GUICtrlEdit_SetSel ($WakeInput, 0, -1)
    GUISetState(@SW_SHOW)
    $snooze = TimerInit()
    
    Do
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $nMsg = 0
                ContinueLoop
            Case $Button1
                $answ = "yes"
                $nMsg = $GUI_EVENT_CLOSE
            Case $Button2
                $answ = "no"
                $nMsg = $GUI_EVENT_CLOSE
        EndSwitch
    Until $nMsg = $GUI_EVENT_CLOSE Or TimerDiff($snooze) >= (20 * 1000) ; idle 15 sec
    
    If ReadAssign($SleepInput, $WakeInput) = 1 Then $answ = "no"
    SetWakeUpTime($WakeH, $WakeM)
    GUIDelete($Form1)
    
    If $answ = "yes" Or TimerDiff($snooze) >= (20 * 1000) Then ;stanby!!
        $r = DllCall("PowrProf.dll", "long", "SetSuspendState", "long", $mode, "long", True, "long", False)
    EndIf
EndFunc   ;==>ReadyForStandby
;--
;--
;--

Func ReadAssign($Sinp, $Winp)
    Local $i = _GUICtrlEdit_GetText ($Sinp)
    $WakeH = Int(StringLeft( _GUICtrlEdit_GetText ($Winp), 2))
    $WakeM = Int(StringRight( _GUICtrlEdit_GetText ($Winp), 2))
    If $SleepH <> Int(StringLeft($i, 2)) Or $SleepM <> Int(StringRight($i, 2)) Then
        $SleepH = Int(StringLeft($i, 2))
        $SleepM = Int(StringRight($i, 2))
        Return 1
    EndIf
    Return 0
EndFunc   ;==>ReadAssign
;;   ***************************************************SetWakeUpTime
Func SetWakeUpTime($Hour, $Minute, $Day = @MDAY, $Month = @MON, $Year = @YEAR)
    Local $result, $lastError
    Local $SYSTEMTIME = DllStructCreate("ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort")
    Local $lpSYSTEMTIME = DllStructGetPtr($SYSTEMTIME)
    Local $LOCALFILETIME = DllStructCreate("dword;dword")
    Local $lpLOCALFILETIME = DllStructGetPtr($LOCALFILETIME)
    Local $DueTime = DllStructCreate("dword;dword")
    Local $lpDueTime = DllStructGetPtr($DueTime)

    DllStructSetData($SYSTEMTIME, 1, $Year)
    DllStructSetData($SYSTEMTIME, 2, $Month)
    DllStructSetData($SYSTEMTIME, 3, _DateToDayOfWeek($Year, $Month, $Day) - 1)
    DllStructSetData($SYSTEMTIME, 4, $Day)
    DllStructSetData($SYSTEMTIME, 5, $Hour)
    DllStructSetData($SYSTEMTIME, 6, $Minute)
    DllStructSetData($SYSTEMTIME, 7, 0)
    DllStructSetData($SYSTEMTIME, 8, 0)

    $result = DllCall("kernel32.dll", "long", "SystemTimeToFileTime", "ptr", $lpSYSTEMTIME, "ptr", $lpLOCALFILETIME)
    If $result[0] = 0 Then
        $lastError = DllCall("kernel32.dll", "int", "GetLastError")
        SetExtended($lastError[0])
        SetError(1)
        Return 0
    EndIf
    $result = DllCall("kernel32.dll", "long", "LocalFileTimeToFileTime", "ptr", $lpLOCALFILETIME, "ptr", $lpLOCALFILETIME)
    If $result[0] = 0 Then
        Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
        SetExtended($lastError[0])
        SetError(1)
        Return 0
    EndIf
    $result = DllCall("kernel32.dll", "long", "CreateWaitableTimer", "long", 0, "long", True, "str", "")
    If $result[0] = 0 Then
        Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
        SetExtended($lastError[0])
        SetError(1)
        Return 0
    EndIf
    DllCall("kernel32.dll", "none", "CancelWaitableTimer", "long", $result[0])

    DllStructSetData($DueTime, 1, DllStructGetData($LOCALFILETIME, 1))
    DllStructSetData($DueTime, 2, DllStructGetData($LOCALFILETIME, 2))

    $result = DllCall("kernel32.dll", "long", "SetWaitableTimer", "long", $result[0], "ptr", $lpDueTime, "long", 1000, "long", 0, "long", 0, "long", True)
    If $result[0] = 0 Then
        Local $lastError = DllCall("kernel32.dll", "int", "GetLastError")
        SetExtended($lastError[0])
        SetError(1)
        Return 0
    EndIf
    Return 1
EndFunc   ;==>SetWakeUpTime
Edited by Hermano
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...