Task won't run

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
Vertuas
Posts: 2
Joined: Tue Sep 18, 2007 1:01 pm

Task won't run

Post by Vertuas »

Hello

I am trying to get my application to create/update a task in the scheduler, to run at a user set time of the day.

However, my task never runs and task Scheduler reports "Could not start".

My schedule procedure follows, and is mostly copied from the help file.

Can anyone see what I have done wrong?

Thanks

Vert


/*==============Code below======================*/

procedure SetSched(hour, minutes: integer);
var n : integer;
task : ttaskitem;
ST : TSystemTime;
trigger : ttrigger;
triggerdetails : ttriggerdetails;
taskscheduler1: ttaskscheduler;
begin
taskscheduler1:=ttaskscheduler.create(nil);
try
task:=nil;
taskscheduler1.Open;
taskscheduler1.Refresh;

for n:=0 to taskscheduler1.Count-1 do
begin
if taskscheduler1.Items[n].name='Notepad' then
begin
task:=taskscheduler1.Items[n];
task.Activate;
task.Triggers.clear;
end;
end;

if task=nil then
begin
task:=TaskScheduler1.CreateNewItem('Notepad');
end;

if task=nil then exit;

with task do
begin

ApplicationName:='c:\windows\system32\notepad.exe';
Flags:=[tfRunOnlyIfLoggedOn];

DateTimeToSystemTime(now, ST);
ST.wMinute:=minutes;
ST.wSecond:=0;
ST.wMilliseconds:=0;
ST.wHour:=Hour;
Trigger:=task.Triggers.Add;
Trigger.triggertype:=ttDaily;
Trigger.BeginDate:=date;
Trigger.StartTime:=SystemTimeToDateTime(ST);

TriggerDetails.Daily.DaysInterval:=1;

Trigger.Details:=TriggerDetails;

Triggers.UpdateTriggers;

Save;
end;
taskscheduler1.close;
finally
taskscheduler1.free;
end;

end;
Vertuas
Posts: 2
Joined: Tue Sep 18, 2007 1:01 pm

Additionally

Post by Vertuas »

Just been experimenting.

If i select run from the scheduler i get the same error message.

If i then open th task, change something (i deleted the e from the end of .exe, re typed it, then clicked ok), then try and run the task, it then runs.

I suspect i have missed a setting that windows is updating for me.

Thanks

Vert
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

Hello,

I can suppose that you need to set user name and password for task using SetAccountInformation() method.
Best regards,
Igor Siticov.
Post Reply