Page 1 of 1

Help with simple code example

Posted: Sun Jan 25, 2004 1:23 am
by mkinsel
I am a new registered user and bought the component for a simple task. I don't need a scheduling wizard, but want to be able to create (and later on, edit) a task that calls an external .EXE file once a week in the middle of the night (i.e. 1:00 AM) from within my Delphi app. Can someone send me a simple example of the above code? Thanks for the help ...

Mark

Posted: Mon Jan 26, 2004 11:04 am
by isiticov
The requested demo is available at:
http://www.sicomponents.com/soft/TaskSc ... unDemo.zip

Thanks for the help!

Posted: Thu Jan 29, 2004 4:18 am
by mkinsel
Thanks for the demo. I got my code built and it works great!

Mark

Example application

Posted: Tue Jul 27, 2004 5:38 pm
by mkinsel
The example application compiles file, but the Windows scheduler won't run it. It gives the status as "Could not start". I have tried with two applications of my own using your example and they have the same problem. One other point, in my applications, I want the scheduler to restart the calling application at the designated time.

Posted: Wed Jul 28, 2004 7:12 am
by isiticov
There could be one of the following reasons for this:
1. You've specified wrong account name and password
2. It is impossible to find the path to executable. In this example there is used TaskItem.ApplicationName := Application.ExeName; Please check that ApplicationName contains the FULL path to executable.

Hope this helps.

Simple example

Posted: Thu Jul 29, 2004 7:42 pm
by mkinsel
What account name and password should I use? The account and password for logging onto the computer at start up? There isn't one on this machine.

Mark

Posted: Mon Aug 02, 2004 6:27 am
by basil
Hello,

yes, if you run the task on Windows NT/2k/XP, then we recommend to use AccountName and Password, that are used to logon to Windows.

On Windows 9x the task does not need an account and password at all, just make sure the ApplicationName is specified properly.

Best regards

Simple example

Posted: Mon Aug 02, 2004 6:24 pm
by mkinsel
Is there an API / function call to get the Account Name and Password programmatically? It would make my life easier. I did do some testing and specifying the account name and password seemed to fix the problem. Thanks for the help ...

Mark

Posted: Tue Aug 03, 2004 6:45 am
by basil
Hello,

The Windows API function "GetUserName" retrieves the name of the user currently logged onto the system. This function might simplify setting the task paramaters a little but the password anyway should be typed by the user.

Another way is running task under "SYSTEM" account. In this case BOTH AccountName and Password should be empty and the task should NOT have the flag tfRunOnlyIfLoggedOn. Example:
...
if (Trim(Accnt) = EmptyStr) and (Trim(Pwd) = EmptyStr) then
FTask.Flags := FTask.Flags - [tfRunOnlyIfLoggedOn]
else
FTask.Flags := FTask.Flags + [tfRunOnlyIfLoggedOn];
FTask.SetAccountInformation(Trim(Accnt), Trim(Pwd));
...
Note, scheduling tasks under the "SYSTEM" account has some limitations. For example, a task running under SYSTEM does not allow interaction with the logged user (that is no message boxes, prompts, any dialogs).

System account

Posted: Thu Oct 21, 2004 3:06 am
by mkinsel
I'm still having problems getting my project to work. I am making an application that automatically sends a file as an attachment to an e-mail address. I want this file to be scheduled to be sent once a week. I have tried using the System account without any luck. When I manually try to use the system account in the XP task scheduler, it says my program is running with nothing showing on the screen or being sent. Unfortunately, I can't use the administrator account in Window XP since many people (including myself) don't remember the password they use with their login. Norton Antivirus seems to have found a way to use the administrator account without the user providing a password. Any suggestions on how to fix my problem?

Mark

Posted: Thu Oct 21, 2004 1:22 pm
by isiticov
There are 2 options:
1) use the SYSTEM account (empty accountname and password). In this case however, the application indeed does not show any dialogs. Therefore you will need to redesign your applcaition so it does not require any interaction with user.
2) You can use any account or create a special account for this task, but set the flag

Code: Select all

FTask.Flags := FTask.Flags - [tfRunOnlyIfLoggedOn];
Then the task will run when any user is logged on. However, if the task's account is different from the current user, the last one still won't be able to interact with program.
P.S. You tried to run a task under system account in the XP task scheduler and the email was not sent. It is possible that Norton Internet Secutity firewall just didn't allow the email sending.

System account

Posted: Thu Oct 21, 2004 5:51 pm
by mkinsel
I got my application running now with the System account; however, I have a problem with my button to edit the schedule using the TTaskPropertiesDialog component. My problem is that the changes made using the TTaskPropertiesDialog are not being saved / applied to the Windows Task Scheduler.

My onClick code for the Edit Schedule button is:

TaskDialog1.TaskName := 'MyName';
TaskDialog1.Execute;

Is the Execute method supposed to save the changes? What do I need to do differently?

System account

Posted: Fri Oct 22, 2004 2:55 pm
by mkinsel
Is there a way to set the Run As property / field in the Windows XP Task Scheduler programmatically with your components. To make the system account work, you need to specify the Run As field as "System".

Posted: Fri Oct 22, 2004 4:25 pm
by isiticov
Just add a call:
Task.Deactivate(True);

after

TaskDialog1.Execute;


Run As could be performed using SetAccountInformation() method.