Error: Task is not activated

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
jeffreysadler
Posts: 3
Joined: Tue Mar 23, 2010 1:30 am

Error: Task is not activated

Post by jeffreysadler »

Hi,

I am running the code below on Windows 7 (built using Delphi 7) but get the error "Task 'Maximus_20100420223644' is not activated." when trying to execute line
"Task.Flags := Task.Flags + [tfRunOnlyIfLoggedOn, tfDeleteWhenDone];". The code works fine on Windows XP but not Windows 7.

Do you know what I am doing wrong?

CoInitialize(nil);
TaskScheduler := nil;

TaskScheduler := TTaskScheduler.Create(nil);
TaskScheduler.Active := True;

Task := TaskScheduler.CreateNewItem('Maximus_' + DateTimeToMaximusDateTime);
Task.Triggers.Add(ttOnce);
Task.Triggers[0].StartTime := Time;
Task.Triggers[0].BeginDate := Date;
Task.Triggers[0].Enabled := true;
Task.Triggers.UpdateTriggers;

Task.ApplicationName := 'Blaa';
Task.WorkingDirectory := ExtractFilePath(BlaaFilename);
Task.Parameters := '';
Task.SetAccountInformation(FUsername, FPassword);
Task.Flags := Task.Flags + [tfRunOnlyIfLoggedOn, tfDeleteWhenDone];

Task.Save;
Task.Run;
finally
TaskScheduler.free;
CoUnInitialize;
end;

Thanks

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

Post by isiticov »

Hello,

Please use Task.VistaFlags property under Windows Vista and later and Task.Flags for earlier versions. To detect the running OS you can use:

Code: Select all

if (not Scheduler.RunningVistaOrLater) then...
Best regards,
Igor Siticov.
jeffreysadler
Posts: 3
Joined: Tue Mar 23, 2010 1:30 am

Post by jeffreysadler »

I tried your suggested changes and it now works.

Thank you.
Post Reply