Sign in to follow this  
Followers 0
cyanidemonkey

run a scheduled task

10 posts in this topic

#1 ·  Posted (edited)

I have a .ini called schedule.ini

It has a bunch of preset tasks in it where the SectionName is the task name and the key/values are the start date time etc.

There is a start hour & minute and also a list of days to run the task (1 on / 4 off). Like this:

[Job 1]
StartHour=23
StartMinute=35
sunday=4
monday=1
tuesday=4
wednesday=1
thursday=4
friday=1
saturday=4
[Job 2]
StartHour=18
StartMinute=00
sunday=4
monday=4
tuesday=4
wednesday=1
thursday=4
friday=4
saturday=4
[Job 3]
StartHour=13
StartMinute=45
sunday=1
monday=4
tuesday=4
wednesday=4
thursday=4
friday=4
saturday=1

I am wondering what would be the best way to check the schedule .ini? Schedules may be down to the minute.

At the top of my While 1 Wend loop - loop through the sections checking day, then hour/minute and compare to system day/time?

How would I do this?

Edited by cyanidemonkey

My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You could try this:

#include <Date.au3>

While 1
    
    $jobs = IniReadSectionNames ("schedule.ini")

    ConsoleWrite($jobs[0] & " jobs found")

    For $X = 1 to $jobs[0]
        $currentDay = _DateDayOfWeek( @WDAY )
        
        $StartTime = IniRead ("schedule.ini", $jobs[$X], "StartTime", 4)
        
        ;Return 1 or 4, 1 = on, 4 = off (default)
        $run = Number(IniRead ("schedule.ini", $jobs[$X], $currentDay, 4))
        
        If $run = 1 AND _NowTime (4) = $StartTime Then
            ;Execute Job or add to a queue
        EndIf
    Next

    ;Sleep 1 minute
    Sleep(60000)
WEnd

This pulls all the jobs from the ini and loops through them every minute. You could execute a program directly from the line that says ;Execute Job but if you have any other jobs that need to start at the same time they will skip.

BTW - I changed the StartHour and StartMinute in the ini to just StartTime like HH:MM

EDIT: Now that I think about it, instead of looping this script every minute it may be better to read from the ini once, and add each job to the windows task scheduler (at.exe or schtasks.exe) with the specified times

Edited by weaponx

Share this post


Link to post
Share on other sites

I'm not sure how I can use the windows task scheduler to fire an event within my script. Maybe I was not very clear in my explaination.

I can't use the sleep(60000) due to the other stuff happening in the while 1 loop, but I'm sure I can put some kind of switch or timer in to the same effect.

Do you think there would be an advantage to read the ini into an array at the start of the day using @WDAY as a filter and then loop through the array once a minute?


My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites

To do it in AutoIt: Use AdLibEnable() to interrupt your script periodically and check on the tasks required. Use TimerInit/TimerDiff to control timing.

If you really want a task under Task Scheduler, use the SCHTASKS.EXE tool to set it up.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

To do it in AutoIt: Use AdLibEnable() to interrupt your script periodically and check on the tasks required. Use TimerInit/TimerDiff to control timing.

If you really want a task under Task Scheduler, use the SCHTASKS.EXE tool to set it up.

:)

Cool thanks, I see in the help file that AdLibEnable() will pause the script until it's job is done. Is there away I can call a function and have it do it's job while the main while 1 loop continues?

eg:

while 1
  if x = y then
     call function(do stuff independently)
  endif
  continue to do other stuff
  sleep(1)
wend

My concern is while there is not many jobs listed in the schedule.ini it will work fine but if there is lots of jobs it might take awhile to read through the file before it releases.


My AutoIt Scripts.- AutoHost and Password Enabler for Delta Force 2 Demo.| Caffine for Winamp 2.9x and WRS 2.0 | mp3 directory cleaner | CRAP DJ | A:B:J Radio Automation Software | FFMPEG batch conversion automator

Share this post


Link to post
Share on other sites

Cool thanks, I see in the help file that AdLibEnable() will pause the script until it's job is done. Is there away I can call a function and have it do it's job while the main while 1 loop continues?

eg:

while 1
  if x = y then
     call function(do stuff independently)
  endif
  continue to do other stuff
  sleep(1)
wend

My concern is while there is not many jobs listed in the schedule.ini it will work fine but if there is lots of jobs it might take awhile to read through the file before it releases.

The .ini file only needs to be read once into an array. It's a matter of looping through the array after that.

Still, AutoIt is not multi-threaded. So maybe the first instance of the script needs to spawn child processes with command line switches indicating which of the functions to perform. What method works best must depend on how many processes and how much time each process needs.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

i would suggest to use

ftp://ftp.microsoft.com/reskit/win2000/jt.zip

jt.exe from the windows 2000 resource kit

because it's much easier .. compatible with Windows 2000/XP/2003/Vista

Emiel

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Why did you resurrect this?

I looked at the syntax for jt.exe and it definitely wasn't easier than task scheduler.

http://www.jsifaq.com/SF/Tips/Tip.aspx?id=2621

If you find schtasks easier thats your opinion, i think jt.exe is much easier than schtasks.exe

Futher schtasks.exe is not compatible with Windows 95/98/ME .... (but who cares.. ) `

but maybe http://www.microsoft.com/downloads/details...;displaylang=en would be nicer to use.. or using the mstask.dll directly .. but to complex for me

<edit>

I don't know is Schtasks supports Hidden mode but JT does ..

with JT it is possible to schedule a task which will not be available to the users ..

</edit>

Edited by Emiel Wieldraaijer

Best regards,Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

I like to use System Scheduler from Splinterware. It's a lot more flexible that the standard Windows scheduler.

http://www.splinterware.com/products/wincron.htm

The basic version is free, the professional version is $30. I don't really need the features of the professional version, so I use the freebie.

It also has the ability to build macros, but with AutoIt, that feature is a bit redundant...

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