Jump to content

Wait until specific time


Recommended Posts

Im building a script to delete files after a certain date, this script will be run as a system service via srvany. how would i go about having the program run a a certain time in the day? so far all important variables are being picked up off of an ini file.

here is the question in a simpler manner:

$i=1
While $i=1
[b]waituntiltime(10,"AM")[/b]; this is the part that im looking for, has anyone already created a function that would work here?
msgbox(0,"title","its currently 10am")
Wend

it really doesnt matter if its in military or standard but having this script run as a system service is key, i really dont want to have to use messy windows scheduling.

Link to comment
Share on other sites

This is very generic but I have used this before.

Func WaitUntilTime($Hour, $Min, $Sec)
    While 1
        Sleep(1000)
        If @HOUR = $Hour And @MIN = $Min And @SEC = $Sec Then
    ;What you want to do, once this processes you can continue loop or exit the script
        EndIf
    WEnd
EndFunc
Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

This is very generic but I have used this before.

Func WaitUntilTime($Hour, $Min, $Sec)
    While 1
        Sleep(1000)
        If @HOUR = $Hour And @MIN = $Min And @SEC = $Sec Then
;What you want to do, once this processes you can continue loop or exit the script
        EndIf
    WEnd
EndFunc

Would there happen to be something that doesnt rely on sleep? Trying to keep my script as elegantly written as possible. This will definitely work but im hoping for something a little lower level.

Link to comment
Share on other sites

Just reduce the sleep there, there is a good chance that it will miss the second.

Edit:

I wouldn't say this is better but it doesn't rely on the sleep (just saves the cpu)

#include <Date.au3>
$enddate="2008/04/02 12:00:00" ; Continues script after this date
$diff=_DateDiff("s",_NowCalc(),$enddate)
$timer=TimerInit()
while True
    sleep(10)
    If (TimerDiff($timer)/1000)>$diff Then ExitLoop
WEnd
Edited by monoceres

Broken link? PM me and I'll send you the file!

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