Jump to content
Sign in to follow this  
ghetek

Wait until specific time

Recommended Posts

ghetek

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.

Share this post


Link to post
Share on other sites
DarkMatter

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]

Share this post


Link to post
Share on other sites
ghetek

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.

Share this post


Link to post
Share on other sites
monoceres

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!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.