Share via


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="https://schemas.microsoft.com/windows/2004/02/mit/task">
    <RegistrationInfo>
        <Date>2006-05-02T13:21:17</Date>
        <Author>AuthorName</Author>
        <Version>1.0.0</Version>
        <Description>Task shows a message box when an event occurs.</Description>
    </RegistrationInfo>
    <Triggers>
        <EventTrigger>
            <StartBoundary>2006-02-13T10:14:00</StartBoundary>
            <EndBoundary>2007-05-02T13:20:00</EndBoundary>
            <ExecutionTimeLimit>PT5M</ExecutionTimeLimit>
            <Subscription>
                &lt;QueryList&gt; 
                    &lt;Query Id='1'&gt;
                        &lt;Select Path='System'&gt;*[System/Level=4]&lt;/Select&gt;
                    &lt;/Query&gt;
                &lt;/QueryList&gt;
            </Subscription>
            <ValueQueries>
                <Value name="eventID">Event/System/EventRecordID</Value>
            </ValueQueries>                
        </EventTrigger>
    </Triggers>
    <Principals>
        <Principal>
            <UserId>Administrator</UserId>
            <LogonType>InteractiveToken</LogonType>
        </Principal>
    </Principals>
    <Settings>
        <Enabled>true</Enabled>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <AllowHardTerminate>true</AllowHardTerminate>
    </Settings>
    <Actions>
        <ShowMessage>
            <Title>Message Box Title</Title>
            <Body>A level 4 event occurred: $(eventID)</Body>
        </ShowMessage>
    </Actions>
</Task>

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.

Using the Task Scheduler

 

 

Send comments about this topic to Microsoft

Build date: 10/16/2012