Message Box Example (XML)

The XML in this example defines a task that shows a message box when an event occurs.

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 schedule a task to show a message box when an event occurs

The following XML example shows how to define a task with a message box action, an event trigger that starts the task when a specified event is received, and several other task settings that affect how the task is handled by the Task Scheduler service.

<?xml version="1.0" ?>
This sample schedules a task to show a message box when an event occurs.
<Task xmlns="">
        <Description>Task shows a message box when an event occurs.</Description>
                    &lt;Query Id='1'&gt;
                        &lt;Select Path='System'&gt;*[System/Level=4]&lt;/Select&gt;
                <Value name="eventID">Event/System/EventRecordID</Value>
            <Title>Message Box Title</Title>
            <Body>A level 4 event occurred: $(eventID)</Body>

TaskScheduler Schema Elements

The following list includes important elements to be aware of when using this example:

  • RegistrationInfo: Contains registration information about the task.
  • Triggers: Defines the trigger that starts the task.
  • EventTrigger: Defines the event trigger. In this case, five child elements are used: the start and end boundaries that specify when the trigger is activated and deactivated, the execution time limit that specifies the maximum amount of time in which the task can be started by the trigger, the event subscription query, and the <ValueQueries> element. The event subscription queries for level four events from the System event log. For information about how to create an event query, see Event Selection.
  • Principal: Defines the security context that a task runs under.
  • Settings: Defines the task settings that the Task Scheduler uses to perform the task.
  • Actions: Defines the actions that the task performs. The task example above contains a message box action. For more information, see showMessageType Complex Type.

Related topics

Using the Task Scheduler



Send comments about this topic to Microsoft

Build date: 10/16/2012

Community Additions