View previous topic :: View next topic |
Author |
Message |
mkinsel
Joined: 25 Jan 2004 Posts: 8
|
Posted: Sun Jan 25, 2004 1:23 am Post subject: Help with simple code example |
|
|
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 |
|
Back to top |
|
 |
isiticov Site Admin
Joined: 21 Nov 2002 Posts: 2129
|
|
Back to top |
|
 |
mkinsel
Joined: 25 Jan 2004 Posts: 8
|
Posted: Thu Jan 29, 2004 4:18 am Post subject: Thanks for the help! |
|
|
Thanks for the demo. I got my code built and it works great!
Mark |
|
Back to top |
|
 |
mkinsel
Joined: 25 Jan 2004 Posts: 8
|
Posted: Tue Jul 27, 2004 5:38 pm Post subject: Example application |
|
|
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. |
|
Back to top |
|
 |
isiticov Site Admin
Joined: 21 Nov 2002 Posts: 2129
|
Posted: Wed Jul 28, 2004 7:12 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
mkinsel
Joined: 25 Jan 2004 Posts: 8
|
Posted: Thu Jul 29, 2004 7:42 pm Post subject: Simple example |
|
|
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 |
|
Back to top |
|
 |
basil
Joined: 02 Aug 2004 Posts: 2
|
Posted: Mon Aug 02, 2004 6:27 am Post subject: |
|
|
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 |
|
Back to top |
|
 |
mkinsel
Joined: 25 Jan 2004 Posts: 8
|
Posted: Mon Aug 02, 2004 6:24 pm Post subject: Simple example |
|
|
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 |
|
Back to top |
|
 |
basil
Joined: 02 Aug 2004 Posts: 2
|
Posted: Tue Aug 03, 2004 6:45 am Post subject: |
|
|
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). |
|
Back to top |
|
 |
mkinsel
Joined: 25 Jan 2004 Posts: 8
|
Posted: Thu Oct 21, 2004 3:06 am Post subject: System account |
|
|
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 |
|
Back to top |
|
 |
isiticov Site Admin
Joined: 21 Nov 2002 Posts: 2129
|
Posted: Thu Oct 21, 2004 1:22 pm Post subject: |
|
|
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: | 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. |
|
Back to top |
|
 |
mkinsel
Joined: 25 Jan 2004 Posts: 8
|
Posted: Thu Oct 21, 2004 5:51 pm Post subject: System account |
|
|
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? |
|
Back to top |
|
 |
mkinsel
Joined: 25 Jan 2004 Posts: 8
|
Posted: Fri Oct 22, 2004 2:55 pm Post subject: System account |
|
|
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". |
|
Back to top |
|
 |
isiticov Site Admin
Joined: 21 Nov 2002 Posts: 2129
|
Posted: Fri Oct 22, 2004 4:25 pm Post subject: |
|
|
Just add a call:
Task.Deactivate(True);
after
TaskDialog1.Execute;
Run As could be performed using SetAccountInformation() method. |
|
Back to top |
|
 |
|