- NSIS Discussion
- Scheduled Task with Multiple Schedules?
Archive: Scheduled Task with Multiple Schedules?
Coolblu77
29th November 2007 14:29 UTC
Scheduled Task with Multiple Schedules?
I'm new to using NSIS.
I've found the plugin code for creating Scheduled Tasks (http://nsis.sourceforge.net/Scheduled_Tasks).
Is it possible to create one with multiple schedules?
i.e. start daily at 7:30 and run every 30 minutes (I've got this bit working), but also start at System Startup.
Thanks for any help.
kichik
29th November 2007 17:17 UTC
That should be possible if you duplicate the lines that create the trigger and modify them to add a different trigger. It starts with the CreateTrigger() call and ends in freeing the TASK_TRIGGER structures.
Coolblu77
30th November 2007 10:25 UTC
Thanks for your reply.
I've been trying to copy the lines that add the trigger.
; ITask->CreateTrigger(trindex, ITaskTrigger)
System::Call '$R2->3(*i .R4, *i .R5)'
; allocate TASK_TRIGGER structure
System::Call '$5' Pop $R6
; ITaskTrigger->SetTrigger
System::Call '$R5->3(i R6)'
; ITaskTrigger->Release
System::Call '$R5->2()'
; free TASK_TRIGGER structure
System::Free $R6
But as I said before I'm new to this and don't really know what I'm doing.
Where do I put the new trigger values?
I've been changing this line (on the 2nd copy):
; ITaskTrigger->SetTrigger
System::Call '$R5->3(i R6)'
to:
; ITaskTrigger->SetTrigger
System::Call '$R5->3(i "*(&l2, &i2 0, \
&i2 2007, &i2 1, &i2 1, \
&i2 0, &i2 0, &i2 0, \
&i2 7, &i2 1, \
i 0, \
i 0, \
i 0, \
i 6, \
i 0, &i2 0, i 0, &i2 0) i.s")'
What I'm trying to do is have 2 triggers. The 1st will run the task at a particular time at 30 minute intervals, which works fine.
This 2nd trigger should schedule the task to run at system startup, however instead its setting this trigger to run once at the current time.
Obviously I'm missing something, hopefully just some syntax, but possibly I'm doing it completely wrong.
Also I didn't like to push the 2nd trigger values in the same way as the first, because I think all those values are popped into registers, and all 10 are in use already (I think).
kichik
30th November 2007 12:29 UTC
According to MSDN, you only need to specify TASK_EVENT_TRIGGER_AT_SYSTEMSTART (== 6) in the trigger type field of the TASK_TRIGGER structure. It seems you've already done that but missed one field. The TriggerType field is fourth from the end. You've set the fifth field to 6.
As for the registers, you have 20 (you forgot $R0-$R9) by default and you can declare more using Var.
Coolblu77
30th November 2007 13:02 UTC
Thanks again for your reply.
I'm a little confused though, are you sure I've missed a field?
System::Call '$R5->3(i "*(&l2, &i2 0, \ ; skip
&i2 2007, &i2 1, &i2 1, \ ; Begin YY MM DD
&i2 0, &i2 0, &i2 0, \ ; End YY MM DD
&i2 7, &i2 1, \ ; Start HH MM
i 0, \ ; Duration
i 0, \ ; Interval
i 0, \ ; Flags
i 6, \ ; Trigger
i 0, &i2 0, i 0, &i2 0) i.s")' ; not sure about the last line,
I copied this from the example in the comments
As I understand it for this trigger the only parameters that might need a value are the start date and time, and of course the trigger.
Also I know I could define a variable, although I'm not sure about the scope of them and some syntax (need to read more tutorials), but thought it would be simplier to hard code this trigger, as every install will use this trigger, the other daily trigger might change start time from one user to another, so thats being pushed as in the example.
kichik
30th November 2007 13:08 UTC
There's some field confusion. You've one extra field in the end or some fields are mixed up. You said you wanted it be triggered on system start-up. For that, the fourth field from the end needs to be 6, not the fifth. I suggest you look for TASK_TRIGGER in MSDN and make sure every field is where it should be.
Coolblu77
4th December 2007 10:20 UTC
I've got it working.
I still don't understand what's needed for the last params, as far as I can tell if the TriggerType is 6 (or some others) then the next field the Type (TRIGGER_TYPE_UNION) is not required, then the next field is reserved so needs a 0, and the last field is not used.
However from my testing the only combination that seems to work, has "&i2 0, i 0, i 0, &i2 0" after the trigger type, this looks wrong, but works.
My main problem was that I was passing in a string instead of a pointer to a TASK_TRIGGER. I found this out by using some message boxes.
After trying to hard code the values directly, and copying to a var and pushing and popping them, I finally came across System::Call with a register name, this works fine.
So in case anyone else has problems with this, all I had to do was copy the section mentioned above, but replace Pop$R6 with
; put the trigger values into a buffer on R6
System::Call "*$R6(&l2, &i2 0, \
&i2 2003, &i2 9, &i2 4, \
&i2 0, &i2 0, &i2 0, \
&i2 7, &i2 01, \
i 0, i 0, \
i 0, \
i 6, \
&i2 0, i 0, i 0, &i2 0) i.s"