SiComponents Home Page SiComponents Forums
Here you will be able to get help and share your experience
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help with simple code example

 
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent
View previous topic :: View next topic  
Author Message
mkinsel



Joined: 25 Jan 2004
Posts: 8

PostPosted: Sun Jan 25, 2004 1:23 am    Post subject: Help with simple code example Reply with quote

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
View user's profile Send private message Send e-mail
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2102

PostPosted: Mon Jan 26, 2004 11:04 am    Post subject: Reply with quote

The requested demo is available at:
http://www.sicomponents.com/soft/TaskSchedulerRunDemo.zip
Back to top
View user's profile Send private message
mkinsel



Joined: 25 Jan 2004
Posts: 8

PostPosted: Thu Jan 29, 2004 4:18 am    Post subject: Thanks for the help! Reply with quote

Thanks for the demo. I got my code built and it works great!

Mark
Back to top
View user's profile Send private message Send e-mail
mkinsel



Joined: 25 Jan 2004
Posts: 8

PostPosted: Tue Jul 27, 2004 5:38 pm    Post subject: Example application Reply with quote

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
View user's profile Send private message Send e-mail
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2102

PostPosted: Wed Jul 28, 2004 7:12 am    Post subject: Reply with quote

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
View user's profile Send private message
mkinsel



Joined: 25 Jan 2004
Posts: 8

PostPosted: Thu Jul 29, 2004 7:42 pm    Post subject: Simple example Reply with quote

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
View user's profile Send private message Send e-mail
basil



Joined: 02 Aug 2004
Posts: 2

PostPosted: Mon Aug 02, 2004 6:27 am    Post subject: Reply with quote

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
View user's profile Send private message
mkinsel



Joined: 25 Jan 2004
Posts: 8

PostPosted: Mon Aug 02, 2004 6:24 pm    Post subject: Simple example Reply with quote

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
View user's profile Send private message Send e-mail
basil



Joined: 02 Aug 2004
Posts: 2

PostPosted: Tue Aug 03, 2004 6:45 am    Post subject: Reply with quote

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
View user's profile Send private message
mkinsel



Joined: 25 Jan 2004
Posts: 8

PostPosted: Thu Oct 21, 2004 3:06 am    Post subject: System account Reply with quote

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
View user's profile Send private message Send e-mail
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2102

PostPosted: Thu Oct 21, 2004 1:22 pm    Post subject: Reply with quote

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
View user's profile Send private message
mkinsel



Joined: 25 Jan 2004
Posts: 8

PostPosted: Thu Oct 21, 2004 5:51 pm    Post subject: System account Reply with quote

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
View user's profile Send private message Send e-mail
mkinsel



Joined: 25 Jan 2004
Posts: 8

PostPosted: Fri Oct 22, 2004 2:55 pm    Post subject: System account Reply with quote

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
View user's profile Send private message Send e-mail
isiticov
Site Admin


Joined: 21 Nov 2002
Posts: 2102

PostPosted: Fri Oct 22, 2004 4:25 pm    Post subject: Reply with quote

Just add a call:
Task.Deactivate(True);

after

TaskDialog1.Execute;


Run As could be performed using SetAccountInformation() method.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SiComponents Forums Forum Index -> VCL Scheduling Agent All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by p h p B B  © 2001, 2005 p h p B B  Group