Weekly Trigger Example (XML)

The XML in this example defines a task that starts Notepad on a bi-weekly basis.

To register a task that is defined in XML, you can use either the ITaskFolder::RegisterTask function (TaskFolder.RegisterTask for scripting) or the Schtasks.exe command-line tool. If you use the Schtasks.exe tool (located in the C:\Windows\System32 directory), then you can use the following command to register the task: schtasks /create /XML <path to the XML file containing the task definition> /tn <task name>.

To define a task to start Notepad every other week on Monday at 8:00 AM

The following XML example shows how to define a task with a single execution action (starting Notepad), a single calendar trigger (starts the task every other week on Monday at 8:00 AM), and several other task settings that affect how the task is handled by Task Scheduler.

<?xml version="1.0" ?>
This sample schedules a task to start on a bi-weekly basis.
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
        <Description>Notepad starts every other week on Monday at 8:00am.</Description>

TaskScheduler Schema Elements

Here are some important elements to keep in mind when using this example.

  • RegistrationInfo

    Contains registration information about the task.

  • Triggers

    Defines the trigger that starts the task.

  • CalendarTrigger

    Defines the weekly calendar trigger. In this case, only four child elements are used: the start and end boundaries that specify when the trigger is activated and deactivated, the weekly schedule, and the days of the week that the task will run on. The StartBoundary element is a required element for calendar triggers.

  • ScheduleByWeek

    Defines the weekly schedule. In this case, the interval is set to perform the task every other week on a Monday.

  • Principal

    Defines the security context that a task runs under.

  • Settings

    Defines the task settings that Task Scheduler uses to perform the task.

  • Actions

    Defines the actions the task performs (in this case, running Notepad).

Related topics

Using the Task Scheduler