query task.flags[]

This forum is designated to discuss SiComponents Scheduling Agent.
Post Reply
samh
Posts: 5
Joined: Mon Sep 12, 2005 8:14 pm
Location: Camarillo CA. USA
Contact:

query task.flags[]

Post by samh »

Hello,

1. How can I test the TaskItem.Flags to see if they aready include [tfDisabled]?

2. The snippet included below tirns on the scheduler but it also generates an ugly AV. Can you tell what I am doing wrong?

Thanks
Sam
=============================================

procedure Tmaxmain.AutomaticallyUploadBackup(
Sender: TObject);
var
Trigger: TTrigger;
Details: TTriggerDetails;
S,ulogin: string;
x:smallint;
begin
ulogin:='';
dialogs.InputQuery('Windows Login','Please Enter Login.',ulogin);
TaskItem := TaskScheduler1.ActivateTask('iNetBackup');
if TaskItem = nil then
try
TaskItem := TaskScheduler1.CreateNewItem('iNetBackup');
if (Trim(sysinfo1.Username) = EmptyStr) and (Trim(ulogin) = EmptyStr) then
TaskItem.Flags:=TaskItem.Flags - [tfRunOnlyIfLoggedOn]
else
TaskItem.Flags:=TaskItem.Flags + [tfRunOnlyIfLoggedOn];
TaskItem.ApplicationName :='c:\hunni\inetbkup.exe';
TaskItem.Parameters := '-runtask "' + 'c:\hunni\inetbkup.exe'+ '"';
TaskItem.SetAccountInformation(sysinfo1.Username,ulogin);
Trigger := TaskItem.Triggers.Add;
Trigger.TriggerType := ttAtStartup;
Trigger.BeginDate := Now;
TaskItem.Save;
finally
end
else
try
x:=-1;
repeat
inc(x);
until taskscheduler1.items[x].Name='iNetBackup';
taskitem:=taskscheduler1.items[x];
TaskItem.Flags := TaskItem.Flags - [tfDisabled];
TaskItem.Save;
finally
end;

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

Post by isiticov »

1. This code snippet inverts the tfDisabled flag:

Code: Select all

    if tfDisabled in TaskItem.Flags then
      TaskItem.Flags := TaskItem.Flags - [tfDisabled]
    else
      TaskItem.Flags := TaskItem.Flags + [tfDisabled];
2. If you specify at wich line you get AV error it would help. Anyway please find below the working sample. We've changed a little code by eliminating sysinfo1 reference, since we don't have it :)

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
var
  Trigger: TTrigger;
//  Details: TTriggerDetails;
//  S,ulogin: string;
//  x:smallint;
  TaskItem: TTaskItem;
begin
  TaskScheduler1.Open;
  TaskScheduler1.Refresh;
//  ulogin:='';
//  dialogs.InputQuery('Windows Login','Please Enter Login.',ulogin);
  TaskItem := TaskScheduler1.ActivateTask('iNetBackup');
  if TaskItem = nil then
  begin
    TaskItem := TaskScheduler1.CreateNewItem('iNetBackup');
//    if (Trim(sysinfo1.Username) = EmptyStr) and (Trim(ulogin) = EmptyStr) then
    TaskItem.Flags:=TaskItem.Flags - [tfRunOnlyIfLoggedOn];
//    else
//      TaskItem.Flags:=TaskItem.Flags + [tfRunOnlyIfLoggedOn];
    TaskItem.ApplicationName :='c:\hunni\inetbkup.exe';
    TaskItem.Parameters := '-runtask "' + 'c:\hunni\inetbkup.exe'+ '"';
    TaskItem.SetAccountInformation('', '');
    Trigger := TaskItem.Triggers.Add;
    Trigger.TriggerType := ttAtStartup;
    Trigger.BeginDate := Now;
    TaskItem.Save;
  end
  else
  begin
{    x:=-1;
    repeat
      inc(x);
    until taskscheduler1.items[x].Name='iNetBackup';
    taskitem:=taskscheduler1.items[x];}
    TaskItem.Activate;
    if tfDisabled in TaskItem.Flags then
      TaskItem.Flags := TaskItem.Flags - [tfDisabled]
    else
      TaskItem.Flags := TaskItem.Flags + [tfDisabled];
    TaskItem.Save;
  end;
end;
Hope this helps.
Best regards,
Igor Siticov.
samh
Posts: 5
Joined: Mon Sep 12, 2005 8:14 pm
Location: Camarillo CA. USA
Contact:

query flags[]

Post by samh »

Hello,

I used the code you suggested. It works much better but I am still getting the AV. The AV happens in the saTask.pas unit, in the finction GetWorkingDirectory, on the call to OLECheck. I was unable to debug into OLECheck. I get the AV EOLESYSTEM ERROR "Access is Denied".

Even with the AV , the code still sets the scheduler. There is another issue with the scheduler setting I would like to resolve: The run time is alwasy set to the time of day I enter the task into the scheduler. What I want is for the scheduler to start running the app immediately instead of waiting until a specific time of day.

My code is below.

Thnaks
Sam
===========================================
procedure Tmaxmain.Button1Click(
Sender: TObject);
var
Trigger:TTrigger;
TaskItem: TTaskItem;
begin
TaskScheduler1.Open;
TaskScheduler1.Refresh;
TaskItem := TaskScheduler1.ActivateTask('iNetBackup');
if TaskItem = nil then
begin
TaskItem := TaskScheduler1.CreateNewItem('iNetBackup');
TaskItem.Flags:=TaskItem.Flags - [tfRunOnlyIfLoggedOn];
TaskItem.ApplicationName :='c:\hunni\inetbkup.exe';
TaskItem.Parameters := '-runtask "' + 'c:\hunni\inetbkup.exe'+ '"';
TaskItem.SetAccountInformation('', '');
Trigger := TaskItem.Triggers.Add;
Trigger.TriggerType := ttAtStartup;
Trigger.BeginDate := Now;
TaskItem.Save;
end
else
begin
TaskItem.Activate;
if tfDisabled in TaskItem.Flags then
TaskItem.Flags := TaskItem.Flags - [tfDisabled];
TaskItem.Save;
end;
end;
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

You can use TaskItem.Run method to execute task immediately.

Hope this helps.
Best regards,
Igor Siticov.
samh
Posts: 5
Joined: Mon Sep 12, 2005 8:14 pm
Location: Camarillo CA. USA
Contact:

AV when setting scheduler

Post by samh »

Hello,

I was hoping to receive an answer about the AV as well as the time setting. I guess on the time setting I will need to set the start time to 6 AM since it appears the scheduler takes the time of task entry as the start time if no start time is stated.

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

Re: AV when setting scheduler

Post by isiticov »

samh wrote:I was hoping to receive an answer about the AV as well as the time setting. I guess on the time setting I will need to set the start time to 6 AM since it appears the scheduler takes the time of task entry as the start time if no start time is stated.
In the provided code there is no any call for WorkingDirectory property and it must execute without any problems. If you access to WorkingDirectory property in other place of code please note: it must be called only after saving or activating the task item, before that it will contain invalid data.
To set the start time you should use StartTime property, but in your :!: question you asked how to run task immediately, and the answer was provided.

Hope this helps.
Best regards,
Igor Siticov.
samh
Posts: 5
Joined: Mon Sep 12, 2005 8:14 pm
Location: Camarillo CA. USA
Contact:

AV

Post by samh »

Sorry to be a pest;

I have solved the AV issue. I added saTask.pas to my project and when I did I got an error that saDialogs was compiled with a different version of saTask. So I added saDialogs to my project (both from the source folder). This stopped the AV so I guess I was having some kind of conflict with holdover code from the demo mixing with code form the licensed product.

Now I still need to solve the starttime issue. I do not want a starttime. I want the app to start running as soon as the computer is booted. I am unable to get the schedule to NOT include a startime (which is always the time of day when the app was entered into the scheduler).

Once again I have included my code below.
Thanks
Sam
========================================
procedure Tbutton1click(Sender: TObject);
var
Trigger:TTrigger;
TaskItem: TTaskItem;
begin
TaskScheduler1.Open;
TaskScheduler1.Refresh;
TaskItem := TaskScheduler1.ActivateTask('iNetBackup');
if TaskItem = nil then
begin
TaskItem := TaskScheduler1.CreateNewItem('iNetBackup');
TaskItem.WorkingDirectory:='C:\Hunni';
TaskItem.Flags:=TaskItem.Flags - [tfRunOnlyIfLoggedOn];
TaskItem.ApplicationName :='c:\hunni\inetbkup.exe';
TaskItem.Parameters := '-runtask "' + 'c:\hunni\inetbkup.exe'+ '"';
TaskItem.SetAccountInformation('', '');
Trigger := TaskItem.Triggers.Add;
Trigger.TriggerType := ttAtStartup;
Trigger.BeginDate := Now;
TaskItem.Save;
end
else
begin
TaskItem.Activate;
if tfDisabled in TaskItem.Flags then
TaskItem.Flags := TaskItem.Flags - [tfDisabled];
TaskItem.Save;
end;
end;
isiticov
Site Admin
Posts: 2383
Joined: Thu Nov 21, 2002 3:17 pm

Post by isiticov »

....
TaskItem.SetAccountInformation('', '');
Trigger := TaskItem.Triggers.Add;
Trigger.TriggerType := ttAtStartup;
Trigger.BeginDate := Now;
Trigger.Enabled := True;
Trigger.UpdateTrigger;

TaskItem.Save;
.....

Please add lines in bold to your source. Ther origin: trigger needs to be enabled and you must call UpdateTrigger method after all settings are set.

or
TaskItem.Triggers.UpdateTriggers;
TaskItem.Save;


Hope this helps.
Best regards,
Igor Siticov.
samh
Posts: 5
Joined: Mon Sep 12, 2005 8:14 pm
Location: Camarillo CA. USA
Contact:

Got it

Post by samh »

Thanks for your help. I am now getting the exact results I purchased your product for.

Reagrds
Sam
Post Reply