This project has moved and is read-only. For the latest updates, please go here.

Task is created in WinXP but not in Win7

Jun 13, 2011 at 3:38 PM

Hi there,

I've developed a tool to create scheduled tasks with WinXP in mind, but ended up that when I needed to use it in Win7, I receive an error.

The exception message is: (47,4):EndBondary:, triggered when I call TaskService.RootFolder.RegisterTaskDefinition(string, TaskDefinition, TaskCreation, string, string, TaskLogonType, string).
I have to use that overload of RegisterTaskDefinition() since I need the created task to run under a specific username even when the user is not logged in.

I even tried to set Trigger.EndBoundary explicitly to DateTime.MaxValue, but the error persists.

As an additional information, the issue happens when either a WeeklyTrigger or DailyTrigger is used.

Using Microsoft.Win32.TaskScheduler.dll v.

Can anyone please help me with that? I have no idea what is going on.

Jun 13, 2011 at 7:29 PM

I think I will need to see more of your code to help troubleshoot. I personally have used the EndBoundary property of many different kinds of tasks under both XP and Win7 with success. Please create an issue and post your code that both creates the trigger and registers the task. If you are passing around a TaskDefinition, please also include that code in case there is a persistance error.

Jun 13, 2011 at 7:35 PM
Edited Jun 13, 2011 at 8:18 PM

Thanks for the answer, dahall. I added the issue as you suggested, but as for now I figured out a workaround. I simply set Trigger.EndBoundary = new DateTime(2099, 12, 31) and the problem is gone.

Not the most elegant solution, I know, specially because it can be visible in the scheduled task editor, but at least I can get it to work for now. Hopefully the scheduled task won't be necessary in 2100 :-)

Jun 13, 2011 at 9:37 PM

Under Win7, whenever you assign a value DeleteExpiredTaskAfter you must also assign a value to EndBoundary. I also noticed your use of Repetition.Duration without specifying Repetition.Interval. The DailyTrigger will already repeat each day based on the specified DaysInterval. I think that line may be extraneous. Also, if you only need to run the trigger once, just use the TimeTrigger. The following code works:

using (TaskService taskService = new TaskService())
   TaskDefinition task = taskService.NewTask();

   task.Triggers.Add(new DailyTrigger { EndBoundary = DateTime.Now + TimeSpan.FromDays(7) });
   task.Actions.Add(new ExecAction("notepad.exe", String.Empty, @"C:\Windows"));

   // Ensures the task is marked with 'delete the task if it is not scheduled to run again'
   task.Settings.DeleteExpiredTaskAfter = TimeSpan.FromMinutes(1);

   // We want that the task is executed under a specific user even when the user is not logged in
   taskService.RootFolder.RegisterTaskDefinition("Test Task", task, TaskCreation.CreateOrUpdate, "username", "password", TaskLogonType.Password, null);
Jun 14, 2011 at 3:18 PM

Setting Repetition.Duration is necessary to avoid the following exception in Windows XP: System.ArgumentException: Trigger.Repetition.Interval must be less than Trigger.Repetition.Duration under Task Scheduler 1.0.

Any ideas how to avoid that without setting Repetition.Duration only?

Jun 14, 2011 at 9:27 PM

You're right about that problem under V1 and version 1.6.1 of the library. It is corrected in the 1.6.2 release that is forthcoming. Under 1.6.1, your addition of that line is an appropriate work-around.