0% found this document useful (0 votes)
267 views860 pages

e76a889dc5feb1779e32e683ae606d3b

Uploaded by

Ali Esam Dabes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
267 views860 pages

e76a889dc5feb1779e32e683ae606d3b

Uploaded by

Ali Esam Dabes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 860

Contents

Task Scheduler
What's new in Task Scheduler
About the Task Scheduler
Tasks
Task Actions
Task Triggers
Trigger Types
Trigger Interfaces
Task Scheduler 1.0 Triggers
Trigger Structures for Task Scheduler 1.0
Idle Triggers for Task Scheduler 1.0
Task Registration Information
Task Idle Conditions
Security Contexts for Tasks
Task Security Hardening
Repeating A Task
Automatic Maintenance
Task Scheduler 1.0 Task Information
Programming Considerations
Enumerating Tasks
Scheduled Work Items
Adding Work Items
Managing Work Items
Using the Task Scheduler
Starting an Executable at a Specific Time
Time Trigger Example (Scripting)
Time Trigger Example (C++)
Time Trigger Example (XML)
Starting an Executable Daily
Daily Trigger Example (Scripting)
Daily Trigger Example (C++)
Daily Trigger Example (XML)
Starting an Executable When a Task is Registered
Registration Trigger Example (Scripting)
Registration Trigger Example (C++)
Registration Trigger Example (XML)
Starting an Executable Weekly
Weekly Trigger Example (Scripting)
Weekly Trigger Example (C++)
Weekly Trigger Example (XML)
Starting an Executable When a User Logs On
Logon Trigger Example (Scripting)
Logon Trigger Example (C++)
Logon Trigger Example (XML)
Starting an Executable on System Boot
Boot Trigger Example (Scripting)
Boot Trigger Example (C++)
Boot Trigger Example (XML)
Enumerating Tasks and Displaying Task Information
Displaying Task Names and States (Scripting)
Displaying Task Names and States (C++)
Task Scheduler 1.0 Examples
Creating a Task Using NewWorkItem Example
C/C++ Code Example: Creating a Task Using NewWorkItem
Enumerating Tasks Example
C/C++ Code Example: Enumerating Tasks
Starting a Task Example
C/C++ Code Example: Starting a Task
Editing a Work Item using Property Pages
C/C++ Code Example: Editing a Work Item
Retrieving Work Item Property Examples
C/C++ Code Example: Retrieving Task Account Information
C/C++ Code Example: Retrieving a Task Comment
C/C++ Code Example: Retrieving the Task Creator
C/C++ Code Example: Retrieving Task Exit Code
C/C++ Code Example: Retrieving Task Idle-wait Time
C/C++ Code Example: Retrieving the Task MostRecentRun Time
C/C++ Code Example: Retrieving the Task NextRun Time
C/C++ Code Example: Retrieving Task Run Times
C/C++ Code Example: Retrieving Task Status
Setting Work Item Property Examples
C/C++ Code Example: Setting Task Account Information
C/C++ Code Example: Setting Task Comment
Retrieving Task Property Examples
C/C++ Code Example: Retrieving the Task Application Name
C/C++ Code Example: Retrieving the Task MaxRunTime
C/C++ Code Example: Retrieving Task Parameters
C/C++ Code Example: Retrieving the Task Priority
C/C++ Code Example: Retrieving the Task Working Directory
Setting Task Property Examples
C/C++ Code Example: Setting Application Name
C/C++ Code Example: Setting MaxRunTime
C/C++ Code Example: Setting Task Parameters
C/C++ Code Example: Setting Task Priority
C/C++ Code Example: Setting Working Directory
Retrieving a Task Page Example
C/C++ Code Example: Retrieving a Task Page
Creating a New Trigger
C/C++ Code Example: Creating a Task Trigger
Creating an Idle Trigger Example
C/C++ Code Example: Creating an Idle Trigger
Terminating a Task Example
C/C++ Code Example: Terminating a Task
Retrieving Trigger Strings Example
C/C++ Code Example: Retrieving Trigger Strings
Task Scheduler Reference
Task Scheduler Scripting Objects
Action
Action.Id
Action.Type
ActionCollection
ActionCollection.Context
ActionCollection.Count
ActionCollection.Item
ActionCollection.XmlText
ActionCollection.Clear
ActionCollection.Create
ActionCollection.Remove
BootTrigger
BootTrigger.Delay
ComHandlerAction
ComHandlerAction.ClassId
ComHandlerAction.Data
DailyTrigger
DailyTrigger.DaysInterval
DailyTrigger.RandomDelay
EmailAction
EmailAction.Attachments
EmailAction.Bcc
EmailAction.Body
EmailAction.Cc
EmailAction.From
EmailAction.HeaderFields
EmailAction.ReplyTo
EmailAction.Server
EmailAction.Subject
EmailAction.To
EventTrigger
EventTrigger.Delay
EventTrigger.Subscription
EventTrigger.ValueQueries
ExecAction
ExecAction.Arguments
ExecAction.Path
ExecAction.WorkingDirectory
IdleSettings
IdleSettings.IdleDuration
IdleSettings.RestartOnIdle
IdleSettings.StopOnIdleEnd
IdleSettings.WaitTimeout
IdleTrigger
LogonTrigger
LogonTrigger.Delay
LogonTrigger.UserId
MonthlyDOWTrigger
MonthlyDOWTrigger.DaysOfWeek
MonthlyDOWTrigger.MonthsOfYear
MonthlyDOWTrigger.RandomDelay
MonthlyDOWTrigger.RunOnLastWeekOfMonth
MonthlyDOWTrigger.WeeksOfMonth
MonthlyTrigger
MonthlyTrigger.DaysOfMonth
MonthlyTrigger.MonthsOfYear
MonthlyTrigger.RandomDelay
MonthlyTrigger.RunOnLastDayOfMonth
NetworkSettings
NetworkSettings.Id
NetworkSettings.Name
Principal
Principal.DisplayName
Principal.GroupId
Principal.Id
Principal.LogonType
Principal.UserId
Principal.RunLevel
RegisteredTask
RegisteredTask.Definition
RegisteredTask.Enabled
RegisteredTask.LastRunTime
RegisteredTask.LastTaskResult
RegisteredTask.Name
RegisteredTask.NextRunTime
RegisteredTask.NumberOfMissedRuns
RegisteredTask.Path
RegisteredTask.State
RegisteredTask.XML
RegisteredTask.GetInstances
RegisteredTask.GetRunTimes
RegisteredTask.GetSecurityDescriptor
RegisteredTask.Run
RegisteredTask.RunEx
RegisteredTask.SetSecurityDescriptor
RegisteredTask.Stop
RegisteredTaskCollection
RegisteredTaskCollection.Count
RegisteredTaskCollection.Item
RegistrationInfo
RegistrationInfo.Author
RegistrationInfo.Date
RegistrationInfo.Description
RegistrationInfo.Documentation
RegistrationInfo.SecurityDescriptor
RegistrationInfo.Source
RegistrationInfo.URI
RegistrationInfo.Version
RegistrationInfo.XmlText
RegistrationTrigger
RegistrationTrigger.Delay
RepetitionPattern
RepetitionPattern.Duration
RepetitionPattern.Interval
RepetitionPattern.StopAtDurationEnd
RunningTask
RunningTask.CurrentAction
RunningTask.EnginePID
RunningTask.InstanceGuid
RunningTask.Name
RunningTask.Path
RunningTask.State
RunningTask.Refresh
RunningTask.Stop
RunningTaskCollection
RunningTaskCollection.Count
RunningTaskCollection.Item
SessionStateChangeTrigger
SessionStateChangeTrigger.Delay
SessionStateChangeTrigger.StateChange
SessionStateChangeTrigger.UserId
ShowMessageAction
ShowMessageAction.MessageBody
ShowMessageAction.Title
TaskDefinition
TaskDefinition.Actions
TaskDefinition.Data
TaskDefinition.Principal
TaskDefinition.RegistrationInfo
TaskDefinition.Settings
TaskDefinition.Triggers
TaskDefinition.XmlText
TaskFolder
TaskFolder.CreateFolder
TaskFolder.DeleteFolder
TaskFolder.DeleteTask
TaskFolder.GetFolder
TaskFolder.GetFolders
TaskFolder.GetSecurityDescriptor
TaskFolder.GetTask
TaskFolder.GetTasks
TaskFolder.Name
TaskFolder.Path
TaskFolder.RegisterTask
TaskFolder.RegisterTaskDefinition
TaskFolder.SetSecurityDescriptor
TaskFolderCollection
TaskFolderCollection.Count
TaskFolderCollection.Item
TaskNamedValueCollection
TaskNamedValueCollection.Clear
TaskNamedValueCollection.Count
TaskNamedValueCollection.Create
TaskNamedValueCollection.Item
TaskNamedValueCollection.Remove
TaskNamedValuePair
TaskNamedValuePair.Name
TaskNamedValuePair.Value
TaskService
TaskService.Connect
TaskService.Connected
TaskService.ConnectedDomain
TaskService.ConnectedUser
TaskService.GetFolder
TaskService.GetRunningTasks
TaskService.HighestVersion
TaskService.NewTask
TaskService.TargetServer
TaskSettings
TaskSettings.AllowDemandStart
TaskSettings.AllowHardTerminate
TaskSettings.Compatibility
TaskSettings.DeleteExpiredTaskAfter
TaskSettings.DisallowStartIfOnBatteries
TaskSettings.Enabled
TaskSettings.ExecutionTimeLimit
TaskSettings.Hidden
TaskSettings.IdleSettings
TaskSettings.MultipleInstances
TaskSettings.NetworkSettings
TaskSettings.Priority
TaskSettings.RestartCount
TaskSettings.RestartInterval
TaskSettings.RunOnlyIfIdle
TaskSettings.RunOnlyIfNetworkAvailable
TaskSettings.StartWhenAvailable
TaskSettings.StopIfGoingOnBatteries
TaskSettings.WakeToRun
TaskSettings.XmlText
TaskVariables
TaskVariables.GetContext
TaskVariables.GetInput
TaskVariables.SetOutput
TimeTrigger
TimeTrigger.RandomDelay
Trigger
Trigger.Enabled
Trigger.EndBoundary
Trigger.ExecutionTimeLimit
Trigger.Id
Trigger.Repetition
Trigger.StartBoundary
Trigger.Type
TriggerCollection
TriggerCollection.Count
TriggerCollection.Item
TriggerCollection.Clear
TriggerCollection.Create
TriggerCollection.Remove
WeeklyTrigger
WeeklyTrigger.DaysOfWeek
WeeklyTrigger.RandomDelay
WeeklyTrigger.WeeksInterval
Task Scheduler Interfaces
Task Scheduler 1.0 Interfaces
IEnumWorkItems
IEnumWorkItems::Clone
IEnumWorkItems::Next
IEnumWorkItems::Reset
IEnumWorkItems::Skip
IProvideTaskPage
IProvideTaskPage::GetPage
IScheduledWorkItem
IScheduledWorkItem::CreateTrigger
IScheduledWorkItem::DeleteTrigger
IScheduledWorkItem::EditWorkItem
IScheduledWorkItem::GetAccountInformation
IScheduledWorkItem::GetComment
IScheduledWorkItem::GetCreator
IScheduledWorkItem::GetErrorRetryCount
IScheduledWorkItem::GetErrorRetryInterval
IScheduledWorkItem::GetExitCode
IScheduledWorkItem::GetFlags
IScheduledWorkItem::GetIdleWait
IScheduledWorkItem::GetMostRecentRunTime
IScheduledWorkItem::GetNextRunTime
IScheduledWorkItem::GetRunTimes
IScheduledWorkItem::GetStatus
IScheduledWorkItem::GetTrigger
IScheduledWorkItem::GetTriggerCount
IScheduledWorkItem::GetTriggerString
IScheduledWorkItem::GetWorkItemData
IScheduledWorkItem::Run
IScheduledWorkItem::SetAccountInformation
IScheduledWorkItem::SetComment
IScheduledWorkItem::SetCreator
IScheduledWorkItem::SetErrorRetryCount
IScheduledWorkItem::SetErrorRetryInterval
IScheduledWorkItem::SetFlags
IScheduledWorkItem::SetIdleWait
IScheduledWorkItem::SetWorkItemData
IScheduledWorkItem::Terminate
ITask
ITask::GetApplicationName
ITask::GetMaxRunTime
ITask::GetParameters
ITask::GetPriority
ITask::GetTaskFlags
ITask::GetWorkingDirectory
ITask::SetApplicationName
ITask::SetMaxRunTime
ITask::SetParameters
ITask::SetPriority
ITask::SetTaskFlags
ITask::SetWorkingDirectory
ITaskScheduler
ITaskScheduler::Activate
ITaskScheduler::AddWorkItem
ITaskScheduler::Delete
ITaskScheduler::Enum
ITaskScheduler::GetTargetComputer
ITaskScheduler::IsOfType
ITaskScheduler::NewWorkItem
ITaskScheduler::SetTargetComputer
ITaskTrigger
ITaskTrigger::GetTrigger
ITaskTrigger::GetTriggerString
ITaskTrigger::SetTrigger
Task Scheduler 2.0 Interfaces
IAction
Id Property of IAction
Type Property of IAction
IActionCollection
Context Property of IActionCollection
Count Property of IActionCollection
Item Property of IActionCollection
XmlText Property of IActionCollection
_NewEnum Property of IActionCollection
IActionCollection::Clear
IActionCollection::Create
IActionCollection::Remove
IBootTrigger
Delay Property of IBootTrigger
IComHandlerAction
ClassId Property of IComHandlerAction
Data Property of IComHandlerAction
IDailyTrigger
DaysInterval Property of IDailyTrigger
RandomDelay Property of IDailyTrigger
IEmailAction
Attachments Property of IEmailAction
Bcc Property of IEmailAction
Body Property of IEmailAction
Cc Property of IEmailAction
From Property of IEmailAction
HeaderFields Property of IEmailAction
ReplyTo Property of IEmailAction
Server Property of IEmailAction
Subject Property of IEmailAction
To Property of IEmailAction
IEventTrigger
Delay Property of IEventTrigger
Subscription Property of IEventTrigger
ValueQueries Property of IEventTrigger
IExecAction
Arguments Property of IExecAction
Path Property of IExecAction
WorkingDirectory Property of IExecAction
IIdleSettings
IdleDuration Property of IIdleSettings
RestartOnIdle Property of IIdleSettings
StopOnIdleEnd Property of IIdleSettings
WaitTimeout Property of IIdleSettings
IIdleTrigger
ILogonTrigger
Delay Property of ILogonTrigger
UserId Property of ILogonTrigger
IMaintenanceSettings
Deadline property
Exclusive property
Period property
IMonthlyDOWTrigger
DaysOfWeek Property of IMonthlyDOWTrigger
MonthsOfYear Property of IMonthlyDOWTrigger
RandomDelay Property of IMonthlyDOWTrigger
RunOnLastWeekOfMonth Property of IMonthlyDOWTrigger
WeeksOfMonth Property of IMonthlyDOWTrigger
IMonthlyTrigger
DaysOfMonth Property of IMonthlyTrigger
MonthsOfYear Property of IMonthlyTrigger
RandomDelay Property of IMonthlyTrigger
RunOnLastDayOfMonth Property of IMonthlyTrigger
INetworkSettings
Id Property of INetworkSettings
Name Property of INetworkSettings
IPrincipal
DisplayName Property of IPrincipal
GroupId Property of IPrincipal
Id Property of IPrincipal
LogonType Property of IPrincipal
UserId Property of IPrincipal
RunLevel Property of IPrincipal
IPrincipal2
AddRequiredPrivilege Method
ProcessTokenSidType Property
RequiredPrivilege Property
RequiredPrivilegeCount Property
IRegisteredTask
Definition Property of IRegisteredTask
Enabled Property of IRegisteredTask
LastRunTime Property of IRegisteredTask
LastTaskResult Property of IRegisteredTask
Name Property of IRegisteredTask
NextRunTime Property of IRegisteredTask
NumberOfMissedRuns Property of IRegisteredTask
Path Property of IRegisteredTask
State Property of IRegisteredTask
XML Property of IRegisteredTask
IRegisteredTask::GetInstances
IRegisteredTask::GetRunTimes
IRegisteredTask::GetSecurityDescriptor
IRegisteredTask::Run
IRegisteredTask::RunEx
IRegisteredTask::SetSecurityDescriptor
IRegisteredTask::Stop
IRegisteredTaskCollection
Count Property of IRegisteredTaskCollection
Item Property of IRegisteredTaskCollection
_NewEnum Property of IRegisteredTaskCollection
IRegistrationInfo
Author Property of IRegistrationInfo
Date Property of IRegistrationInfo
Description Property of IRegistrationInfo
Documentation Property of IRegistrationInfo
SecurityDescriptor Property of IRegistrationInfo
Source Property of IRegistrationInfo
URI Property of IRegistrationInfo
Version Property of IRegistrationInfo
XmlText Property of IRegistrationInfo
IRegistrationTrigger
Delay Property of IRegistrationTrigger
IRepetitionPattern
Duration Property of IRepetitionPattern
Interval Property of IRepetitionPattern
StopAtDurationEnd Property of IRepetitionPattern
IRunningTask
CurrentAction Property of IRunningTask
EnginePID Property of IRunningTask
InstanceGuid Property of IRunningTask
Name Property of IRunningTask
Path Property of IRunningTask
State Property of IRunningTask
IRunningTask::Refresh
IRunningTask::Stop
IRunningTaskCollection
Count Property of IRunningTaskCollection
Item Property of IRunningTaskCollection
_NewEnum Property of IRunningTaskCollection
ISessionStateChangeTrigger
Delay Property of ISessionStateChangeTrigger
StateChange Property of ISessionStateChangeTrigger
UserId Property of ISessionStateChangeTrigger
IShowMessageAction
MessageBody Property of IShowMessageAction
Title Property of IShowMessageAction
ITaskDefinition
Actions Property of ITaskDefinition
Data Property of ITaskDefinition
Principal Property of ITaskDefinition
RegistrationInfo Property of ITaskDefinition
Settings Property of ITaskDefinition
Triggers Property of ITaskDefinition
XmlText Property of ITaskDefinition
ITaskFolder
Name Property of ITaskFolder
Path Property of ITaskFolder
ITaskFolder::CreateFolder
ITaskFolder::DeleteFolder
ITaskFolder::DeleteTask
ITaskFolder::GetFolder
ITaskFolder::GetFolders
ITaskFolder::GetSecurityDescriptor
ITaskFolder::GetTask
ITaskFolder::GetTasks
ITaskFolder::RegisterTask
ITaskFolder::RegisterTaskDefinition
ITaskFolder::SetSecurityDescriptor
ITaskFolderCollection
Count Property of ITaskFolderCollection
Item Property of ITaskFolderCollection
_NewEnum Property of ITaskFolderCollection
ITaskHandler
ITaskHandler::Pause
ITaskHandler::Resume
ITaskHandler::Start
ITaskHandler::Stop
ITaskHandlerStatus
ITaskHandlerStatus::UpdateStatus
ITaskHandlerStatus::TaskCompleted
ITaskNamedValueCollection
Count Property of ITaskNamedValueCollection
Item Property of ITaskNamedValueCollection
_NewEnum Property of ITaskNamedValueCollection
ITaskNamedValueCollection::Clear
ITaskNamedValueCollection::Create
ITaskNamedValueCollection::Remove
ITaskNamedValuePair
Name Property of ITaskNamedValuePair
Value Property of ITaskNamedValuePair
ITaskService
Connected Property of ITaskService
ConnectedDomain Property of ITaskService
ConnectedUser Property of ITaskService
HighestVersion Property of ITaskService
TargetServer Property of ITaskService
ITaskService::Connect
ITaskService::GetFolder
ITaskService::GetRunningTasks
ITaskService::NewTask
ITaskSettings
AllowDemandStart Property of ITaskSettings
AllowHardTerminate Property of ITaskSettings
Compatibility Property of ITaskSettings
DeleteExpiredTaskAfter Property of ITaskSettings
DisallowStartIfOnBatteries Property of ITaskSettings
Enabled Property of ITaskSettings
ExecutionTimeLimit Property of ITaskSettings
Hidden Property of ITaskSettings
IdleSettings Property of ITaskSettings
MultipleInstances Property of ITaskSettings
NetworkSettings Property of ITaskSettings
Priority Property of ITaskSettings
RestartCount Property of ITaskSettings
RestartInterval Property of ITaskSettings
RunOnlyIfIdle Property of ITaskSettings
RunOnlyIfNetworkAvailable Property of ITaskSettings
StartWhenAvailable Property of ITaskSettings
StopIfGoingOnBatteries Property of ITaskSettings
WakeToRun Property of ITaskSettings
XmlText Property of ITaskSettings
ITaskSettings2
DisallowStartOnRemoteAppSession Property
UseUnifiedSchedulingEngine Property
ITaskSettings3
CreateMantenanceSettings method
MaintenanceSettings property
Volatile property
ITaskVariables
ITaskVariables::GetContext
ITaskVariables::GetInput
ITaskVariables::SetOutput
ITimeTrigger
RandomDelay Property of ITimeTrigger
ITrigger
Enabled Property of ITrigger
EndBoundary Property of ITrigger
ExecutionTimeLimit Property of ITrigger
Id Property of ITrigger
Repetition Property of ITrigger
StartBoundary Property of ITrigger
Type Property of ITrigger
ITriggerCollection
Count Property of ITriggerCollection
Item Property of ITriggerCollection
_NewEnum Property of ITriggerCollection
ITriggerCollection::Clear
ITriggerCollection::Create
ITriggerCollection::Remove
IWeeklyTrigger
DaysOfWeek Property of IWeeklyTrigger
RandomDelay Property of IWeeklyTrigger
WeeksInterval Property of IWeeklyTrigger
Task Scheduler Structures and Unions
DAILY
MONTHLYDATE
MONTHLYDOW
TASK_TRIGGER
TRIGGER_TYPE_UNION
WEEKLY
Task Scheduler Enumerated Types
Task Scheduler 1.0 Enumerated Types
TASK_TRIGGER_TYPE
TASKPAGE
Task Scheduler 2.0 Enumerated Types
TASK_ACTION_TYPE
TASK_COMPATIBILITY
TASK_CREATION
TASK_ENUM_FLAGS
TASK_INSTANCES_POLICY
TASK_LOGON_TYPE
TASK_PROCESSTOKENSID_TYPE
TASK_RUNLEVEL_TYPE
TASK_RUN_FLAGS
TASK_SESSION_STATE_CHANGE_TYPE
TASK_STATE
TASK_TRIGGER_TYPE2
Task Scheduler Schema
Task Scheduler Schema Elements
Actions (taskType) Element
AllowHardTerminate (settingsType) Element
AllowStartOnDemand (settingsType) Element
April (monthsType) Element
Arguments (execType) Element
Attachments (sendEmailType) Element
August (monthsType) Element
Author (registrationInfoType) Element
Body (sendEmailType) Element
Body (showMessageType) Element
BootTrigger (bootTriggerType) Element
Bcc (sendEmailType) Element
CalendarTrigger (calendarTriggerType) Element
Cc (sendEmailType) Element
ClassId (comHandlerType) Element
ComHandler (actionGroup) Element
Command (execType) Element
Count (restartType) Element
Data (comHandlerType) Element
Data (taskType) Element
Date (registrationInfoType) Element
Day (daysOfMonthType) Element
DaysInterval (dailyScheduleType) Element
DaysOfMonth (monthlyScheduleType) Element
DaysOfWeek (monthlyDayOfWeekScheduleType) Element
DaysOfWeek (weeklyScheduleType) Element
Deadline Element
December (monthsType) Element
Delay (bootTriggerType) Element
Delay (eventTriggerType) Element
Delay (logonTriggerType) Element
Delay (registrationTriggerType) Element
Delay (sessionStateChangeTriggerType) Element
DeleteExpiredTaskAfter (settingsType) Element
Description (registrationInfoType) Element
DisallowStartIfOnBatteries (settingsType) Element
DisallowStartOnRemoteAppSession (settingsType) Element
DisplayName (principalType) Element
Documentation (registrationInfoType) Element
Duration (idleSettingsType) Element
Duration (repetitionType) Element
Enabled (settingsType) Element
Enabled (triggerBaseType) Element
EndBoundary (triggerBaseType) Element
EventTrigger (triggerGroup) Element
Exclusive Element
Exec (actionGroup) Element
ExecutionTimeLimit (settingsType) Element
ExecutionTimeLimit (triggerBaseType) Element
February (monthsType) Element
File (attachmentsType) Element
Friday (daysOfWeekType) Element
From (sendEmailType) Element
GroupId (principalType) Element
HeaderFields (sendEmailType) Element
HeaderField (headerFieldsType) Element
Hidden (settingsType) Element
IdleSettings (settingsType) Element
IdleTrigger (triggerGroup) Element
Id (networkSettingsType) Element
Interval (repetitionType) Element
Interval (restartType) Element
January (monthsType) Element
July (monthsType) Element
June (monthsType) Element
LogonTrigger (triggerGroup) Element
LogonType (principalType) Element
MaintenanceSettings (maintenanceSettingsType) Element
March (monthsType) Element
May (monthsType) Element
Monday (weeklyScheduleType) Element
Months (monthlyDayOfWeekScheduleType) Element
Months (monthlyScheduleType) Element
MultipleInstancesPolicy (multipleInstancesPolicyType) Element
Name (headerFieldType) Element
Name (networkSettingsType) Element
NetworkProfileName (settingsType) Element
NetworkSettings (settingsType) Element
November (monthsType) Element
October (monthsType) Element
Period Element
Principal (principalType) Element
Principals (taskType) Element
Privilege (requiredPrivilegesType) Element
ProcessTokenSidType (principalType) Element
Priority (settingsType) Element
RandomDelay (calendarTriggerType) Element
RandomDelay (timeTriggerType) Element
RegistrationInfo (taskType) Element
RegistrationTrigger (registrationTriggerType) Element
Repetition (triggerBaseType) Element
ReplyTo (sendEmailType) Element
RequiredPrivileges (requiredPrivilegesType) Element
RestartOnFailure (settingsType) Element
RestartOnIdle (idleSettingsType) Element
RunLevel (runLevelType) Element
RunOnlyIfIdle (settingsType) Element
RunOnlyIfNetworkAvailable (settingsType) Element
Saturday (daysOfWeekType) Element
ScheduleByDay (calendarTriggerType) Element
ScheduleByMonthDayOfWeek (monthlyDayOfWeekScheduleType) Element
ScheduleByMonth (calendarTriggerType) Element
ScheduleByWeek (calendarTriggerType) Element
SecurityDescriptor (registrationInfoType) Element
SendEmail (actionGroup) Element
September (monthsType) Element
Server (sendEmailType) Element
SessionStateChangeTrigger (triggerGroup) Element
Settings (taskType) Element
ShowMessage (actionGroup) Element
Source (registrationInfoType) Element
StartBoundary (triggerBaseType) Element
StartWhenAvailable (settingsType) Element
StateChange (sessionStateChangeTriggerType) Element
StopAtDurationEnd (repetitionType) Element
StopIfGoingOnBatteries (settingsType) Element
StopOnIdleEnd (idleSettingsType) Element
Subject (sendEmailType) Element
Subscription (eventTriggerType) Element
Sunday (daysOfWeekType) Element
Task Element
Thursday (daysOfWeekType) Element
TimeTrigger (triggerGroup) Element
Title (showMessageType) Element
To (sendEmailType) Element
Triggers (triggersType) Element
Tuesday (daysOfWeekType) Element
URI (registrationInfoType) Element
UserId (logonTriggerType) Element
UserId (principalType) Element
UserId (sessionStateChangeTriggerType) Element
UseUnifiedSchedulingEngine (settingsType) Element
ValueQueries (eventTriggerType) Element
Value (headerFieldType) Element
Value (namedValues) Element
Version (registrationInfoType) Element
Volatile Element
WaitTimeout (idleSettingsType) Element
WakeToRun (settingsType) Element
Wednesday (daysOfWeekType) Element
Week (weeksType) Element
WeeksInterval (weeklyScheduleType) Element
Weeks (monthlyDayOfWeekScheduleType) Element
WorkingDirectory (execType) Element
Task Scheduler Schema Simple Types
dayOfMonthType Simple Type
guidType Simple Type
logonType Simple Type
multipleInstancesPolicyType Simple Type
nonEmptyString Simple Type
pathType Simple Type
priorityType Simple Type
privilegeType Simple Type
processTokenSidType Simple Type
runlevelType Simple Type
sessionStateChangeType Simple Type
versionType Simple Type
weekType Simple Type
Task Scheduler Schema Complex Types
actionBaseType Complex Type
actionsType Complex Type
attachmentType Complex Type
bootTriggerType Complex Type
calendarTriggerType Complex Type
comHandlerType Complex Type
dailyScheduleType Complex Type
dataType Complex Type
daysOfMonthType Complex Type
daysOfWeekType Complex Type
eventTriggerType Complex Type
execType Complex Type
headerFieldsType Complex Type
headerFieldType Complex Type
idleSettingsType Complex Type
idleTriggerType Complex Type
logonTriggerType Complex Type
maintenanceSettingsType Complex Type
monthlyDayOfWeekScheduleType Complex Type
monthlyScheduleType Complex Type
monthsType Complex Type
namedValues Complex Type
namedValue Complex Type
networkSettingsType Complex Type
principalsType Complex Type
principalType Complex Type
registrationInfoType Complex Type
registrationTriggerType Complex Type
repetitionType Complex Type
requiredPrivilegesType Complex Type
restartType Complex Type
sendMailType Complex Type
sessionStateChangeTriggerType Complex Type
settingsType Complex Type
showMessageType Complex Type
taskType Complex Type
timeTriggerType Complex Type
triggerBaseType Complex Type
triggersType Complex Type
weeklyScheduleType Complex Type
weeksType Complex Type
Task Scheduler Schema Groups
actionGroup Group
triggerGroup Group
Task Scheduler Error and Success Constants
Schtasks.exe
Task Scheduler Glossary
E
I
P
S
T
W
Task Scheduler for developers
8/8/2022 • 2 minutes to read • Edit Online

IMPORTANT
This topic and the other topics in this section are for a developer audience. If you're wishing to use the the Task Scheduler
component in your capacity as an administrator, or an IT Professional, then see Task Scheduler.

About the Task Scheduler


The Task Scheduler enables you to automatically perform routine tasks on a chosen computer. Task Scheduler
does this by monitoring whatever criteria you choose (referred to as triggers) and then executing the tasks when
those criteria are met.
You can use the Task Scheduler to execute tasks such as starting an application, sending an email message, or
showing a message box. Tasks can be scheduled to execute in response to these events, or triggers.
When a specific system event occurs.
At a specific time.
At a specific time on a daily schedule.
At a specific time on a weekly schedule.
At a specific time on a monthly schedule.
At a specific time on a monthly day-of-week schedule.
When the computer enters an idle state.
When the task is registered.
When the system is booted.
When a user logs on.
When a Terminal Server session changes state.

Developers
The Task Scheduler provides APIs in these forms.
Task Scheduler 2.0: interfaces and objects are provided for C++, and for scripting development, respectively.
Task Scheduler 1.0: interfaces are provided for C++ development.

Run-time requirements
The Task Scheduler requires the following operating systems.
Task Scheduler 2.0: Client requires Windows Vista, or above. Server requires Windows Server 2008, or
above.
Task Scheduler 1.0: Client requires Windows Vista, or Windows XP. Server requires Windows Server 2008, or
Windows Server 2003.

In this section
TO P IC DESC RIP T IO N

What's new in Task Scheduler Summary of new functionality introduced by the Task
Scheduler.

About the Task Scheduler General conceptual information about the Task Scheduler
API.

Using the Task Scheduler Code examples that show how to use the Task Scheduler
APIs.

Task Scheduler reference Detailed reference information for Task Scheduler APIs and
the Task Scheduler schema.
What's New in Task Scheduler
8/8/2022 • 3 minutes to read • Edit Online

The following changes summarize what is new in different versions of Task Scheduler.

Windows 10 (and Windows Server 2016)


The following Task Scheduler changes are introduced in Windows 10.
When battery saver is on, Windows Task Scheduler tasks are triggered only if the task is:
Not set to Star t the task only if the computer is idle... (task doesn't use IdleSettings )
Not set to run during automatic maintenance (task doesn't use MaintenanceSettings )
Is set to Run only when user is logged on (task LogonType is
TASK_LOGON_INTERACTIVE_TOKEN or TASK_LOGON_GROUP )
All other triggers are delayed until battery saver is off. For more information about accessing battery
saver status in your application, see SYSTEM_POWER_STATUS . For general information about battery
saver, see battery saver (in the hardware component guidelines).
For security reasons, a non-administrator user cannot view nor manage a Windows Task Scheduler task
that was created by another user.

Windows 8
The following Task Scheduler 2.0 changes are introduced in Windows 8:
Powershell support: users can manage (create, delete, modify, explicitly start, stop etc.) Windows Task
Scheduler tasks using the ScheduledTasks powershell module.
Managed passwords: administrators can use the Active Directory managed password accounts as task
principals. These tasks no longer require an enforced password reset policy.
API changes: Introduced two new task settings with the ITaskSettings3 interface.
MaintenanceSettings : tasks using these settings are treated as a new type of scheduled tasks that
are invoked during OS automatic maintenance time, according to the specified periodicity and
deadline.
Volatile : tasks that are set to be volatile are always disabled on an OS boot and must be explicitly re-
enabled back when required. Volatile tasks are utilized by the failover clusters to ensure only one task
instance is scheduled on a cluster at a time.
The unified scheduling engine now supports the following features:
S4U Logon type, through the LogonType element.
XPath query values for event triggers, through the ValueQueries element.
Do not allow task hard terminate, through the AllowHardTerminate element.
Features deprecated in this release
Action: sendEmail (you can use IExecAction with the Windows PowerShell Send-MailMessage
cmdlet as a workaround).
Action: showMessage .
AT.exe cmdline utility

Windows 7
The following Task Scheduler 2.0 changes are introduced in Windows 7:
Using the unified scheduling engine provided by the underlying operating system.
Ability to reject starting tasks in Remote Applications Integrated Locally (RAIL) sessions.
Task security hardening (for tasks running as "NETWORK SERVICE" or "LOCAL SERVICE" only):
Ability to assign a process token security identifier (SID) type (for example, unrestricted or none) to a
task.
Allow task developers to request the exact set of privileges that their task requires.
API changes:
Task security hardening support: new task security hardening feature is introduced with new
IPrincipal2 interface.
Introduced two new task settings with the new ITaskSettings2 interface.
DisallowStartOnRemoteAppSession: The new DisallowStartOnRemoteAppSession setting
can reject a task start if triggered in Remote Applications Integrated Locally (RAIL) sessions.
UseUnifiedSchedulingEngine: Using the UseUnifiedSchedulingEngine setting provides a
cohesive behavior for Windows Tasks and Services because it is being managed in a
uniform manner by a common system-wide scheduling engine. Although using a unified
engine is recommended, it does not support some of the Task Scheduler features. If the
combination of properties will not allow running of the task under a unified engine, the
registration of such will be rejected.
The task features that are not supported by the unified scheduling engine include:
Logon types:
TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD
Multiple instance policy:
TASK_INSTANCES_STOP_EXISTING
Actions:
Send email
Display message
Settings:
Task network settings
Do not allow task hard terminate
Triggers:
Trigger execution time limit
Repetition patterns for calendar triggers
XPath query values for event triggers
Monthly and Monthly day-of-week trigger types

Windows Vista
The Task Scheduler 2.0 API should be used in developing applications that use the Task Scheduler service on
Windows Vista. For more information, see Task Scheduler Reference and Using the Task Scheduler.

Windows 2000, Windows XP, and Windows Server 2003


The Task Scheduler 2.0 API is not available. Use Task Scheduler 1.0.

Related topics
Task Scheduler
About The Task Scheduler
About the Task Scheduler
8/8/2022 • 2 minutes to read • Edit Online

The Task Scheduler service allows you to perform automated tasks on a chosen computer. With this service, you
can schedule any program to run at a convenient time for you or when a specific event occurs. The Task
Scheduler monitors the time or event criteria that you choose and then executes the task when those criteria are
met.

Where Task Scheduler is Installed


The Task Scheduler is automatically installed with several Microsoft operating systems.
Task Scheduler 1.0 is installed with the Windows Server 2003, Windows XP, and Windows 2000 operating
systems.
Task Scheduler 2.0 is installed with Windows Vista and Windows Server 2008.
The Task Scheduler 2.0 API should be used in developing applications that use the Task Scheduler service on
Windows Vista. For more information, see Task Scheduler Reference.
Task Scheduler is started each time the operating system is started. It can be run either through the Task
Scheduler graphical user interface (GUI) or through the Task Scheduler API described in this SDK.

Information about Tasks


Tasks are the main component of the Task Scheduler. For information on what tasks are and what their
components are, see the following topics:
Tasks
Task Actions
Task Triggers
Task Registration Information
Task Idle Conditions
Security Contexts for Tasks
Repeating A Task
Automatic Maintenance
For more information and examples about how to use the Task Scheduler interfaces, scripting objects, and XML,
see Using the Task Scheduler.

Related topics
Task Scheduler
Tasks
8/8/2022 • 4 minutes to read • Edit Online

A task is the scheduled work that the Task Scheduler service performs. A task is composed of different
components, but a task must contain a trigger that the Task Scheduler uses to start the task and an action that
describes what work the Task Scheduler will perform.
When a task is created, it is stored in a task folder. Task folders can be accessed through the ITaskFolder
interface (TaskFolder for scripting), and tasks can be accessed through the IRegisteredTask interface
(RegisteredTask for scripting) when they are created. You can change access control lists (ACLs) for tasks and
task folders in order to grant or deny certain users and groups access to a task or task folder. This can be done
by using the IRegisteredTask ::SetSecurityDescriptor method, the ITaskFolder ::SetSecurityDescriptor
method, or by specifying a security descriptor when a task is registered by using the RegisterTaskDefinition
or RegisterTask method.

NOTE
If the Local System account is denied access to a task file or task folder, then the Task Scheduler service can produce
unexpected results.

Components of a Task
The following illustration shows the task components.

The following list contains a brief description of each task component:


Triggers: Task Scheduler uses event or time-based triggers to know when to start a task. Every task can
specify one or more triggers to start the task.
For more information about triggers, see Task Triggers.
Actions: These are the actions, the actual work, that is performed by the task. Every task can specify one
or more actions to complete its work.
For more information about actions, see Task Actions.
Principals: Principals define the security context in which the task is run. For example, a principal might
define a specific user or user group that can run the task.
For more information about principals, see Security Contexts for Tasks.
Settings: These are the settings that the Task Scheduler uses to run the task with respect to conditions that
are external to the task itself. For example, these settings can specify the priority of the task with respect
to other tasks, whether multiple instances of the task can be run, how the task is handled when the
computer is in an idle condition, and other conditions.
For more information about task settings, see ITaskSettings (TaskSettings for scripting).

NOTE
By default, a task will be stopped 72 hours after it starts to run. You can change this by changing the
ExecutionTimeLimit setting.

Registration Information: This is administrative information that is gathered when the task is registered.
For example, this information describes the author of the task, the date when the task was registered, an
XML description of the task, and other information.
For more information about task registration information, see Task Registration Information.
Data: This is additional documentation about the task that is supplied by the author of the task. For
example, this data may contain XML Help that can be used by users when they run the task.

Task APIs
Task Scheduler 2.0 provides two sets of APIs: a set of scripting objects and interfaces for Task Scheduler 2.0. For
more information, see Task Scheduler Reference.
Task compatibility, which is set through the Compatibility property, should only be set to
TASK_COMPATIBILITY_V1 if a task must be accessed or modified from a Windows XP, Windows Server 2003, or
Windows 2000 computer. Otherwise, it is recommended that you use Task Scheduler 2.0 compatibility because
it has more features.
Starting with Task Scheduler 2.0, the ITaskSer vice interface (TaskSer vice for scripting) is used as a starting
point to create tasks in specified folders. The ITaskDefinition interface (TaskDefinition for scripting) is used to
hold all the components of a task, such as the settings, actions, and triggers. The ITaskTrigger , IAction , and
ITaskSettings APIs provide properties that are then used to define the other components of the task. Task
Scheduler 1.0 provides the ITask interface, which is supported only for backward compatibility.
For scripting, the Task Scheduler interfaces map to scripting objects that have the similar names, properties, and
methods. For example, the TaskSer vice scripting object has the same properties and methods as the
ITaskSer vice interface.
For more information and examples about how to use the Task Scheduler interfaces, scripting objects, and XML,
see Using the Task Scheduler.
Task Scheduler 1.0 Tasks
A Task Scheduler 1.0 task is any application or file type that the Task Scheduler can execute. These may include
any of the following (as supported by the operating system on which the task will execute): Win32 applications,
Win16 applications, OS/2 applications, MS-DOS applications, batch files (*.bat), command files (*.cmd), or any
properly registered file type.
Data that describes a task is kept in a task file that is stored in the Scheduled Tasks folder. For more information,
see Scheduled Tasks folder. The name of these task files include the name of the task, followed by a .job file
name extension.
For more information about adding Task Scheduler 1.0 tasks, see Adding Work Items.
For more information about enumerating through Task Scheduler 1.0 tasks, see Enumerating Tasks.
For a Windows Server 2003, Windows XP, or Windows 2000 computer to create, monitor, or control tasks on a
Windows Vista computer, the following operations should be completed on the Windows Vista computer, and
the user who is calling the ITaskScheduler ::SetTargetComputer method must be a member of the
Administrators group on the remote Windows Vista computer.
To enable the "Share File and Printers" exception in Windows Firewall
1. Click Star t , and then click Control Panel .
2. In Control Panel , click Classic View and then double-click the Windows Firewall icon.
3. In the Windows Firewall window, click the Exceptions tab and select File and Printer Sharing
exception check box.
To enable the "Remote Registr y" ser vice
Open a Command Prompt window and enter the following command: net star t "Remote Registr y" .

Related topics
About the Task Scheduler
Task Triggers
Task Actions
ITaskDefinition
TaskDefinition
ITaskSer vice
TaskSer vice
Task Actions
8/8/2022 • 2 minutes to read • Edit Online

The work items performed by a task are called actions. A task can have a single action or a maximum of 32
actions. Be aware that when multiple actions are specified, they are executed sequentially.

Types of Actions
The following table of actions describes the type of work or actions that can be accomplished by a task.

T Y P E O F A C T IO N DESC RIP T IO N

ComHandler Action This action fires a COM handler.

Exec Action This action executes a command-line operation such as


starting Notepad.

E-mail Action This action sends an email when a task is triggered.

Show Message Action This action shows a message box with a specified message
and title.

Specifying Actions
The actions of a task are specified when the task is defined and stored in a collection of actions used by the Task
Scheduler service. The following table lists links to reference topics for the APIs and XML elements that are
associated with actions.
For more information and examples about how to use the Task Scheduler interfaces, scripting objects, and XML,
see Using the Task Scheduler.
Interface APIs for C++ Development
API DESC RIP T IO N

Actions Proper ty of ITaskDefinition Gets or sets the actions performed by the task.

IActionCollection Contains the actions performed by the task.

IComHandlerAction Represents an action that fires a handler.

IExecAction Represents an action that executes a command-line


operation.

IEmailAction Represents an action that sends an email message.

IShowMessageAction Represents an action that shows a message box.

Scripting Object APIs for Scripting Development


API DESC RIP T IO N

TaskDefinition.Actions Gets or sets the actions performed by the task.

ActionCollection Contains the actions performed by the task.

ComHandlerAction Represents an action that fires a handler.

ExecAction Represents an action that executes a command-line


operation.

EmailAction Represents an action that sends an email message.

ShowMessageAction Represents an action that shows a message box.

XML Elements
EL EM EN T DESC RIP T IO N

Actions Defines the actions performed by the task.

ComHandler Represents an action that fires a handler.

Exec Represents an action that executes a command-line


operation.

SendEmail Represents an action that sends an email message.

ShowMessage Represents an action that shows a message box.

Using Variables in Action Properties


Some action properties that are of type BSTR can contain $(Arg0), $(Arg1), ..., $(Arg32) variables in their string
values. These variables are replaced with the values that are specified in the params parameter of the
IRegisteredTask ::Run and IRegisteredTask ::RunEx methods or are contained within the event trigger for the
task. The following table lists the action properties that can use variables in their string values.

A C T IO N P RO P ERT IES

COM Handler Action C++:


ClassId Proper ty of IComHandlerAction
Data Proper ty of IComHandlerAction

Scripting:
ComHandlerAction.ClassId
ComHandlerAction.Data
A C T IO N P RO P ERT IES

Email Action C++:


Body Proper ty of IEmailAction
Ser ver Proper ty of IEmailAction
Subject Proper ty of IEmailAction
To Proper ty of IEmailAction
Cc Proper ty of IEmailAction
Bcc Proper ty of IEmailAction
ReplyTo Proper ty of IEmailAction
From Proper ty of IEmailAction

Scripting:
EmailAction.Body
EmailAction.Ser ver
EmailAction.Subject
EmailAction.To
EmailAction.Cc
EmailAction.Bcc
EmailAction.ReplyTo
EmailAction.From

Exec Action C++:


Arguments Proper ty of IExecAction
WorkingDirector y Proper ty of IExecAction

Scripting:
ExecAction.Arguments
ExecAction.WorkingDirector y

Show Message Action C++:


Title Proper ty of IShowMessageAction
MessageBody Proper ty of
IShowMessageAction

Scripting:
ShowMessageAction.Title
ShowMessageAction.MessageBody

Related topics
About The Task Scheduler
Task Triggers
8/8/2022 • 2 minutes to read • Edit Online

A trigger is a set of criteria that, when met, starts the execution of a task. Task Scheduler provides both time-
based and event-based triggers that can start a task in several different ways. A given task can be started by one
or more triggers. A task can have a maximum of 48 triggers.

Time-based Triggers
Time-based triggers start tasks at specified times. This includes starting the task once at a specific time or
starting the task multiple times on a daily, weekly, monthly, or monthly day-of-week schedule.

Event-based Triggers
Event-based triggers start a task in response to certain system events. For example, event-based triggers can be
set to start a task when the system starts up, when a user logs on to the local computer, or when the system
becomes idle.

Multiple Triggers
Each task can be started by one or more triggers, allowing the task to be started in any number of ways.
However, multiple triggers are implemented differently in Task Scheduler 1.0 and Task Scheduler 2.0.
In Task Scheduler 2.0, each trigger is defined by a separate trigger API that is associated with the task through
the trigger collection.
In Task Scheduler 1.0, multiple triggers can be thought of as a schedule, a set of times at which the task starts. In
this case, the schedule is the set of times (specified by the union of all of the triggers associated with the work
item) at which a work item will execute.

Related topics
Repeating A Task
Trigger Types
Trigger Interfaces
About The Task Scheduler
Trigger Types
8/8/2022 • 2 minutes to read • Edit Online

The time-based and event-based triggers that are described below allow you to start tasks in a variety of ways.

Task Scheduler 2.0 Triggers


The following trigger types are defined by the TASK_TRIGGER_TYPE2 enumeration.

T RIGGER DESC RIP T IO N

Event trigger (event based trigger) For scripting Starts the task when a specific system event occurs.
development, see EventTrigger .
For C++ development, see IEventTrigger .
For XML development, see EventTrigger Element .

Time trigger (time-based trigger)For scripting development, Starts the task at a specific date and time.
see TimeTrigger .
For C++ development, see ITimeTrigger .
For XML development, see TimeTrigger Element .

Daily trigger (time-based calendar trigger)For scripting Starts the task at a specific time on a daily schedule. For
development, see DailyTrigger . example, the task starts at 8:00 AM every day or every
For C++ development, see IDailyTrigger . other day.
For XML development, see CalendarTrigger Element .

Weekly trigger (time-based calendar trigger)For scripting Starts the task at a specific time on a weekly schedule. For
development, see WeeklyTrigger . example, the task starts at 8:00 AM on a specific day of the
For C++ development, see IWeeklyTrigger . week every week or on a specific day of the week every
For XML development, see CalendarTrigger Element . other week.

Monthly trigger (time-based calendar trigger)For scripting Starts the task at a specific time on a monthly schedule. For
development, see MonthlyTrigger . example, the task starts at 8:00 AM on specific days of the
For C++ development, see IMonthlyTrigger . month on specific months.
For XML development, see CalendarTrigger Element .

Monthly day-of-week (DOW) trigger (time-based calendar Starts the task at a specific time on a monthly day-of-week
trigger)For scripting development, see schedule. For example, the task starts at 8:00 AM on specific
MonthlyDOWTrigger . days of the week, weeks of the month, and months of the
For C++ development, see IMonthlyDOWTrigger . year.
For XML development, see CalendarTrigger Element .

Idle trigger (event-based trigger)For scripting development, Starts the task when the computer enters an idle state.
see IdleTrigger .
For C++ development, see IIdleTrigger .
For XML development, see IdleTrigger Element .

Registration trigger (event-based trigger)For scripting Starts the task when the task is registered or updated.
development, see RegistrationTrigger .
For C++ development, see IRegistrationTrigger .
For XML development, see RegistrationTrigger Element .
T RIGGER DESC RIP T IO N

Boot trigger (event-based trigger)For scripting development, Starts the task when the system is booted.
see BootTrigger .
For C++ development, see IBootTrigger .
For XML development, see BootTrigger Element .

Logon trigger (event-based trigger)For scripting Starts the task when a user logs on.
development, see LogonTrigger .
For C++ development, see ILogonTrigger .
For XML development, see LogonTrigger Element .

Session state change trigger (event-based trigger)For Starts the task when a Terminal Server session changes state.
scripting development, see SessionStateChangeTrigger .
For C++ development, see ISessionStateChangeTrigger .
For XML development, see SessionStateChangeTrigger
Element .

Task Scheduler 1.0 Triggers


The following trigger types are defined by the TASK_TRIGGER_TYPE enumeration. To implement any of the
following triggers, see the TASK_TRIGGER structure.
Once trigger: Starts the task a single time.
Daily trigger: Starts the task on a daily interval.
Weekly trigger: Starts the task on a weekly schedule.
Monthly trigger: Starts the task on a monthly schedule.
Monthly DOW trigger: Starts the task on a monthly day-of-week schedule.
On Idle trigger: Starts the task when the computer is in an idle state.
System Start trigger: Starts the task when the computer is booted.
Logon trigger: Starts the task when a specific user logs on.

Related topics
Task Triggers
Trigger Interfaces
Trigger Structures
Trigger Interfaces
8/8/2022 • 2 minutes to read • Edit Online

The APIs that are used to manage triggers vary depending on the version of the Task Scheduler. However, in
both cases these APIs enable you to create new triggers, retrieve and update existing triggers, and delete
triggers that are no longer required.
Applications that are developed using Task Scheduler 2.0 can use objects and interfaces to create, retrieve,
modify, and delete the triggers for a task.
In the following illustration, a task specifies a collection of triggers using its Triggers property. This collection
contains one or more individual trigger APIs with each API specifying a specific trigger type. For example, in the
illustration below the trigger collection contains a boot trigger, logon trigger, and a daily trigger.

Object APIs for Scripting Development


For more information about the methods and properties of the objects that are used to specify triggers, see:
TaskDefinition
TriggerCollection
Trigger
BootTrigger
DailyTrigger
EventTrigger
IdleTrigger
LogonTrigger
MonthlyDOWTrigger
MonthlyTrigger
RegistrationTrigger
TimeTrigger
WeeklyTrigger
Interfaces APIs for C++ Development
For more information about the methods and properties of the interfaces that are used to specify triggers, see:
ITaskDefinition
ITriggerCollection
ITrigger
IBootTrigger
IDailyTrigger
IEventTrigger
IIdleTrigger
ILogonTrigger
IMonthlyDOWTrigger
IMonthlyTrigger
IRegistrationTrigger
ITimeTrigger
IWeeklyTrigger

Task Scheduler 1.0 Trigger Interfaces


Existing applications that are developed using Task Scheduler 1.0 can use the methods that are available from
the Task Scheduler 1.0 interfaces to create, retrieve, modify, and delete the triggers for a work item. However,
note that all Task Scheduler 1.0 interfaces, enumerations, and structures are obsolete and should not be used for
the development of new applications.
The two interfaces that are used to do this are shown in the following illustration. The IScheduledWorkItem
interface is used to manage all the triggers that are associated with a work item (such management includes
creating a new trigger for the work item). The ITaskTrigger interface is used to manage a specific trigger.

The IScheduledWorkItem interface provides methods for creating a new trigger for a work item, retrieving the
number of triggers that are associated with a work item, retrieving the trigger structures that are associated with
the work item, retrieving trigger strings that are associated with the work item, and for deleting triggers.
Once the trigger object is available, you can use the ITaskTrigger interface to retrieve the trigger structure and
the string of the trigger and to set the criteria that is used to fire the trigger. This interface is used only when you
are working with a task trigger object.

Related topics
Task Triggers
Trigger Types
Trigger Structures
Task Scheduler 1.0 Triggers
8/8/2022 • 2 minutes to read • Edit Online

The following topics refer to triggers used by Task Scheduler 1.0 tasks. They are included here for developers
who are looking at existing code.

Related topics
Trigger Structures
Idle Triggers
Task Scheduler
Trigger Structures for Task Scheduler 1.0
8/8/2022 • 2 minutes to read • Edit Online

Task Scheduler 1.0 uses several structures to define the criteria of a trigger.

NOTE
For more information about Task Scheduler 2.0 triggers, see Trigger Interfaces.

Task Scheduler 1.0 Structures


The following illustration shows the TASK_TRIGGER structure. It has three required members (wBeginYear ,
wBeginMonth , and wBeginDay ) that must be set when creating a new trigger. (To jump to the reference page
for this structure, click the structure name in the illustration.)

Be aware that the TriggerType member uses the TASK_TRIGGER_TYPE enumeration and the Type member
uses a TASK_TRIGGER_UNION structure. The TASK_TRIGGER_TYPE enumeration is used to specify the type
of trigger (event and time-based trigger types). The TRIGGER_TYPE_UNION structure is used to combine the
DAILY , WEEKLY , MONTHLYDATE (day of month), and MONTHLYDOW (day of week) structures that are used
to specify when a time-based trigger will fire.
If TriggerType specifies a one-time time-based trigger or an event-based trigger, the Type member is ignored.
The TRIGGER_TYPE_UNION structure is used only if the TriggerType member specifies a daily, weekly, day-
of-month, or monthly day-of-week time-based trigger.
In addition, the setting of the Type member indicates which member of the TRIGGER_TYPE_UNION structure
is used. The following illustration shows the relationship between the values of the TASK_TRIGGER_TYPE
enumeration and the members of the TRIGGER_TYPE_STRUCTURE structure. (To jump to the reference pages
for these structures click the structure name in the illustration.)
Related topics
Task Triggers
Trigger Types
Trigger Interfaces
Idle Triggers for Task Scheduler 1.0
8/8/2022 • 2 minutes to read • Edit Online

An idle trigger is an event-based trigger that is fired a specific number of times after the computer becomes idle.
There are multiple conditions that define when a computer becomes idle, such as when no keyboard or mouse
input occurs.
Idle triggers are created by specifying TASK_EVENT_TRIGGER_ON_IDLE in the TASK_TRIGGER_TYPE member
of the TASK_TRIGGER structure. The idle trigger is fired when the system becomes idle for the amount of time
that is specified by the idle wait time of the work item.

NOTE
When TASK_EVENT_TRIGGER_ON_IDLE is specified, the wStar tHour , wStar tMinute , and Type members of the
TASK_TRIGGER structure are ignored.

You can set the idle wait time of a work item by calling the IScheduledWorkItem::SetIdleWait method. This
method sets the amount of time (in minutes) that the system must remain idle before the trigger is fired and the
work item is executed.
To retrieve the idle time of a task, call the IScheduledWorkItem::GetIdleWait method.

Related topics
Task Triggers
Task Registration Information
8/8/2022 • 2 minutes to read • Edit Online

Registration information provides a way to identify a task in several different ways. For example, a task can be
identified by the author, how it was authored (referred to as the task source), and date of registration.

Using Registration Information


Registration information is typically specified when the task is created and then used in the following ways:
Displayed by the Task Scheduler user interface.
Get or set by C++ applications or scripts.
In an enterprise environment, used as a search criteria when enumerating over all registered tasks.

Types of Registration Information


Task registration information is defined by the properties of the RegistrationInfo object for scripting
applications, the properties of the IRegistrationInfo interface for C++ applications, and the child elements of
the RegistrationInfo (taskType) element for reading or writing XML.
These properties allow access to the following types of registration information:
Task Author
Task Scheduler sets the author of the task when it is created.
Task Registration Date
Task Scheduler sets this date when the task is registered.
Task Description
A user-defined description that may include what triggers are used to start the task or what actions the
task performs.
Task Documentation
User-supplied documentation that is needed by the task.
Task Security Descriptor
A user-supplied security descriptor.
Task Source
User-supplied information that describes where the task originated from. For example, a task may
originate from a component, service, application, or user.
Task URI
A uniform resource identifier (URI) for the task.
Task Version
User-supplied information that is used when multiple versions of a task exist.
XML Text
An XML-formatted version of the registration information. Note that you can set or modify the
registration information directly through this XML and the appropriate object and interface properties
will be updated accordingly.

Registering Tasks
A task can be registered after the task definitions are created and registration information and setting values are
supplied by the user. A task is registered using the TaskFolder.RegisterTaskDefinition method for scripting
applications or the ITaskFolder ::RegisterTaskDefinition method for C++ applications. If you want to register
a task using XML to define the task, you use the TaskFolder.RegisterTask method for scripting applications
and the ITaskFolder ::RegisterTask method for C++ applications.
In the methods mentioned above, you can specify the security context to run the task. You have to be an
administrator on the system to schedule jobs to run under contexts other than your own. For more information
on the security contexts to run tasks, see Security Contexts for Running Tasks.

Related topics
About The Task Scheduler
Task Scheduler
Task idle conditions
8/8/2022 • 4 minutes to read • Edit Online

A task can be handled in several ways when the computer enters an idle state. This includes defining an idle
trigger or setting the idle conditions for when the task starts.

Detecting the idle state


In Windows 7, the Task Scheduler verifies that the computer is in an idle state every 15 minutes. Task Scheduler
checks for an idle state using two criteria: user absence, and a lack of resource consumption. The user is
considered absent if there is no keyboard or mouse input during this period of time. The computer is considered
idle if all the processors and all the disks were idle for more than 90% of the last detection interval. (An
exception would be for any presentation type application that sets the ES_DISPLAY_REQUIRED flag. This flag
forces Task Schedule to not consider the system as being idle, regardless of user activity or resource
consumption.)
In Windows 7, Task Scheduler considers a processor as idle even when low priority threads (thread priority <
normal) execute.
In Windows 7, when the Task Scheduler detects that the computer is idle, the service waits only for user input to
mark the end of the idle state.
In Windows 8, Task Scheduler performs the same general user absence and resource consumption checks.
However, Task Scheduler relies on the operating system power subsystem to detect user presence. By default,
the user is considered absent after four minutes of no keyboard or mouse input. The resource consumption
verification time is shortened to 10 minute intervals when the user is present. When the user is away, the
verification time is shortened to 30 second intervals. Task Scheduler makes additional resource consumption
checks for the following events:
User presence state changed
AC/DC power source changed
Battery level changed (only when on batteries)
When any of the events above happens, Task Scheduler tests the computer for idleness since the last verification
time. In practice, this means that Task Scheduler may declare the system as idle immediately after user absence
is detected, if the other conditions have been met since the last verification time.
In Windows 8, the CPU and IO thresholds are set to 80%.
When detecting the idle state in Windows 8 Server, Task Scheduler does not take user presence or absence into
account. To mark the end of the idle state, Task Scheduler revises the resource consumption once in 90 minutes.

Defining an idle trigger


A task can be started when the computer enters an idle state by defining an idle trigger.
An idle trigger will only trigger a task action if the computer enters an idle state after the start boundary of the
trigger.
An application can define an idle trigger by using the IIdleTrigger interface.
If reading or writing XML, the idle trigger is specified by the IdleTrigger element of the Task Scheduler schema.
Task settings for idle conditions
The task settings can be used to define how the Task Scheduler handles the task when the computer enters an
idle state.
The following illustrations provide three possible timelines that show how these different idle conditions relate
to each other. Be aware that the illustrations start when the task trigger is activated or when the task is started
on demand (without requesting to ignore the existing task constraints).

NOTE
The Duration and WaitTimeout settings are deprecated. They're still present in the Task Scheduler user interface, and their
interface methods may still return valid values, but they're no longer used.

The following list describes the idle conditions.


Idle start: The time when the computer enters the idle state.
Idle end: The time when the computer transitions out of the idle state. Be aware that the amount of time the
computer is in the idle state is independent of the idle duration time that was described previously.
Idle wait and Idle duration have been deprecated.
Idle wait: The amount of time that the Task Scheduler will wait for an idle state to occur after a task trigger is
activated or after the task is started on demand.
Idle duration: The amount of time you want the computer to have been idle before starting the task.
For example, if a task is set to start only if the computer is idle for 30 minutes, and the task waits for the
computer to be idle for 10 minutes, then the task will launch in 5 minutes only if the computer has been idle for
25 minutes prior to the time the trigger was activated. The task will not start if the computer enters an idle state
5 minutes after the trigger is activated.
By default, a task DisallowStar tIfOnBatteries property is set to true, which means the Task Scheduler service
will not run tasks that are triggered by an idle trigger (or a trigger with idle conditions) when a computer is
running on battery power. You can change this behavior by setting the DisallowStar tIfOnBatteries property
to false.
If a task is triggered by an idle trigger, then the WaitTimeout property of the IIdleSettings interface
(IdleSettings for scripting) is ignored.
Applications can control the idle conditions by setting the properties in the IIdleSettings and IIdleTrigger
interfaces.
If reading or writing XML, these conditions are specified in the Settings element of the Task Scheduler schema.

Cycling idle condition


If the computer is cycling in and out of the idle state, you can terminate and restart the task using the following
idle conditions. To terminate and restart a task, both properties and elements must be set to True:
To terminate the task when the idle condition ends, set the StopOnIdleEnd property or the StopOnIdleEnd
element to True.
To restart the task when the computer cycles into the idle condition again, set the Restar tOnIdle property or
the Restar tOnIdle element to True.
Security Contexts for Tasks
8/8/2022 • 6 minutes to read • Edit Online

Tasks are registered and run under a specific security context. Users can create applications that successfully
register, update, delete, or run tasks, but the user must supply the correct credentials when a task is registered
and the application must be running in a process with the correct privileges.

Specifying Credentials
You can specify the security context for a task by specifying credentials in the ITaskFolder ::RegisterTask or
ITaskFolder ::RegisterTaskDefinition (TaskFolder.RegisterTask or TaskFolder.RegisterTaskDefinition for
scripting) methods or by assigning a principal to the Principal Proper ty of ITaskDefinition
(TaskDefinition.Principal for scripting). If a principal is created for a task definition, and then the task
definition is registered using the RegisterTaskDefinition method with different credentials specified in the
method parameters, then the credentials specified in the RegisterTaskDefinition method will overwrite the
credentials in the principal. If a principal is created for a task definition using XML, and then the XML for the task
is registered using the RegisterTask method with different credentials specified in the method parameters, then
the credentials specified in the RegisterTask method will overwrite the credentials in the principal.
You specify a user account or group when registering a task or specifying the principle for a task. The security
context of the user account or group is used for the security context of the task. In these methods and
properties, you also define the logon type. The logon type is defined by one of the constants in the
TASK_LOGON_TYPE enumeration.
Tasks registered with the TASK_LOGON_PASSWORD or TASK_LOGON_S4U flag will only launch if the specified
user has the Logon as Batch privilege enabled. Administrators and Backup Operators group users have this
privilege enabled by default.
When you call the ITaskSer vice::Connect (TaskSer vice.Connect for scripting) method, any subsequent
method calls to the Task Scheduler service will use the credentials that were passed to the Connect method.
This is important to consider when registering tasks with an interactive logon type. When you register a task
with the logon type equal to TASK_LOGON_INTERACTIVE_TOKEN and the task does not have credentials
specified in the Principal property of the task definition, specified in the parameters to
RegisterTaskDefinition , or specified in the XML that is passed to RegisterTask , then the task will be
registered with the credentials of the user that called the Connect method.

User Account Control (UAC) Security for Tasks


User Account Control (UAC) lets users exercise general functionality such as running programs and saving and
modifying data without exposing administrative privileges. By default, a task runs with low level privileges when
UAC is turned on. Tasks can specify that they will run with elevated privileges or low privileges by setting a
privilege level from the TASK_RUNLEVEL_TYPE enumeration for the RunLevel proper ty of IPrincipal
(Principal.RunLevel for scripting). The value of the RunLevel property determines the privilege level at which
a task's actions will be run. If a task's actions must have elevated privileges to run, then you must set the
RunLevel property to TASK_RUNLEVEL_HIGHEST . If a task is registered using the Administrators group for
the security context of the task, then you must also set the RunLevel property to TASK_RUNLEVEL_HIGHEST
if you want to run the task. If a task is registered using the Builtin\Administrator account or the Local System or
Local Service accounts, then the RunLevel property will be ignored. The property value will also be ignored if
User Account Control (UAC) is turned off. The value of the RunLevel property doesn't affect the permissions
needed to run or delete a task.
NOTE
After upgrading an operating system from Windows XP to Windows Vista, tasks that were registered using the
Builtin\Administrator account on Windows XP will have the RunLevel property set to TASK_RUNLEVEL_LUA . This
might cause some tasks to fail. You can update this property manually to ensure all the tasks will run.

From a low privilege process, you cannot register a task with the RunLevel property equal to
TASK_RUNLEVEL_HIGHEST , but you can register a task with the RunLevel property equal to
TASK_RUNLEVEL_LUA . The task actions will be run with low privileges. You are not allowed to register the task
as Builtin/Administrator, Local System, or for a group.
From an elevated privilege process, you can register a task with the RunLevel property equal to
TASK_RUNLEVEL_HIGHEST or TASK_RUNLEVEL_LUA . The task will be run with a privilege level decided by
the RunLevel property unless you are using the Administrator account, in which case the task is run with
elevated privileges.
From an elevated process, you can register a Task Scheduler 1.0 task. The Task Scheduler service will set the run
level of the task to TASK_RUNLEVEL_HIGHEST and the task will run with elevated privileges.
From an low privilege process, you can also register a Task Scheduler 1.0 task. The Task Scheduler service will
set the run level of the task to TASK_RUNLEVEL_LUA, and the task will run with low privileges. If this task is
updated from an elevated process, the run level of the task will remain TASK_RUNLEVEL_LUA.

Security for Registering Tasks


When you register a task from an account that is a member of the Administrators group, then you only need to
specify a password while registering the task in the following situations:
If you register the task to run under the security context of your account or a different user's account and you
use the TASK_LOGON_PASSWORD flag in the RegisterTask or RegisterTaskDefinition method.
If you register the task to run under the security context of a different user's account and you use the
TASK_LOGON_S4U flag in the RegisterTask or RegisterTaskDefinition method.
You cannot use a user group as the security context of a task when you register the task using the
TASK_LOGON_S4U flag or the TASK_LOGON_PASSWORD flag in the RegisterTask or RegisterTaskDefinition
method.
When you register a task from a user account that is not a member of the Administrators group, then you do
not need to specify a password when registering the task if you register the task to run under the security
context of your account and you use the S4U or interactive logon type. Otherwise, you need to specify a
password when registering the task. Also, you cannot register the task using the Local Service account or by
using a group for the task's security context.

Security for Reading, Updating, Deleting, and Running Tasks


By default, a user who creates a task can read, update, delete, and run the task. A user must have file write
permission on a task file to update a task, file read permission on a task file to read a task, delete permission on
a task file to delete a task, and file execute permission on a task to run a task using the IRegisteredTask ::Run
or RunEx methods (RegisteredTask .Run and RunEx for scripting). Members of the Administrators group or
the SYSTEM account can read, update, delete, and run any tasks. Members of the Users group, the LocalService
account, and the NetworkService account can only read, update, delete, and run the tasks that they have created.
This default behavior is changed when the DACL of the task file is changed, in which case the DACL defines
which users have file write, read, execute, and delete permission. To set permissions for a task file, use the
IRegisteredTask.SetSecurityDescriptor method (RegisteredTask.SetSecurityDescriptor for scripting) or set the
security descriptor when you register the task using the RegisterTask or RegisterTaskDefinition methods.
A user must have WriteDAC permission in addition to the read/write permissions to update a task if the task
update requires a change to the DACL for the task.

Related topics
Task Registration Information
About The Task Scheduler
Task Security Hardening
TaskFolder.RegisterTaskDefinition
ITaskFolder ::RegisterTaskDefinition
Principal Proper ty of ITaskDefinition
TASK_LOGON_TYPE
Task Security Hardening
8/8/2022 • 2 minutes to read • Edit Online

Using the tasks security hardening feature will allow task owners to run their tasks with minimum required
privileges. Note that this feature is enabled by default and task owners can make further adjustments by using
the task process token security identifier type and task required privileges array.

Task Process Token SID Type and Task Required Privileges Array
Specifying ProcessTokenSidType at the task definition level allows task owners to request a task process to
run with the "none" SID type or the "unrestricted" SID type. If the field is present in task definition, validation
ensures that task UserId contains the name or the corresponding SID string for one of those operating system
built-in service accounts: "NETWORK SERVICE" or "LOCAL SERVICE".
The SID type "none" means that the task runs in a process that does not contain a process token SID (no changes
will be made to the process token groups list). The task principal account SID (LocalService/NetworkService) in
that case has full access to the process token.
The "unrestricted" SID type means that a task SID will be derived from the full task path and will be added to the
process token groups list. For example, the \Microsoft\Windows\RAC\RACTask which runs in the Local Service
account, the task SID is derived from the name Microsoft-Windows-RAC-RACTask where a "-" is substituted for a
"\" since "\" is an invalid user name character. The well known group name for the task SID would be "NT TASK\
<modified full task path>" (domainname\username format). The process token default discretionary access
control list (DACL) will also be modified to allow full control for the task SID and local system SID only and read
control to the task principal account SID. "schtasks.exe /showsid /tn <full task path>" will show the task SID that
is corresponding to the task.
When a non-COM task action starts up, the scheduling engine logs on the task principal account, gets the
process token and queries the list of privileges that the token has and then compares that with the privileges list
specified in RequiredPrivileges. If a privilege is not specified in the latter, then that is marked as
SE_PRIVILEGE_REMOVED. The executable action will then be started with the resulting token handle by using the
CreateProcessAsUser API.
When a COM task action starts up, it must be activated by the taskhost.exe process. The scheduling engine
queries the context block of each running taskhost.exe with the same account as the starting task. If it finds that
a host process was started with a superset of privileges that the starting task needs, then that task gets hosted in
that process. If it does not find such a process, it combines the hardening info of all the tasks that are running in
the taskhosts under the task principal account with the specified RequiredPrivileges mask and then starts up a
new instance of taskhost.exe.
If RequiredPrivileges is not present in the task definition, the default privileges of task principal account without
the SeImpersonatePrivilege will be used for task process. If ProcessTokenSidType is not present in the task
definition, "unrestricted" is used as the default.

Related topics
Task Registration Information
About The Task Scheduler
Security Contexts for Tasks
Repeating A Task
8/8/2022 • 2 minutes to read • Edit Online

Task Scheduler can run a task any number of times times after a trigger is fired. To do this, the trigger defines a
repetition pattern that tells Task Scheduler how long it should continue to repeat the task and the time interval
between each task repetition.

Repetition Pattern
The following illustration shows a repetition pattern with a duration of 60 minutes and an interval of 25
minutes. Be aware that in this case, Task Scheduler runs the task when the trigger is fired, it runs the task again
after 25 minutes, then runs the task again after 50 minutes depending on the setting of the
StopAtDurationEnd proper ty of IRepetitionPattern (RepetitionPattern.StopAtDurationEnd for
scripting). If the StopAtDurationEnd property is set to True, Task Scheduler stops the last instance of the task if
it is still running after 60 minutes. If the StopAtDurationEnd property is set to False, the last instance of the
task is run regardless of the duration.

If you register a task that contains a trigger with a repetition interval equal to one minute and a repetition
duration equal to four minutes, the task will be started five times. The five repetitions can be defined by the
following pattern:
1. A task starts at the beginning of the first minute.
2. The next task starts at the end of the first minute.
3. The next task starts at the end of the second minute.
4. The next task starts at the end of the third minute.
5. The next task starts at the end of the fourth minute.
Windows Ser ver 2003, Windows XP and Windows 2000: If you register a task that contains a trigger with
a repetition interval equal to one minute and a repetition duration equal to four minutes, the task will be started
four times.

Objects, Interfaces, and XML Elements


For scripting development, the repetition pattern is defined using the RepetitionPattern object.
For C++ development, the repetition pattern is defined by the IRepetitionPattern interface.
When reading or writing XML for a task, the repetition pattern is specified in the Repetition element.

Related topics
Task Triggers
Automatic maintenance
8/8/2022 • 6 minutes to read • Edit Online

Maintenance activity refers to an application or process that helps maintain the health and performance of a
Windows PC. Maintenance includes keeping the Windows operating system (OS) and applications up-to-date,
checking security, and running scans for malware. Windows Automatic Management (WAM) is a set of
enhancements to the Task Scheduler API that you can use to link your applications into the Windows
maintenance schedule. Specifically, WAM allows you to add activities that require regular scheduling, but that
don't have exact time requirements. Instead, WAM relies on the operating system to choose the appropriate time
to activate the task throughout the day. The system chooses those times based on minimal impact to the user,
PC performance, and energy efficiency.

How scheduled maintenance works


Task Scheduler maintenance tasks are opportunistic tasks that run when the machine is idle and on AC power.
One of the major goals of maintenance tasks is to minimize impact to the PC by scheduling maintenance only
when the PC is plugged in to AC power and idle (that is, when you're not using, or have stepped away from, the
machine). The idea of maintenance today is for the machine to do work with the least disruption to the user.
Hence the old-style maintenance hour (we talk more about this in the Automatic maintenance—daily
wakeup section later in this topic) has been improved in order to take advantage of these idle periods. While
the maintenance hour can still be leveraged, running opportunistic maintenance is better for system health.
Your task may be starved if a machine doesn't spend much time both idle and on AC power. Make sure that your
scenario will still provide value to the user, even if it is delayed. If the user is actively using the machine, then the
system defers maintenance until a later time. The system also suspends any executing maintenance task if the
user returns to using the PC.
The system restarts a suspended maintenance task during the next idle period; however, the system won't
suspend any task marked as critical. Instead, the system allows a critical task to complete, regardless of user
action.
Due to the nature of scheduling, some scheduled tasks may not finish: perhaps there are too many scheduled
events to fit into the 1-hour maintenance window, or maybe the computer was simply not turned on. In such
cases, you can define a task with a deadline. A deadline is defined as a recurring timeframe in which the system
must successfully perform the task at least once.
If a task misses a deadline, then the maintenance scheduler will continue to attempt to execute the task during
the maintenance window. Further, the scheduler will not limit itself to the regular 1-hour time limit. Instead, the
scheduler extends the duration of the maintenance window in order to complete the delayed task.
Once the system completes the task (even with a failure error code), the attempt is considered successful. After a
successful attempt, the scheduler resets to the regular maintenance schedule, and will attempt the task during
the next period.

Automatic maintenance—daily wakeup


On Windows 7, a maintenance task runs exclusively during maintenance hour, defaulting to 3 AM, and
configurable via Group Policy. The machine would wake up from standby, run maintenance tasks, and go back to
sleep. This daily session was limited to a maximum duration of 1 hour per attempt. This would allow the system
to perform maintenance daily, starting at 3 AM by default. Note that the user may re-schedule the time that the
maintenance is triggered by configuring these settings.
With the advent of laptops, and the heavy focus on battery life, machines are no longer configured to allow S3
wakeup in most circumstances, and generally Doze-To-S4 (hibernate) as soon as possible, to save battery. In
response to these changes, Task Scheduler (> Win7) runs maintenance tasks whenever they are due, and the
machine is idle and on AC power.
This setting can be configured in Control Panel.
Open Control Panel > System and Security > Security and Maintenance > Automatic Maintenance .
So based on how your machines and your tasks are configured, the daily wakeup behavior may not occur today
as expected because of this new configuration. You can first determine whether your machine is S3 capable or
CS (Connected Standby) capable. This can be done by opening an elevated power shell prompt, and running the
following command.

powercfg /a

Maintenance hour, if the machine is configured correctly, still works, but if it doesn't,
Check your BIOS settings for Wake settings.
Check whether Allow Wake Timer is enabled in Power Options. Go to Control Panel > Hardware and
Sound > Power Options > Edit Plan Settings > Change advanced power settings > click Sleep >
Allow Wake Timer .
Check whether your scheduled task is configured with following.
MaintenanceSettings: Task should be configured with Period, Deadline.
Enabled: Task should be enabled.
WakeToRun: Task should be allowed to wake the machine.
For scheduling wakes from CS, the machine should be AOAC capable.
For scheduling wakes in S3 machines,
Check whether the machine went into S3 on AC Power.
The system should have Wake Enabled in Group Policy for Maintenance.
Connected Standby is the system state that an AOAC-compliant system can enter.
See differences between Modern Standby and S3 in the topic Modern Standby vs S3.

Defining an Automatic Maintenance Task


You can convert any Task Scheduler task to a maintenance task. To do so, you must confirm that your application
can be suspended. Then, you must extend the task definition with the new MaintenanceSettings and
AllowStar tOnDemand elements.
The main concern with creating a maintenance task is ensuring that the system can suspend and restart the
task. The system will likely suspend a maintenance task multiple times; therefore, you need to ensure that your
application is able to save its own state, and then resume at an arbitrary time. This ensures that the system does
not perform the same part of your task repeatedly.
Once you have ensured that your application can be suspended and resumed gracefully, you can use the
MaintenanceSettings and AllowStar tOnDemand elements to define the schedule. MaintenanceSettings
is defined according to the period, deadline, and exclusivity.
The period is mandatory, and defines how often the task should occur. Usually, this is defined in terms of a
multi-day cycle, such as “once every 5 days”. A period must be at least one day, meaning that you can't
schedule a task to occur multiple times in a day.
The deadline is optional, and defines how long the scheduler can fail to complete the task before notifying
the user or performing emergency maintenance. The deadline must be longer than the period, meaning that
the system must have the opportunity to attempt the task at least once before notifying the user.
In addition, a maintenance task can optionally be defined as exclusive. An exclusive task runs separate from
other maintenance tasks. Usually, an exclusive task is one that uses a great deal of resources, such as a large
amount of CPU time, or exclusive access to a database. The system completes all non-exclusive maintenance
tasks before starting an exclusive task. Therefore, you should declare a task as exclusive only when
necessary.
In contrast, AllowStar tOnDemand merely indicates that the system or the user can start the task at any time.
This allows the system to start the task during regular maintenance. Otherwise, you would have to set a unique
trigger for the task.
Task Scheduler 1.0 Task Information
8/8/2022 • 2 minutes to read • Edit Online

The following topics provide information on tasks that are developed using Task Scheduler 1.0.

NOTE
For a Windows Server 2003, Windows XP, or Windows 2000 computer to create, monitor, or control tasks on a
Windows Vista computer, certain operations must be completed on the Windows Vista computer. For more information,
see Tasks.

Task Scheduler 1.0 Topics


TO P IC DESC RIP T IO N

Programming Considerations Contains a list of programming issues to keep in mind when


developing applications that use Task Scheduler 1.0.

Enumerating Tasks Task Scheduler 1.0 provides an enumeration object for


enumerating the tasks in the Scheduled Tasks folder.

Related topics
Conceptual
About the Task Scheduler
Programming Considerations (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

When developing applications that use the Task Scheduler 1.0, keep the following programming issues in mind.
Your application must ensure the Task Scheduler service is running before attempting to make any calls
using the Task Scheduler API.
When retrieving strings, make sure that you call CoTaskMemFree to release each string after it is no longer
needed. When retrieving arrays of strings, make sure you first release each string in the array and then
release the array itself.
When creating or modifying a work item, including triggers associated with a work item, make sure you call
IPersistFile::Save to save the work item to disk.
After using any of the interfaces that are provided by the Task Scheduler API, make sure you call
IUnknown::Release to release the interface. IUnknown is supported by each Task Scheduler object.
The Using section of the Task Scheduler documentation provides numerous examples that follow these
guidelines. The table below provides jumps to some of these examples.

F O R A N EXA M P L E O F SEE

Releasing strings Retrieving Work Item Property Examples

Saving work items to disk Setting Work Item Property Examples

Releasing interfaces Creating a Task Using NewWorkItem Example


Enumerating Tasks
8/8/2022 • 2 minutes to read • Edit Online

Task Scheduler 1.0 provides an enumeration object for enumerating the tasks in the Scheduled Tasks folder.

NOTE
For a Windows Server 2003, Windows XP, or Windows 2000 computer to create, monitor, or control tasks on a
Windows Vista computer, certain operations must be completed on the Windows Vista computer. For more information,
see Tasks.

Using the Enumeration Object


The IEnumWorkItems interface of this object provides methods for enumerating the tasks in the folder,
resetting the enumeration sequence to the start of the list, skipping tasks, and making a copy of the current
enumeration object for later use.
For information about enumerating the tasks in the Scheduled tasks folder, see IEnumWorkItems::Next .
For information about resetting the enumeration to the start of the list, see IEnumWorkItems::Reset .
For information about skipping tasks, see IEnumWorkItems::Skip .
For information about making a copy of the current enumeration object, see IEnumWorkItems::Clone .
For an example of enumerating the tasks in the Scheduled Tasks folder, see Enumerating Tasks Example.

Related topics
Conceptual
Task Scheduler 1.0 Task Information
Scheduled Work Items
8/8/2022 • 2 minutes to read • Edit Online

The Task Scheduler uses two terms to describe what it can schedule: work items and tasks. Of these two terms,
work item is a more general term that describes any type of item that can be scheduled. A work item can be any
item that the Task Scheduler service runs at a time that is specified by the item's trigger(s).
In contrast, a task is a specific type of work item. Currently, the only type of scheduled work item that is
supported is a task.
The IScheduledWorkItem interface contains methods that are supported by all types of scheduled work items.
For example, account information, run times, and application-defined comments are properties that may apply
to all types of work items. These properties can be set and retrieved through the IScheduledWorkItem
interface.
The ITask interface contains methods that are supported only by tasks.
The methods of the IScheduledWorkItem interface are currently inherited by the ITask interface and in the
future will be inherited by other work item interfaces.

F O R EXA M P L ES O F SEE

Creating a new task. Creating a Task Using NewWorkItem Example

Running an existing task. Starting a Task Example

Retrieving properties that apply to all types of work items. Retrieving Work Item Property Examples

Setting properties that apply to all types of work items. Setting Work Item Property Examples
Adding Work Items
8/8/2022 • 2 minutes to read • Edit Online

There are two ways to add work items to the Scheduled Tasksfolder. You can create a new work item within the
folder, or you can add an existing work item to the folder.

NOTE
Currently, only task objects can be added to the Scheduled Tasks folder. When adding a task, you must know the
identifiers for the task class and the task interface ITask .

You create new work items by calling the ITaskScheduler ::NewWorkItem method. This method creates a new
work item object using the name that you provide and adds the work item to the Scheduled Tasks folder. When
you create a new work item, the Task Scheduler allocates the memory that is required for the new object.
To add existing work items to the Scheduled Tasks folder, call the ITaskScheduler ::AddWorkItem method.
When you call this method, you must create the object.
The names you supply for work items must be unique within the Scheduled Tasks folder. If a work item with the
same name already exists when you call either the ITaskScheduler ::NewWorkItem method or the
ITaskScheduler ::AddWorkItem method, the method returns an ERROR_FILE_EXISTS error. For more
information, see Creating a Task Using NewWorkItem Example.
Manipulating Work Items
8/8/2022 • 2 minutes to read • Edit Online

The IScheduledWorkItem interface provides methods for retrieving and setting work item properties;
creating, retrieving, and deleting triggers for work items (setting the trigger must be done with the
ITaskTrigger ::SetTrigger method); and for running, terminating, and deleting the work item.

NOTE
For the properties of a specific type of work item, refer to the interface for that type of object. For example, you cannot
set the priority level of a work item; however, you can use the methods of the ITask interface to retrieve and set the
priority of a task.

Whenever you modify a work item, you must call the IPersistFile::Save object to save the modified work item
to disk. The IPersistFile interface is a standard COM interface that is supported by the ITask interface.

F O R EXA M P L ES O F SEE

Retrieving properties that apply to all types of work items Retrieving Work Item Property Examples

Setting properties that apply to all types of work items Setting Work Item Property Examples

Running a known task Starting a Task Example

Terminating a running task Terminating a Task Example

Creating a new trigger for a known task Creating a New Trigger

Creating an event-based idle trigger for a known task Creating an Idle Trigger Example

Retrieving the trigger string of all triggers associated with a Retrieving Trigger Strings Example
known task
Using the Task Scheduler
8/8/2022 • 2 minutes to read • Edit Online

This section contains code examples that illustrate how the Task Scheduler API is used and XML examples that
show how tasks are defined in the Task Scheduler schema. Most of these examples are stand-alone code that
can be run independently, or pasted into a larger application and modified to the requirements of the
application.
The following table lists Task Scheduler 2.0 examples included in this section.

EXA M P L E DESC RIP T IO N

Starting an Executable at a Specific Time Defines a task that starts Notepad at a specified time.

Starting an Executable Daily Defines a task that starts Notepad daily.

Starting an Executable on System Boot Defines a task that starts Notepad when the system is
booted.

Starting an Executable Weekly Defines a task that starts Notepad on a weekly basis.

Starting an Executable When a Task is Registered Defines a task that starts Notepad when the task is
registered.

Starting an Executable When a User Logs On Defines a task that starts Notepad when a user logs on.

Enumerating Tasks and Displaying Task Information Enumerates through all the tasks on the local computer and
displays each task's state.

The following table lists Task Scheduler 1.0 examples included in this section.

EXA M P L E DESC RIP T IO N

Creating a Task Using NewWorkItem Example Creates a new task.

Enumerating Tasks Example Enumerates all the tasks on the local computer.

Starting a Task Example Starts a known task.

Editing a Work Item using Property Pages Displays the property pages of a task for editing.

Retrieving Work Item Property Examples A set of examples that show how to retrieve properties that
apply to all types of work items.

Setting Work Item Property Examples A set of examples that show how to set properties that
apply to all types of work items.

Retrieving Task Property Examples A set of examples that show how to retrieve properties
unique to tasks.
EXA M P L E DESC RIP T IO N

Setting Task Property Examples A set of examples that show how to set properties unique to
tasks.

Retrieving a Task Page Example Retrieves and displays the general task page of a known
task.

Creating a New Trigger Creates a new trigger for a known task.

Creating an Idle Trigger Example Creates an event-based idle trigger for a known task.

Terminating a Task Example Terminates a task while it is running.

Retrieving Trigger Strings Example Retrieves the trigger string of all triggers associated with a
known task.

Related topics
Task Scheduler
About The Task Scheduler
Starting an Executable at a Specific Time
8/8/2022 • 2 minutes to read • Edit Online

Writing a task that starts an executable at a specific time is done by defining a time trigger and an executable
action.

Start Boundary
It is important to note that a time trigger is different from other time-based triggers in that it is fired when the
trigger is activated by its start boundary. Other time-based triggers are activated by their start boundary, but
they do not start performing their actions (in this case starting an executable) until a scheduled date is reached.

Time Trigger Examples


The following examples start Notepad 30 seconds after the task is activated:
Time Trigger Example (C++)
Time Trigger Example (Scripting)
Time Trigger Example (XML)

Related topics
Using the Task Scheduler
Time Trigger Example (Scripting)
8/8/2022 • 3 minutes to read • Edit Online

This scripting example shows how to create a task that runs Notepad at a specific time. The task contains a time-
based trigger that specifies a start boundary to activate the task, an executable action that runs Notepad, and an
end boundary that deactivates the task.
The following procedure describes how to schedule a task to start an executable at a specific time.
To Schedule Notepad to star t at a Specific Time
1. Create a TaskSer vice object. This object allows you to create the task in a specified folder.
2. Get a task folder and create a task. Use the TaskSer vice.GetFolder method to get the folder where the task
is stored and the TaskSer vice.NewTask method to create the TaskDefinition object that represents the
task.
3. Define information about the task using the TaskDefinition object. Use the TaskDefinition.Settings
property to define the settings that determine how the Task Scheduler service performs the task and the
TaskDefinition.RegistrationInfo property to define the information that describes the task.
4. Create a time-based trigger using the TaskDefinition.Triggers property. This property provides access to
the TriggerCollection object. Use the TriggerCollection.Create method (specifying the type of trigger
you want to create) to create a time-based trigger. As you create the trigger, set the start boundary and end
boundary of the trigger to activate and deactivate the trigger. The start boundary specifies when the task's
action will be performed.
5. Create an action for the task to execute by using the TaskDefinition.Actions property. This property
provides access to the ActionCollection object. Use the ActionCollection.Create method to specify the
type of action you want to create. This example uses an ExecAction object, which represents an action that
executes a command-line operation.
6. Register the task using the TaskFolder.RegisterTaskDefinition method. For this example the task will start
Notepad at the current time plus 30 seconds.
The following VBScript example shows how to schedule a task to execute Notepad 30 seconds after the task is
registered.

'------------------------------------------------------------------
' This sample schedules a task to start notepad.exe 30 seconds
' from the time the task is registered.
'------------------------------------------------------------------

' A constant that specifies a time-based trigger.


const TriggerTypeTime = 1
' A constant that specifies an executable action.
const ActionTypeExec = 0

'********************************************************
' Create the TaskService object.
Set service = CreateObject("Schedule.Service")
call service.Connect()

'********************************************************
' Get a folder to create a task definition in.
Dim rootFolder
Set rootFolder = service.GetFolder("\")

' The taskDefinition variable is the TaskDefinition object.


' The taskDefinition variable is the TaskDefinition object.
Dim taskDefinition
' The flags parameter is 0 because it is not supported.
Set taskDefinition = service.NewTask(0)

'********************************************************
' Define information about the task.

' Set the registration info for the task by


' creating the RegistrationInfo object.
Dim regInfo
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Start notepad at a certain time"
regInfo.Author = "Author Name"

'********************************************************
' Set the principal for the task
Dim principal
Set principal = taskDefinition.Principal

' Set the logon type to interactive logon


principal.LogonType = 3

' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.Enabled = True
settings.StartWhenAvailable = True
settings.Hidden = False

'********************************************************
' Create a time-based trigger.
Dim triggers
Set triggers = taskDefinition.Triggers

Dim trigger
Set trigger = triggers.Create(TriggerTypeTime)

' Trigger variables that define when the trigger is active.


Dim startTime, endTime

Dim time
time = DateAdd("s", 30, Now) 'start time = 30 seconds from now
startTime = XmlTime(time)

time = DateAdd("n", 5, Now) 'end time = 5 minutes from now


endTime = XmlTime(time)

WScript.Echo "startTime :" & startTime


WScript.Echo "endTime :" & endTime

trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.ExecutionTimeLimit = "PT5M" 'Five minutes
trigger.Id = "TimeTriggerId"
trigger.Enabled = True

'***********************************************************
' Create the action for the task to execute.

' Add an action to the task to run notepad.exe.


Dim Action
Set Action = taskDefinition.Actions.Create( ActionTypeExec )
Action.Path = "C:\Windows\System32\notepad.exe"

WScript.Echo "Task definition created. About to submit the task..."

'***********************************************************
'***********************************************************
' Register (create) the task.

call rootFolder.RegisterTaskDefinition( _
"Test TimeTrigger", taskDefinition, 6, , , 3)

WScript.Echo "Task submitted."

'------------------------------------------------------------------
' Used to get the time for the trigger
' startBoundary and endBoundary.
' Return the time in the correct format:
' YYYY-MM-DDTHH:MM:SS.
'------------------------------------------------------------------
Function XmlTime(t)
Dim cSecond, cMinute, CHour, cDay, cMonth, cYear
Dim tTime, tDate

cSecond = "0" & Second(t)


cMinute = "0" & Minute(t)
cHour = "0" & Hour(t)
cDay = "0" & Day(t)
cMonth = "0" & Month(t)
cYear = Year(t)

tTime = Right(cHour, 2) & ":" & Right(cMinute, 2) & _


":" & Right(cSecond, 2)
tDate = cYear & "-" & Right(cMonth, 2) & "-" & Right(cDay, 2)
XmlTime = tDate & "T" & tTime
End Function

Related topics
Using the Task Scheduler
Time Trigger Example (C++)
8/8/2022 • 6 minutes to read • Edit Online

This C++ example shows how to create a task that is scheduled to execute Notepad at a specified time. The task
contains a time-based trigger that specifies a start boundary and an end boundary for the task. The task also
contains an action that specifies the task to execute Notepad. The task is registered using an interactive logon
type, which means the task runs under the security context of the user who runs the application. The task also
contains idle settings, which specifies how Task Scheduler performs tasks when the computer is in an idle
condition.
The following procedure describes how to schedule a task to start an executable at a certain time.
To schedule Notepad to star t at a specific time
1. Initialize COM and set general COM security.
2. Create the ITaskSer vice object.
This object allows you to create tasks in a specified folder.
3. Get a task folder to create a task in.
Use the ITaskSer vice::GetFolder method to get the folder, and the ITaskSer vice::NewTask method to
create the ITaskDefinition object.
4. Define information about the task using the ITaskDefinition object, such as the registration information
for the task.
Use the RegistrationInfo proper ty of ITaskDefinition and other properties of the ITaskDefinition
interface to define the task information.
5. Create a time-based trigger using the Triggers proper ty of ITaskDefinition to access the
ITriggerCollection for the task.
Use the ITriggerCollection::Create method (specifying the type of trigger you want to create) to create
a time-based trigger. This allows you to set the start boundary and the end boundary for the trigger so
that the task's actions will be scheduled to execute at a specified time.
6. Create an action for the task to execute by using the Actions proper ty of ITaskDefinition to access the
IActionCollection interface for the task.
Use the IActionCollection::Create method to specify the type of action that you want to create. This
example uses an IExecAction object, which represents an action that executes a command-line
operation.
7. Register the task using the ITaskFolder ::RegisterTaskDefinition method.
The following C++ example shows how to schedule a task to execute Notepad one minute after the task is
registered.

/********************************************************************
This sample schedules a task to start notepad.exe 1 minute from the
time the task is registered.
********************************************************************/

#define _WIN32_DCOM
#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
#include <wincred.h>
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "comsupp.lib")
#pragma comment(lib, "credui.lib")

using namespace std;

int __cdecl wmain()


{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}

// Set general COM security levels.


hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);

if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create a name for the task.
LPCWSTR wszTaskName = L"Time Trigger Test Task";

// Get the windows directory and set the path to notepad.exe.


wstring wstrExecutablePath = _wgetenv( L"WINDIR");
wstrExecutablePath += L"\\SYSTEM32\\NOTEPAD.EXE";

// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to create an instance of ITaskService: %x", hr);
CoUninitialize();
return 1;
}

// Connect to the task service.


// Connect to the task service.
hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the pointer to the root task folder. This folder will hold the
// new task that is registered.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );
if( FAILED(hr) )
{
printf("Cannot get Root folder pointer: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// If the same task exists, remove it.


pRootFolder->DeleteTask( _bstr_t( wszTaskName), 0 );

// Create the task definition object to create the task.


ITaskDefinition *pTask = NULL;
hr = pService->NewTask( 0, &pTask );

pService->Release(); // COM clean up. Pointer is no longer used.


if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
pRootFolder->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the registration info for setting the identification.
IRegistrationInfo *pRegInfo= NULL;
hr = pTask->get_RegistrationInfo( &pRegInfo );
if( FAILED(hr) )
{
printf("\nCannot get identification pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pRegInfo->put_Author( L"Author Name" );


pRegInfo->Release();
if( FAILED(hr) )
{
printf("\nCannot put identification info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create the principal for the task - these credentials
// are overwritten with the credentials passed to RegisterTaskDefinition
IPrincipal *pPrincipal = NULL;
hr = pTask->get_Principal( &pPrincipal );
if( FAILED(hr) )
if( FAILED(hr) )
{
printf("\nCannot get principal pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set up principal logon type to interactive logon


hr = pPrincipal->put_LogonType( TASK_LOGON_INTERACTIVE_TOKEN );
pPrincipal->Release();
if( FAILED(hr) )
{
printf("\nCannot put principal info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create the settings for the task
ITaskSettings *pSettings = NULL;
hr = pTask->get_Settings( &pSettings );
if( FAILED(hr) )
{
printf("\nCannot get settings pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set setting values for the task.


hr = pSettings->put_StartWhenAvailable(VARIANT_TRUE);
pSettings->Release();
if( FAILED(hr) )
{
printf("\nCannot put setting information: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set the idle settings for the task.


IIdleSettings *pIdleSettings = NULL;
hr = pSettings->get_IdleSettings( &pIdleSettings );
if( FAILED(hr) )
{
printf("\nCannot get idle setting information: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pIdleSettings->put_WaitTimeout(L"PT5M");
pIdleSettings->Release();
if( FAILED(hr) )
{
printf("\nCannot put idle setting information: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Get the trigger collection to insert the time trigger.
ITriggerCollection *pTriggerCollection = NULL;
hr = pTask->get_Triggers( &pTriggerCollection );
if( FAILED(hr) )
{
printf("\nCannot get trigger collection: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Add the time trigger to the task.


ITrigger *pTrigger = NULL;
hr = pTriggerCollection->Create( TASK_TRIGGER_TIME, &pTrigger );
pTriggerCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

ITimeTrigger *pTimeTrigger = NULL;


hr = pTrigger->QueryInterface(
IID_ITimeTrigger, (void**) &pTimeTrigger );
pTrigger->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed for ITimeTrigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pTimeTrigger->put_Id( _bstr_t( L"Trigger1" ) );


if( FAILED(hr) )
printf("\nCannot put trigger ID: %x", hr);

hr = pTimeTrigger->put_EndBoundary( _bstr_t(L"2015-05-02T08:00:00") );
if( FAILED(hr) )
printf("\nCannot put end boundary on trigger: %x", hr);

// Set the task to start at a certain time. The time


// format should be YYYY-MM-DDTHH:MM:SS(+-)(timezone).
// For example, the start boundary below
// is January 1st 2005 at 12:05
hr = pTimeTrigger->put_StartBoundary( _bstr_t(L"2005-01-01T12:05:00") );
pTimeTrigger->Release();
if( FAILED(hr) )
{
printf("\nCannot add start boundary to trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Add an action to the task. This task will execute notepad.exe.
IActionCollection *pActionCollection = NULL;

// Get the task action collection pointer.


hr = pTask->get_Actions( &pActionCollection );
if( FAILED(hr) )
{
printf("\nCannot get Task collection pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Create the action, specifying that it is an executable action.


IAction *pAction = NULL;
hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction );
pActionCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create the action: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

IExecAction *pExecAction = NULL;


// QI for the executable task pointer.
hr = pAction->QueryInterface(
IID_IExecAction, (void**) &pExecAction );
pAction->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed for IExecAction: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set the path of the executable to notepad.exe.


hr = pExecAction->put_Path( _bstr_t( wstrExecutablePath.c_str() ) );
pExecAction->Release();
if( FAILED(hr) )
{
printf("\nCannot put action path: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;
hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(),
_variant_t(),
TASK_LOGON_INTERACTIVE_TOKEN,
_variant_t(L""),
&pRegisteredTask);
if( FAILED(hr) )
{
printf("\nError saving the Task : %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}
}

printf("\n Success! Task successfully registered. " );

// Clean up.
pRootFolder->Release();
pTask->Release();
pRegisteredTask->Release();
CoUninitialize();
return 0;
}

Related topics
Using the Task Scheduler
Time Trigger Example (XML)
8/8/2022 • 2 minutes to read • Edit Online

The XML in this example defines a task that starts Notepad at a specific time.
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 at a specific time


The following XML example shows how to define a task with a single execution action (starting Notepad), a
single time trigger that starts the task at a specified time, and several other task settings that affect how the task
is handled by the Task Scheduler.

<?xml version="1.0" ?>


<!--
This sample schedules a task to start notepad.exe at a specific time.
-->
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2005-10-11T13:21:17-08:00</Date>
<Author>AuthorName</Author>
<Version>1.0.0</Version>
<Description>Task starts after at a specified time.</Description>
</RegistrationInfo>
<Triggers>
<TimeTrigger>
<StartBoundary>2005-10-11T13:21:17-08:00</StartBoundary>
<EndBoundary>2006-01-01T00:00:00-08:00</EndBoundary>
<Enabled>true</Enabled>
<ExecutionTimeLimit>PT5M</ExecutionTimeLimit>
</TimeTrigger>
</Triggers>
<Principals>
<Principal>
<UserId>Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>

TaskScheduler Schema Elements


The following 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.
TimeTrigger : Defines the time trigger. In this case, three child elements are used: the start and end
boundaries that specify when the trigger is activated and deactivated, and the execution time limit that
specifies the maximum amount of time in which the task can be started by the trigger. The Star tBoundar y
element is a required element for time triggers.
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 (in this case, running Notepad).

Related topics
Using the Task Scheduler
Starting an Executable Daily
8/8/2022 • 2 minutes to read • Edit Online

Writing a task that starts an executable on a daily basis is done by defining a daily trigger and an executable
action.

Daily Triggers
Daily triggers use their start boundary to activate the trigger and to specify the time of day that the task is run.
Once the trigger is activated, the triggers interval is used to indicate if the task runs daily, every other day, every
third day, or so on.

Daily Trigger Examples


The following examples show how to create tasks that start Notepad on a daily basis.
Daily Trigger Example (Scripting)
Daily Trigger Example (C++)
Daily Trigger Example (XML)

Related topics
Using the Task Scheduler
Daily Trigger Example (Scripting)
8/8/2022 • 3 minutes to read • Edit Online

This scripting example shows how to create a task that runs Notepad at 8:00 AM every day. The task contains a
daily trigger that specifies a start boundary to activate the trigger and to specify the time of day that the task
runs, a trigger interval to specify that the task runs every day, and an end boundary to deactivates the trigger.
The example also shows how to set a repetition pattern for the trigger to repeat the task. The task also contains
an executable action that runs Notepad.
The following procedure describes how to schedule a task to start an executable at 8:00 AM every day. (These
steps correspond to the code comments included in the example code.)
To schedule Notepad to star t at 8:00 AM ever y day
1. Create a TaskSer vice object. This object allows you to create the task in a specified folder.
2. Get a task folder and create a task. Use the TaskSer vice.GetFolder method to get the folder where the task
is stored and the TaskSer vice.NewTask method to create the TaskDefinition object that represents the
task.
3. Define information about the task using the TaskDefinition object. Use the TaskDefinition.Settings
property to define the settings that determine how the Task Scheduler service performs the task and the
TaskDefinition.RegistrationInfo property to define the information that describes the task.
4. Create a daily trigger using the TaskDefinition.Triggers property. This property provides access to the
TriggerCollection object that is used to create the trigger. Use the TriggerCollection.Create method
(specifying the type of trigger you want to create) to create a daily trigger. As you create the trigger, set the
start boundary to activate the trigger and specify the time of day that the task runs, the interval between the
days, and the end boundary to deactivate the trigger. The example below shows how to set a repetition
pattern for the trigger to repeat the task.
5. Create an action for the task to execute by using the TaskDefinition.Actions property. This property
provides access to the ActionCollection object used to create the action. Use the ActionCollection.Create
method to specify the type of action you want to create. This example uses an ExecAction object, which
represents an action that executes a command-line operation.
6. Register the task using the TaskFolder.RegisterTaskDefinition method. For this example the task will start
Notepad at 8:00 AM every day.
The following VBScript example shows how to schedule a task to execute Notepad every day at 8:00 AM.

'------------------------------------------------------------------
' This sample schedules a task to start on a daily basis.
'------------------------------------------------------------------

' A constant that specifies a daily trigger.


const TriggerTypeDaily = 2
' A constant that specifies an executable action.
const ActionTypeExec = 0

'********************************************************
' Create the TaskService object.
Set service = CreateObject("Schedule.Service")
call service.Connect()

'********************************************************
' Get a folder to create a task definition in.
Dim rootFolder
Set rootFolder = service.GetFolder("\")
Set rootFolder = service.GetFolder("\")

' The taskDefinition variable is the TaskDefinition object.


Dim taskDefinition
' The flags parameter is 0 because it is not supported.
Set taskDefinition = service.NewTask(0)

'********************************************************
' Define information about the task.

' Set the registration info for the task by


' creating the RegistrationInfo object.
Dim regInfo
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Start notepad at 8:00AM daily"
regInfo.Author = "Administrator"

' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.Enabled = True
settings.StartWhenAvailable = True
settings.Hidden = False

'********************************************************
' Create a daily trigger. Note that the start boundary
' specifies the time of day that the task starts and the
' interval specifies what days the task is run.
Dim triggers
Set triggers = taskDefinition.Triggers

Dim trigger
Set trigger = triggers.Create(TriggerTypeDaily)

' Trigger variables that define when the trigger is active


' and the time of day that the task is run. The format of
' this time is YYYY-MM-DDTHH:MM:SS
Dim startTime, endTime

Dim time
startTime = "2006-05-02T08:00:00" 'Task runs at 8:00 AM
endTime = "2015-05-02T08:00:00"

WScript.Echo "startTime :" & startTime


WScript.Echo "endTime :" & endTime

trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.DaysInterval = 1 'Task runs every day.
trigger.Id = "DailyTriggerId"
trigger.Enabled = True

' Set the task repetition pattern for the task.


' This will repeat the task 5 times.
Dim repetitionPattern
Set repetitionPattern = trigger.Repetition
repetitionPattern.Duration = "PT4M"
repetitionPattern.Interval = "PT1M"

'***********************************************************
' Create the action for the task to execute.

' Add an action to the task to run notepad.exe.


Dim Action
Set Action = taskDefinition.Actions.Create( ActionTypeExec )
Action.Path = "C:\Windows\System32\notepad.exe"

WScript.Echo "Task definition created. About to submit the task..."


'***********************************************************
' Register (create) the task.

call rootFolder.RegisterTaskDefinition( _
"Test Daily Trigger", taskDefinition, 6, , , 3)

WScript.Echo "Task submitted."

Related topics
Using the Task Scheduler
Daily Trigger Example (C++)
8/8/2022 • 6 minutes to read • Edit Online

This C++ example shows how to create a task that is scheduled to execute Notepad on a daily basis. The task
contains a daily trigger that specifies a start boundary and a day interval for the task to start. The example also
shows how to set a repetition pattern for the trigger to repeat the task. The task also contains an action that
specifies the task to execute Notepad.
The following procedure describes how to schedule a task to start an executable on a daily basis.
To schedule Notepad to star t on a daily basis
1. Initialize COM and set general COM security.
2. Create the ITaskSer vice object.
This object allows you to create tasks in a specified folder.
3. Get a task folder to create a task in.
Use the ITaskSer vice::GetFolder method to get the folder, and the ITaskSer vice::NewTask method to
create the ITaskDefinition object.
4. Define information about the task using the ITaskDefinition object, such as the registration information
for the task.
Use the RegistrationInfo proper ty of ITaskDefinition and other properties of the ITaskDefinition
interface to define the task information.
5. Create a daily trigger using the Triggers proper ty of ITaskDefinition to access the
ITriggerCollection interface for the task.
Use the ITriggerCollection::Create method to specify that you want to create a daily trigger. You can set
the start boundary and the days interval for the trigger so that the task's actions will be scheduled to
execute at a specified time on certain days. The example also shows how to set a repetition pattern for the
trigger to repeat the task.
6. Create an action for the task to execute by using the Actions proper ty of ITaskDefinition to access the
IActionCollection interface for the task.
Use the IActionCollection::Create method to specify the type of action that you want to create. This
example uses an IExecAction object, which represents an action that executes a command-line
operation.
7. Register the task using the ITaskFolder ::RegisterTaskDefinition method.
The following C++ example shows how to schedule a task to execute Notepad on a daily basis.

/********************************************************************
This sample schedules a task to start on a daily basis.
********************************************************************/

#define _WIN32_DCOM

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
#include <comdef.h>
#include <wincred.h>
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "comsupp.lib")
#pragma comment(lib, "credui.lib")

using namespace std;

int __cdecl wmain()


{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}

// Set general COM security levels.


hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);

if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create a name for the task.
LPCWSTR wszTaskName = L"Daily Trigger Test Task";

// Get the windows directory and set the path to notepad.exe.


wstring wstrExecutablePath = _wgetenv( L"WINDIR");
wstrExecutablePath += L"\\SYSTEM32\\NOTEPAD.EXE";

// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to create an instance of ITaskService: %x", hr);
CoUninitialize();
return 1;
}

// Connect to the task service.


hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the pointer to the root task folder. This folder will hold the
// new task that is registered.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// If the same task exists, remove it.


pRootFolder->DeleteTask( _bstr_t( wszTaskName), 0 );

// Create the task builder object to create the task.


ITaskDefinition *pTask = NULL;
hr = pService->NewTask( 0, &pTask );

pService->Release(); // COM clean up. Pointer is no longer used.


if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
pRootFolder->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the registration info for setting the identification.
IRegistrationInfo *pRegInfo= NULL;
hr = pTask->get_RegistrationInfo( &pRegInfo );
if( FAILED(hr) )
{
printf("\nCannot get identification pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pRegInfo->put_Author( _bstr_t(L"Author Name") );


pRegInfo->Release(); // COM clean up. Pointer is no longer used.
if( FAILED(hr) )
{
printf("\nCannot put identification info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the trigger collection to insert the daily trigger.
ITriggerCollection *pTriggerCollection = NULL;
hr = pTask->get_Triggers( &pTriggerCollection );
if( FAILED(hr) )
{
printf("\nCannot get trigger collection: %x", hr );
pRootFolder->Release();
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Add the daily trigger to the task.


ITrigger *pTrigger = NULL;
hr = pTriggerCollection->Create( TASK_TRIGGER_DAILY, &pTrigger );
pTriggerCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create the trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

IDailyTrigger *pDailyTrigger = NULL;


hr = pTrigger->QueryInterface(
IID_IDailyTrigger, (void**) &pDailyTrigger );
pTrigger->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call on IDailyTrigger failed: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pDailyTrigger->put_Id( _bstr_t( L"Trigger1" ) );


if( FAILED(hr) )
printf("\nCannot put trigger ID: %x", hr);

// Set the task to start daily at a certain time. The time


// format should be YYYY-MM-DDTHH:MM:SS(+-)(timezone).
// For example, the start boundary below
// is January 1st 2005 at 12:05
hr = pDailyTrigger->put_StartBoundary( _bstr_t(L"2005-01-01T12:05:00") );
if( FAILED(hr) )
printf("\nCannot put start boundary: %x", hr);

// Set the time when the trigger is deactivated.


hr = pDailyTrigger->put_EndBoundary( _bstr_t(L"2007-05-02T12:05:00") );
if( FAILED(hr) )
printf("\nCannot put the end boundary: %x", hr);

// Define the interval for the daily trigger. An interval of 2 produces an


// every other day schedule
hr = pDailyTrigger->put_DaysInterval( (short)2 );
if( FAILED(hr) )
{
printf("\nCannot put days interval: %x", hr );
pRootFolder->Release();
pDailyTrigger->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Add a repetition to the trigger so that it repeats


// five times.
IRepetitionPattern *pRepetitionPattern = NULL;
hr = pDailyTrigger->get_Repetition( &pRepetitionPattern );
pDailyTrigger->Release();
if( FAILED(hr) )
{
printf("\nCannot get repetition pattern: %x", hr );
printf("\nCannot get repetition pattern: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pRepetitionPattern->put_Duration( _bstr_t(L"PT4M"));
if( FAILED(hr) )
{
printf("\nCannot put repetition duration: %x", hr );
pRootFolder->Release();
pRepetitionPattern->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pRepetitionPattern->put_Interval( _bstr_t(L"PT1M"));
pRepetitionPattern->Release();
if( FAILED(hr) )
{
printf("\nCannot put repetition interval: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Add an action to the task. This task will execute notepad.exe.
IActionCollection *pActionCollection = NULL;

// Get the task action collection pointer.


hr = pTask->get_Actions( &pActionCollection );
if( FAILED(hr) )
{
printf("\nCannot get task collection pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Create the action, specifying that it is an executable action.


IAction *pAction = NULL;
hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction );
pActionCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create action: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

IExecAction *pExecAction = NULL;


hr = pAction->QueryInterface(
IID_IExecAction, (void**) &pExecAction );
pAction->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed for IExecAction: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}
}

// Set the path of the executable to notepad.exe.


hr = pExecAction->put_Path( _bstr_t( wstrExecutablePath.c_str() ) );
pExecAction->Release();
if( FAILED(hr) )
{
printf("\nCannot put the executable path: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Securely get the user name and password. The task will
// be created to run with the credentials from the supplied
// user name and password.
CREDUI_INFO cui;
TCHAR pszName[CREDUI_MAX_USERNAME_LENGTH] = TEXT("");
TCHAR pszPwd[CREDUI_MAX_PASSWORD_LENGTH] = TEXT("");
BOOL fSave;
DWORD dwErr;

cui.cbSize = sizeof(CREDUI_INFO);
cui.hwndParent = NULL;
// Ensure that MessageText and CaptionText identify
// what credentials to use and which application requires them.
cui.pszMessageText = TEXT("Account information for task registration:");
cui.pszCaptionText = TEXT("Enter Account Information for Task Registration");
cui.hbmBanner = NULL;
fSave = FALSE;

// Create the UI asking for the credentials.


dwErr = CredUIPromptForCredentials(
&cui, // CREDUI_INFO structure
TEXT(""), // Target for credentials
NULL, // Reserved
0, // Reason
pszName, // User name
CREDUI_MAX_USERNAME_LENGTH, // Max number for user name
pszPwd, // Password
CREDUI_MAX_PASSWORD_LENGTH, // Max number for password
&fSave, // State of save check box
CREDUI_FLAGS_GENERIC_CREDENTIALS | // Flags
CREDUI_FLAGS_ALWAYS_SHOW_UI |
CREDUI_FLAGS_DO_NOT_PERSIST);

if(dwErr)
{
cout << "Did not get credentials." << endl;
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;
hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(_bstr_t(pszName)),
_variant_t(_bstr_t(pszPwd)),
TASK_LOGON_PASSWORD,
_variant_t(L""),
&pRegisteredTask);
if( FAILED(hr) )
{
printf("\nError saving the Task : %x", hr );
printf("\nError saving the Task : %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 1;
}

printf("\n Success! Task successfully registered. " );

// Clean up
pRootFolder->Release();
pTask->Release();
pRegisteredTask->Release();
CoUninitialize();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
return 0;
}

Related topics
Using the Task Scheduler
Daily Trigger Example (XML)
8/8/2022 • 2 minutes to read • Edit Online

The XML in this example defines a task that starts Notepad at 8:00 AM every day. The example also shows how
to set a repetition pattern for the trigger to repeat the task.
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 day 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 day 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 daily basis.
-->
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2005-10-11T13:21:17-08:00</Date>
<Author>AuthorName</Author>
<Version>1.0.0</Version>
<Description>Notepad starts every day.</Description>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2005-10-11T13:21:17-08:00</StartBoundary>
<EndBoundary>2006-01-01T00:00:00-08:00</EndBoundary>
<Repetition>
<Interval>PT1M</Interval>
<Duration>PT4M</Duration>
</Repetition>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal>
<UserId>Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>
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 daily calendar trigger. In this case, four child elements are used: the start and end boundaries
that specify when the trigger is activated and deactivated, the daily schedule, and the repetition pattern
for the task. The Star tBoundar y element is a required element for calendar triggers.
ScheduleByDay
Defines the daily schedule. In this case, the interval is set to perform the task every day.
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
Starting an Executable When a Task is Registered
8/8/2022 • 2 minutes to read • Edit Online

Writing a task that starts an executable when a task is registered is done by defining a registration trigger and
an executable action.

Registration Trigger
Registration triggers start a task as soon as it is registered. You can also specify a delay for the registration
trigger, which starts a task after a specific amount of time (the delay) after the task is registered. The delay is
specified in the Delay property of the IRegistrationTrigger interface (RegistrationTrigger for scripting).

NOTE
When a task with a registration trigger is updated, the task will execute after the update occurs.

Registration Trigger Examples


The following examples start Notepad when a task is registered:
Registration Trigger Example (Scripting)
Registration Trigger Example (C++)
Registration Trigger Example (XML)

Related topics
Using the Task Scheduler
Registration Trigger Example (Scripting)
8/8/2022 • 2 minutes to read • Edit Online

This scripting example shows how to create a task that is scheduled to execute Notepad when a task is
registered. The task contains a registration trigger that specifies a start boundary and an end boundary for the
task. The start boundary specifies when the trigger is activated. The task also contains an action that specifies
the task to execute Notepad.

NOTE
When a task with a registration trigger is updated, the task will execute after the update occurs.

The following procedure describes how to schedule an executable such as Notepad to start when a task is
registered.
To schedule Notepad to star t when a task is registered
1. Create a TaskSer vice object. This object allows you to create the task in a specified folder.
2. Get a task folder and create a task. Use the TaskSer vice.GetFolder method to get the folder where the task
is stored and the TaskSer vice.NewTask method to create the TaskDefinition object that represents the
task.
3. Define information about the task using the TaskDefinition object. Use the TaskDefinition.Settings
property to define the settings that determine how the Task Scheduler service performs the task and the
TaskDefinition.RegistrationInfo property to define the information that describes the task.
4. Create a registration trigger using the TaskDefinition.Triggers property. This property provides access to
the TriggerCollection object. Use the TriggerCollection.Create method (specifying the type of trigger
that you want to create) to create a registration trigger.
5. Create an action for the task to execute by using the TaskDefinition.Actions property. This property
provides access to the ActionCollection object. Use the ActionCollection.Create method to specify the
type of action that you want to create. This example uses an ExecAction object, which represents an action
that starts an executable.
6. Register the task using the TaskFolder.RegisterTaskDefinition method.
The following VBScript example shows how to create a task that schedules Notepad to execute when the task is
registered.

'---------------------------------------------------------
' This sample schedules a task to start notepad.exe when
' the task is registered.
'---------------------------------------------------------

' A constant that specifies a registration trigger.


const TriggerTypeRegistration = 7
' A constant that specifies an executable action.
const ActionTypeExecutable = 0

'********************************************************
' Create the TaskService object.
Set service = CreateObject("Schedule.Service")
call service.Connect()
'********************************************************
' Get a folder to create a task definition in.
Dim rootFolder
Set rootFolder = service.GetFolder("\")

' The taskDefinition variable is the TaskDefinition object.


Dim taskDefinition
' The flags parameter is 0 because it is not supported.
Set taskDefinition = service.NewTask(0)

'********************************************************
' Define information about the task.

' Set the registration info for the task by


' creating the RegistrationInfo object.
Dim regInfo
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Start Notepad when the task is registered."
regInfo.Author = "Author Name"

' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.StartWhenAvailable = True

'********************************************************
' Create a registration trigger.
Dim triggers
Set triggers = taskDefinition.Triggers

Dim trigger
Set trigger = triggers.Create(TriggerTypeRegistration)

trigger.ExecutionTimeLimit = "PT5M" 'Five minutes


trigger.Id = "RegistrationTriggerId"

'***********************************************************
' Create the action for the task to execute.

' Add an action to the task. The action executes Notepad.


Dim Action
Set Action = taskDefinition.Actions.Create( ActionTypeExecutable )
Action.Path = "C:\Windows\System32\notepad.exe"

WScript.Echo "Task definition created. About to submit the task..."

'***********************************************************
' Register (create) the task.

call rootFolder.RegisterTaskDefinition( _
"Test Registration Trigger", taskDefinition, 6, , , 3)

WScript.Echo "Task submitted."

Related topics
Using the Task Scheduler
Registration Trigger Example (C++)
8/8/2022 • 5 minutes to read • Edit Online

This C++ example shows how to create a task that is scheduled to execute Notepad when a task is registered.
The task contains a registration trigger that specifies a start boundary and an end boundary for the task and
also a delay for the task. The start boundary specifies when the trigger is activated, and the delay sets the
amount of time between when the task is registered and when the task is started. The task also contains an
action that specifies the task to execute Notepad.

NOTE
When a task with a registration trigger is updated, the task will execute after the update occurs.

The following procedure describes how to schedule a task to start an executable when the task is registered.
To schedule Notepad to star t when a task is registered
1. Initialize COM and set general COM security.
2. Create the ITaskSer vice object. This object allows you to create tasks in a specified folder.
3. Get a task folder to create a task in. Use the ITaskSer vice::GetFolder method to get the folder, and the
ITaskSer vice::NewTask method to create the ITaskDefinition object.
4. Define information about the task using the ITaskDefinition object, such as the registration information for
the task. Use the RegistrationInfo proper ty of ITaskDefinition and other properties of the
ITaskDefinition interface to define the task information.
5. Create a registration trigger using the Triggers proper ty of ITaskDefinition to access the
ITriggerCollection for the task. Use the ITriggerCollection::Create method (specifying the type of trigger
you want to create) to create a registration trigger.
6. Create an action for the task to execute by using the Actions proper ty of ITaskDefinition to access the
IActionCollection interface for the task. Use the IActionCollection::Create method to specify the type of
action that you want to create. This example uses an IExecAction object, which represents an action that
executes a command-line operation.
7. Register the task using the ITaskFolder ::RegisterTaskDefinition method.
The following C++ example shows how to schedule a task to execute Notepad 30 seconds after the task is
registered.

/********************************************************************
This sample schedules a task to start notepad.exe 30 seconds after
the task is registered.
********************************************************************/

#define _WIN32_DCOM

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
#include <wincred.h>
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "comsupp.lib")
#pragma comment(lib, "credui.lib")

using namespace std;

int __cdecl wmain()


{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}

// Set general COM security levels.


hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);

if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create a name for the task.
LPCWSTR wszTaskName = L"Registration Trigger Test Task";

// Get the windows directory and set the path to notepad.exe.


wstring wstrExecutablePath = _wgetenv( L"WINDIR");
wstrExecutablePath += L"\\SYSTEM32\\NOTEPAD.EXE";

// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to create an instance of ITaskService: %x", hr);
CoUninitialize();
return 1;
}

// Connect to the task service.


hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
return 1;
}

// ------------------------------------------------------
// Get the pointer to the root task folder. This folder will hold the
// new task that is registered.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// If the same task exists, remove it.


hr = pRootFolder->DeleteTask( _bstr_t( wszTaskName), 0 );

// Create the task builder object to create the task.


ITaskDefinition *pTask = NULL;
hr = pService->NewTask( 0, &pTask );

pService->Release(); // COM clean up. Pointer is no longer used.


if (FAILED(hr))
{
printf("Failed to create a task definition: %x", hr);
pRootFolder->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the registration info for setting the identification.
IRegistrationInfo *pRegInfo= NULL;
hr = pTask->get_RegistrationInfo( &pRegInfo );
if( FAILED(hr) )
{
printf("\nCannot get identification pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pRegInfo->put_Author( L"Author Name" );


pRegInfo->Release();
if( FAILED(hr) )
{
printf("\nCannot put identification info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create the principal for the task
IPrincipal *pPrincipal = NULL;
hr = pTask->get_Principal( &pPrincipal );
if( FAILED(hr) )
{
printf("\nCannot get principal pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set up principal information:


// Set up principal information:
hr = pPrincipal->put_Id( _bstr_t(L"Principal1") );
if( FAILED(hr) )
printf("\nCannot put the principal ID: %x", hr);

hr = pPrincipal->put_LogonType( TASK_LOGON_INTERACTIVE_TOKEN );
if( FAILED(hr) )
printf("\nCannot put principal logon type: %x", hr);

// Run the task with the least privileges (LUA)


hr = pPrincipal->put_RunLevel( TASK_RUNLEVEL_LUA );
pPrincipal->Release();
if( FAILED(hr) )
{
printf("\nCannot put principal run level: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create the settings for the task
ITaskSettings *pSettings = NULL;
hr = pTask->get_Settings( &pSettings );
if( FAILED(hr) )
{
printf("\nCannot get settings pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set setting values for the task.


hr = pSettings->put_StartWhenAvailable(VARIANT_TRUE);
pSettings->Release();
if( FAILED(hr) )
{
printf("\nCannot put setting info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the trigger collection to insert the registration trigger.
ITriggerCollection *pTriggerCollection = NULL;
hr = pTask->get_Triggers( &pTriggerCollection );
if( FAILED(hr) )
{
printf("\nCannot get trigger collection: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Add the registration trigger to the task.


ITrigger *pTrigger = NULL;
hr = pTriggerCollection->Create( TASK_TRIGGER_REGISTRATION, &pTrigger );
pTriggerCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create a registration trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
CoUninitialize();
return 1;
}

IRegistrationTrigger *pRegistrationTrigger = NULL;


hr = pTrigger->QueryInterface(
IID_IRegistrationTrigger, (void**) &pRegistrationTrigger );
pTrigger->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed on IRegistrationTrigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pRegistrationTrigger->put_Id( _bstr_t( L"Trigger1" ) );


if( FAILED(hr) )
printf("\nCannot put trigger ID: %x", hr);

// Define the delay for the registration trigger.


hr = pRegistrationTrigger->put_Delay( L"PT30S" );
pRegistrationTrigger->Release();
if( FAILED(hr) )
{
printf("\nCannot put registration trigger delay: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Add an Action to the task. This task will execute notepad.exe.
IActionCollection *pActionCollection = NULL;

// Get the task action collection pointer.


hr = pTask->get_Actions( &pActionCollection );
if( FAILED(hr) )
{
printf("\nCannot get Task collection pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Create the action, specifying that it is an executable action.


IAction *pAction = NULL;
hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction );
pActionCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create action: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

IExecAction *pExecAction = NULL;

// QI for the executable task pointer.


hr = pAction->QueryInterface(
IID_IExecAction, (void**) &pExecAction );
pAction->Release();
if( FAILED(hr) )
{
{
printf("\nQueryInterface call failed for IExecAction: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set the path of the executable to notepad.exe.


hr = pExecAction->put_Path( _bstr_t( wstrExecutablePath.c_str() ) );
pExecAction->Release();
if( FAILED(hr) )
{
printf("\nCannot put the action executable path: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;
hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(),
_variant_t(),
TASK_LOGON_INTERACTIVE_TOKEN,
_variant_t(L""),
&pRegisteredTask);
if( FAILED(hr) )
{
printf("\nError saving the Task : %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

printf("\n Success! Task successfully registered. " );

// Clean up.
pRootFolder->Release();
pTask->Release();
pRegisteredTask->Release();
CoUninitialize();
return 0;
}

Related topics
Using the Task Scheduler
Registration Trigger Example (XML)
8/8/2022 • 2 minutes to read • Edit Online

The XML in this example defines a task that starts Notepad when the task is registered.
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>.

NOTE
When a task with a registration trigger is updated, the task will execute after the update occurs.

To define a task to start Notepad on registration


The following XML example shows how to define a task with a single execution action (starting Notepad), a
single registration trigger that starts the task when it is registered, and several other task settings that affect
how the task is handled by the Task Scheduler.

NOTE
When a task with a registration trigger is updated, the task will execute after the update occurs.
<?xml version="1.0" ?>
<!--
This sample schedules a task to start notepad.exe when
the task is registered.
-->
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2005-10-11T13:21:17-08:00</Date>
<Author>AuthorName</Author>
<Version>1.0.0</Version>
<Description>Task starts after registration.</Description>
</RegistrationInfo>
<Triggers>
<RegistrationTrigger>
</RegistrationTrigger>
</Triggers>
<Principals>
<Principal>
<UserId>Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>

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.
RegistrationTrigger : Defines the registration trigger. In this case, only two child elements are used: the start
and end boundaries that specify when the trigger is activated and deactivated.
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 the task performs. In this case, running Notepad.

Related topics
Using the Task Scheduler
Starting an Executable Weekly
8/8/2022 • 2 minutes to read • Edit Online

Writing a task that starts an executable on a weekly basis is done by defining a weekly trigger and an executable
action.

Weekly Triggers
Weekly triggers use their start boundary to activate the trigger and to specify the time of day that the task is
run. When the trigger is activated, the trigger also specifies when the task is run during the week and if the task
runs every week, every other week, every third week, and so on.

Weekly Trigger Examples


The following examples show how to create tasks that start Notepad on a weekly basis.
Weekly Trigger Example (Scripting)
Weekly Trigger Example (C++)
Weekly Trigger Example (XML)

Related topics
Using the Task Scheduler
Weekly Trigger Example (Scripting)
8/8/2022 • 3 minutes to read • Edit Online

This scripting example shows how to create a task that runs Notepad at 8:00 AM on Monday of every week. The
task contains a daily trigger that specifies when the task runs and an executable action that runs Notepad.
The following procedure describes how to schedule a task to start an executable at 8:00 AM on Monday of every
week.
To schedule Notepad to star t at 8:00 AM on Monday of ever y week
1. Create a TaskSer vice object. This object allows you to create the task in a specified folder.
2. Get a task folder and create a task. Use the TaskSer vice.GetFolder method to get the folder where the
task is stored and the TaskSer vice.NewTask method to create the TaskDefinition object that
represents the task.
3. Define information about the task using the TaskDefinition object. Use the TaskDefinition.Settings
property to define the settings that determine how the Task Scheduler service performs the task and the
TaskDefinition.RegistrationInfo property to define the information that describes the task.
4. Create a weekly trigger using the TaskDefinition.Triggers property. This property provides access to
the TriggerCollection object that is used to create the trigger.
Use the TriggerCollection.Create method (specifying the type of trigger you want to create) to create a
weekly trigger.
Set the WeeklyTrigger.Star tBoundar y property to specify when the trigger is activated and the time of
the day when the task is run. In this example the trigger is activated on January 1, 2005 and the task runs
at 8:00 AM.
Set the WeeklyTrigger.EndBoundar y property to specify when the trigger is deactivated. In this
example the trigger is deactivated on January 1, 2015.
Set the WeeklyTrigger.DaysOfWeek property to specify the days of the week on which the task runs. In
this example the task is run on Monday.
Set the WeeklyTrigger.WeeksInter val property to specify the interval between the weeks in the
schedule. In this example the task runs every week.
5. Create an action for the task to execute by using the TaskDefinition.Actions property. This property
provides access to the ActionCollection object used to create the action. Use the
ActionCollection.Create method to specify the type of action you want to create. This example uses an
ExecAction object, which represents an action that executes a command-line operation.
6. Register the task using the TaskFolder.RegisterTaskDefinition method. For this example the task will
start Notepad at 8:00 AM on Monday of every week.
The following VBScript example shows how to schedule a task to execute Notepad every day at 8:00 AM.

'------------------------------------------------------------------
' This sample schedules a task to start on a weekly basis.
'------------------------------------------------------------------

' A constant that specifies a weekly trigger.


const TriggerTypeWeekly = 3
' A constant that specifies an executable action.
const ActionTypeExec = 0

'********************************************************
' Create the TaskService object.
Set service = CreateObject("Schedule.Service")
call service.Connect()

'********************************************************
' Get a folder to create a task definition in.
Dim rootFolder
Set rootFolder = service.GetFolder("\")

' The taskDefinition variable is the TaskDefinition object.


Dim taskDefinition
' The flags parameter is 0 because it is not supported.
Set taskDefinition = service.NewTask(0)

'********************************************************
' Define information about the task.

' Set the registration info for the task by


' creating the RegistrationInfo object.
Dim regInfo
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Start Notepad weekly."
regInfo.Author = "Administrator"

' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.Enabled = True
settings.StartWhenAvailable = True
settings.Hidden = False

'********************************************************
' Create a weekly trigger. Note that the start boundary
' specifies the time of day that the task starts, the
' day-of-week specfies on what day of the week the task
' runs, and the interval specifies what weeks the task runs.
Dim triggers
Set triggers = taskDefinition.Triggers

Dim trigger
Set trigger = triggers.Create(TriggerTypeWeekly)

' Trigger variables that define when the trigger is active


' and the time of day that the task is run. The format of
' this tims is YYYY-MM-DDTHH:MM:SS
Dim startTime, endTime

Dim time
startTime = "2006-05-02T08:00:00" 'Task runs at 8:00 AM
endTime = "2015-05-02T08:00:00"

WScript.Echo "startTime :" & startTime


WScript.Echo "endTime :" & endTime

trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.DaysOfWeek = 1
trigger.WeeksInterval = 1 'Task runs every week.
trigger.Id = "WeeklyTriggerId"
trigger.Enabled = True

'***********************************************************
' Create the action for the task to execute.
' Create the action for the task to execute.

' Add an action to the task to run notepad.exe.


Dim Action
Set Action = taskDefinition.Actions.Create( ActionTypeExec )
Action.Path = "C:\Windows\System32\notepad.exe"

WScript.Echo "Task definition created. About to submit the task..."

'***********************************************************
' Register (create) the task.

call rootFolder.RegisterTaskDefinition( _
"Test Weekly Trigger", taskDefinition, 6, , , 3)

WScript.Echo "Task submitted."

Related topics
Using the Task Scheduler
Weekly Trigger Example (C++)
8/8/2022 • 6 minutes to read • Edit Online

This C++ example shows how to create a task that is scheduled to execute Notepad on a weekly basis. The task
contains a weekly trigger that specifies a start boundary, a weeks interval, and a day of the week for the task to
start on. The task also contains an action that specifies the task to execute Notepad.
The following procedure describes how to schedule a task to start an executable on a weekly basis.
To schedule Notepad to star t on a weekly basis
1. Initialize COM and set general COM security.
2. Create the ITaskSer vice object.
This object allows you to create tasks in a specified folder.
3. Get a task folder to create a task in.
Use the ITaskSer vice::GetFolder method to get the folder, and the ITaskSer vice::NewTask method to
create the ITaskDefinition object.
4. Define information about the task using the ITaskDefinition object, such as the registration information
for the task.
Use the RegistrationInfo proper ty of ITaskDefinition and other properties of the ITaskDefinition
interface to define the task information.
5. Create a weekly trigger using the Triggers proper ty of ITaskDefinition to access the
ITriggerCollection interface for the task.
Use the ITriggerCollection::Create method to specify that you want to create a weekly trigger. You can
set the start boundary, the weeks interval, and the day of the week for the IWeeklyTrigger trigger so
that the task's actions will be scheduled to execute at a specified time on a certain day of the week.
6. Create an action for the task to execute by using the Actions proper ty of ITaskDefinition to access the
IActionCollection interface for the task.
Use the IActionCollection::Create method to specify the type of action that you want to create. This
example uses an IExecAction object, which represents an action that executes a command-line
operation.
7. Register the task using the ITaskFolder ::RegisterTaskDefinition method.
The following C++ example shows how to schedule a task to execute Notepad on a weekly basis.

/********************************************************************
This sample schedules a task to start on a weekly basis.
********************************************************************/

#define _WIN32_DCOM

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
#include <wincred.h>
// Include the task header file.
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "comsupp.lib")
#pragma comment(lib, "credui.lib")

using namespace std;

void main(void)
{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return;
}

// Set general COM security levels.


hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);

if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return;
}

// ------------------------------------------------------
// Create a name for the task.
LPCWSTR wszTaskName = L"Weekly Trigger Task";

// Get the windows directory and set the path to notepad.exe.


wstring wstrExecutablePath = _wgetenv( L"WINDIR");
wstrExecutablePath += L"\\SYSTEM32\\NOTEPAD.EXE";

// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to create an instance of ITaskService: %x", hr);
CoUninitialize();
return;
}

// Connect to the task service.


hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
pService->Release();
CoUninitialize();
return;
}

// ------------------------------------------------------
// Get the pointer to the root task folder.
// This folder will hold the new task that is registered.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
pService->Release();
CoUninitialize();
return;
}

// If the same task exists, remove it.


pRootFolder->DeleteTask( _bstr_t( wszTaskName), 0 );

// Create the task builder object to create the task.


ITaskDefinition *pTask = NULL;
hr = pService->NewTask( 0, &pTask );

pService->Release(); // COM clean up. Pointer is no longer used.


if (FAILED(hr))
{
printf("Failed to create a task definition: %x", hr);
pRootFolder->Release();
CoUninitialize();
return;
}

// ------------------------------------------------------
// Get the registration info for setting the identification.
IRegistrationInfo *pRegInfo= NULL;
hr = pTask->get_RegistrationInfo( &pRegInfo );
if( FAILED(hr) )
{
printf("\nCannot get identification pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

hr = pRegInfo->put_Author( L"Author Name" );


pRegInfo->Release(); // COM clean up. Pointer is no longer used.
if( FAILED(hr) )
{
printf("\nCannot put identification info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

// ------------------------------------------------------
// Get the trigger collection to insert the weekly trigger.
ITriggerCollection *pTriggerCollection = NULL;
hr = pTask->get_Triggers( &pTriggerCollection );
if( FAILED(hr) )
{
printf("\nCannot get trigger collection: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}
}

ITrigger *pTrigger = NULL;


hr = pTriggerCollection->Create( TASK_TRIGGER_WEEKLY, &pTrigger );
pTriggerCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create the trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

IWeeklyTrigger *pWeeklyTrigger = NULL;


hr = pTrigger->QueryInterface(
IID_IWeeklyTrigger, (void**) &pWeeklyTrigger );
pTrigger->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call for IWeeklyTrigger failed: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

hr = pWeeklyTrigger->put_Id( _bstr_t( L"Trigger1" ) );


if( FAILED(hr) )
printf("\nCannot put trigger ID: %x", hr);

// Set the task to start weekly at a certain time. The time


// format should be YYYY-MM-DDTHH:MM:SS(+-)(timezone).
// For example, the start boundary below is January 1st 2005 at
// 12:05
hr = pWeeklyTrigger->put_StartBoundary( _bstr_t(L"2005-01-01T12:05:00") );
if( FAILED(hr) )
printf("\nCannot put the start boundary: %x", hr);

// Set the time when the trigger is deactivated.


hr = pWeeklyTrigger->put_EndBoundary( _bstr_t(L"2007-01-01T12:05:00") );
if( FAILED(hr) )
printf("\nCannot put the end boundary: %x", hr);

// Define the interval for the weekly trigger.


// An interval of 2 produces an
// every other week schedule
hr = pWeeklyTrigger->put_WeeksInterval( (short)2 );
if( FAILED(hr) )
{
printf("\nCannot put weeks interval: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

hr = pWeeklyTrigger->put_DaysOfWeek( (short)2 ); // Runs on Monday


pWeeklyTrigger->Release();
if( FAILED(hr) )
{
printf("\nCannot put days of week interval: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

// ------------------------------------------------------
// ------------------------------------------------------
// Add an Action to the task. This task will execute notepad.exe.
IActionCollection *pActionCollection = NULL;

// Get the task action collection pointer.


hr = pTask->get_Actions( &pActionCollection );
if( FAILED(hr) )
{
printf("\nCannot get Task collection pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

// Create the action, specifying that it is an executable action.


IAction *pAction = NULL;
hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction );
pActionCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create the action: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

IExecAction *pExecAction = NULL;


// QI for the executable task pointer.
hr = pAction->QueryInterface(
IID_IExecAction, (void**) &pExecAction );
pAction->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed on IExecAction: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

// Set the path of the executable to notepad.exe.


hr = pExecAction->put_Path( _bstr_t( wstrExecutablePath.c_str() ) );
pExecAction->Release();
if( FAILED(hr) )
{
printf("\nCannot add path for executable action: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return;
}

// ------------------------------------------------------
// Securely get the user name and password. The task will
// be created to run with the credentials from the supplied
// user name and password.
CREDUI_INFO cui;
TCHAR pszName[CREDUI_MAX_USERNAME_LENGTH] = "";
TCHAR pszPwd[CREDUI_MAX_PASSWORD_LENGTH] = "";
BOOL fSave;
DWORD dwErr;

cui.cbSize = sizeof(CREDUI_INFO);
cui.hwndParent = NULL;
// Ensure that MessageText and CaptionText identify
// what credentials to use and which application requires them.
cui.pszMessageText = TEXT("Account information for task registration:");
cui.pszCaptionText = TEXT("Enter Account Information for Task Registration");
cui.pszCaptionText = TEXT("Enter Account Information for Task Registration");
cui.hbmBanner = NULL;
fSave = FALSE;

// Create the UI asking for the credentials.


dwErr = CredUIPromptForCredentials(
&cui, // CREDUI_INFO structure
TEXT(""), // Target for credentials
NULL, // Reserved
0, // Reason
pszName, // User name
CREDUI_MAX_USERNAME_LENGTH, // Max number for user name
pszPwd, // Password
CREDUI_MAX_PASSWORD_LENGTH, // Max number for password
&fSave, // State of save check box
CREDUI_FLAGS_GENERIC_CREDENTIALS | // Flags
CREDUI_FLAGS_ALWAYS_SHOW_UI |
CREDUI_FLAGS_DO_NOT_PERSIST);

if(dwErr)
{
cout << "Did not get credentials." << endl;
CoUninitialize();
return;
}

// ------------------------------------------------------
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;
hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(_bstr_t(pszName)),
_variant_t(_bstr_t(pszPwd)),
TASK_LOGON_PASSWORD,
_variant_t(L""),
&pRegisteredTask);
if( FAILED(hr) )
{
printf("\nError saving the Task : %x", hr );
pRootFolder->Release();
pTask->Release();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
CoUninitialize();
return;
}

printf("\n Success! Task succesfully registered. " );

// Clean up
pRootFolder->Release();
pTask->Release();
pRegisteredTask->Release();
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
CoUninitialize();
return;
}

Related topics
Using the Task Scheduler
Weekly Trigger Example (XML)
8/8/2022 • 2 minutes to read • Edit Online

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">
<RegistrationInfo>
<Date>2005-05-01T09:00:00</Date>
<Author>AuthorName</Author>
<Version>1.0.0</Version>
<Description>Notepad starts every other week on Monday at 8:00am.</Description>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2005-05-02T08:00:00</StartBoundary>
<EndBoundary>2006-01-01T00:00:00</EndBoundary>
<ScheduleByWeek>
<WeeksInterval>2</WeeksInterval>
<DaysOfWeek>
<Monday/>
</DaysOfWeek>
</ScheduleByWeek>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal>
<UserId>Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>
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 Star tBoundar y 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
Starting an Executable When a User Logs On
8/8/2022 • 2 minutes to read • Edit Online

Writing a task that starts an executable when a user logs on is done by defining a logon trigger and an
executable action.

Logon Trigger
Logon triggers are activated by their start boundary but they do not start the executable until a specified user
logs on. You can specify the logon trigger to start when a certain user logs on by specifying the user in the
UserId property of the ILogonTrigger interface (LogonTrigger for scripting).

LogonTrigger Examples
The following examples start Notepad after a user logs on.
Logon Trigger Example (Scripting)
Logon Trigger Example (C++)
Logon Trigger Example (XML)

Related topics
Using the Task Scheduler
Logon Trigger Example (Scripting)
8/8/2022 • 3 minutes to read • Edit Online

This scripting example shows how to create a task that is scheduled to execute Notepad when a user logs on.
The task contains a logon trigger that specifies a start boundary for the task to start and a user identifier that
specifies the user. The task is registered using the Administrators group as a security context to run the task.
The following procedure describes how to schedule an executable such as Notepad to start when a specified
user logs on.
To schedule Notepad to star t when a user logs on
1. Create a TaskSer vice object. This object allows you to create the task in a specified folder.
2. Get a task folder and create a task. Use the TaskSer vice.GetFolder method to get the folder where the task
is stored and the TaskSer vice.NewTask method to create the TaskDefinition object that represents the
task.
3. Define information about the task using the TaskDefinition object. Use the TaskDefinition.Settings
property to define the settings that determine how the Task Scheduler service performs the task and the
TaskDefinition.RegistrationInfo property to define the information that describes the task.
4. Create a logon trigger using the TaskDefinition.Triggers property. This property provides access to the
TriggerCollection object. Use the TriggerCollection.Create method (specifying the type of trigger that
you want to create) to create a logon trigger. As you create the trigger, set the start boundary and end
boundary of the trigger to activate and deactivate the trigger. You must set the UserId property for the
trigger so that the task's actions will be scheduled to execute when the specified user logs on after the start
boundary.
5. Create an action for the task to execute by using the TaskDefinition.Actions property. This property
provides access to the ActionCollection object. Use the ActionCollection.Create method to specify the
type of action that you want to create. This example uses an ExecAction object, which represents an action
that starts an executable.
6. Register the task using the TaskFolder.RegisterTaskDefinition method. This example registers the task so
that it uses the Administrators group as a security context to run the task.
The following VBScript example shows how to schedule a task to execute Notepad when a user logs on.

'---------------------------------------------------------
' This sample schedules a task to start notepad.exe when a user logs on.
'---------------------------------------------------------

' A constant that specifies a logon trigger.


const TriggerTypeLogon = 9
' A constant that specifies an executable action.
const ActionTypeExecutable = 0

'********************************************************
' Create the TaskService object.
Set service = CreateObject("Schedule.Service")
call service.Connect()

'********************************************************
' Get a folder to create a task definition in.
Dim rootFolder
Set rootFolder = service.GetFolder("\")

' The taskDefinition variable is the TaskDefinition object.


Dim taskDefinition
Dim taskDefinition
' The flags parameter is 0 because it is not supported.
Set taskDefinition = service.NewTask(0)

'********************************************************
' Define information about the task.

' Set the registration info for the task by


' creating the RegistrationInfo object.
Dim regInfo
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Task will execute Notepad when a " & _
"specified user logs on."
regInfo.Author = "Author Name"

' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.StartWhenAvailable = True

'********************************************************
' Create a logon trigger.
Dim triggers
Set triggers = taskDefinition.Triggers

Dim trigger
Set trigger = triggers.Create(TriggerTypeLogon)

' Trigger variables that define when the trigger is active.


Dim startTime, endTime
startTime = "2006-05-02T10:49:02"
endTime = "2006-05-02T10:52:02"

WScript.Echo "startTime :" & startTime


WScript.Echo "endTime :" & endTime

trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.ExecutionTimeLimit = "PT5M" ' Five minutes
trigger.Id = "LogonTriggerId"
trigger.UserId = "DOMAIN\UserName" ' Must be a valid user account

'***********************************************************
' Create the action for the task to execute.

' Add an action to the task. The action executes notepad.


Dim Action
Set Action = taskDefinition.Actions.Create( ActionTypeExecutable )
Action.Path = "C:\Windows\System32\notepad.exe"

WScript.Echo "Task definition created. About to submit the task..."

'***********************************************************
' Register (create) the task.
const createOrUpdateTask = 6
call rootFolder.RegisterTaskDefinition( _
"Test Logon Trigger", taskDefinition, createOrUpdateTask, _
"Builtin\Administrators", , 4)

WScript.Echo "Task submitted."

Related topics
Using the Task Scheduler
Logon Trigger Example (C++)
8/8/2022 • 5 minutes to read • Edit Online

This C++ example shows how to create a task that is scheduled to execute Notepad when a user logs on. The
task contains a logon trigger that specifies a start boundary for the task to start and a user identifier that
specifies the user. The task is registered using the Administrators group as a security context to run the task.
The following procedure describes how to schedule a task to start an executable when a user logs on.
To schedule Notepad to star t when a user logs on
1. Initialize COM and set general COM security.
2. Create the ITaskSer vice object.
This object allows you to create tasks in a specified folder.
3. Get a task folder to create a task in.
Use the ITaskSer vice::GetFolder method to get the folder, and the ITaskSer vice::NewTask method to
create the ITaskDefinition object.
4. Define information about the task using the ITaskDefinition object, such as the registration information
for the task.
Use the RegistrationInfo proper ty of ITaskDefinition and other properties of the ITaskDefinition
interface to define the task information.
5. Create a logon trigger using the Triggers proper ty of ITaskDefinition to access the
ITriggerCollection interface for the task.
Use the ITriggerCollection::Create method to specify that you want to create a logon trigger. You can
set the start boundary and the UserId property for the trigger so that the task's actions will be scheduled
to execute when the user logs on after the start boundary.
6. Create an action for the task to execute by using the Actions proper ty of ITaskDefinition to access the
IActionCollection interface for the task. Use the IActionCollection::Create method to specify the type
of action that you want to create. This example uses an IExecAction object, which represents an action
that executes a command-line operation.
7. Register the task using the ITaskFolder ::RegisterTaskDefinition method.
The following C++ example shows how to schedule a task to execute Notepad when a user logs on.

/**********************************************************************
This sample schedules a task to start notepad.exe when a user logs on.
**********************************************************************/

#define _WIN32_DCOM

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "comsupp.lib")
#pragma comment(lib, "comsupp.lib")

using namespace std;

int __cdecl wmain()


{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}

// Set general COM security levels.


hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);

if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create a name for the task.
LPCWSTR wszTaskName = L"Logon Trigger Test Task";

// Get the windows directory and set the path to notepad.exe.


wstring wstrExecutablePath = _wgetenv( L"WINDIR");
wstrExecutablePath += L"\\SYSTEM32\\NOTEPAD.EXE";

// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to create an instance of ITaskService: %x", hr);
CoUninitialize();
return 1;
}

// Connect to the task service.


hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}
// ------------------------------------------------------
// Get the pointer to the root task folder. This folder will hold the
// new task that is registered.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// If the same task exists, remove it.


pRootFolder->DeleteTask( _bstr_t( wszTaskName), 0 );

// Create the task builder object to create the task.


ITaskDefinition *pTask = NULL;
hr = pService->NewTask( 0, &pTask );

pService->Release(); // COM clean up. Pointer is no longer used.


if (FAILED(hr))
{
printf("Failed to create a task definition: %x", hr);
pRootFolder->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the registration info for setting the identification.
IRegistrationInfo *pRegInfo= NULL;
hr = pTask->get_RegistrationInfo( &pRegInfo );
if( FAILED(hr) )
{
printf("\nCannot get identification pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pRegInfo->put_Author(L"Author Name");
pRegInfo->Release();
if( FAILED(hr) )
{
printf("\nCannot put identification info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create the settings for the task
ITaskSettings *pSettings = NULL;
hr = pTask->get_Settings( &pSettings );
if( FAILED(hr) )
{
printf("\nCannot get settings pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set setting values for the task.


hr = pSettings->put_StartWhenAvailable(VARIANT_TRUE);
pSettings->Release();
pSettings->Release();
if( FAILED(hr) )
{
printf("\nCannot put setting info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the trigger collection to insert the logon trigger.
ITriggerCollection *pTriggerCollection = NULL;
hr = pTask->get_Triggers( &pTriggerCollection );
if( FAILED(hr) )
{
printf("\nCannot get trigger collection: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Add the logon trigger to the task.


ITrigger *pTrigger = NULL;
hr = pTriggerCollection->Create( TASK_TRIGGER_LOGON, &pTrigger );
pTriggerCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create the trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

ILogonTrigger *pLogonTrigger = NULL;


hr = pTrigger->QueryInterface(
IID_ILogonTrigger, (void**) &pLogonTrigger );
pTrigger->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed for ILogonTrigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pLogonTrigger->put_Id( _bstr_t( L"Trigger1" ) );


if( FAILED(hr) )
printf("\nCannot put the trigger ID: %x", hr);

// Set the task to start at a certain time. The time


// format should be YYYY-MM-DDTHH:MM:SS(+-)(timezone).
// For example, the start boundary below
// is January 1st 2005 at 12:05
hr = pLogonTrigger->put_StartBoundary( _bstr_t(L"2005-01-01T12:05:00") );
if( FAILED(hr) )
printf("\nCannot put the start boundary: %x", hr);

hr = pLogonTrigger->put_EndBoundary( _bstr_t(L"2015-05-02T08:00:00") );
if( FAILED(hr) )
printf("\nCannot put the end boundary: %x", hr);

// Define the user. The task will execute when the user logs on.
// The specified user must be a user on this computer.
hr = pLogonTrigger->put_UserId( _bstr_t( L"DOMAIN\\UserName" ) );
pLogonTrigger->Release();
if( FAILED(hr) )
if( FAILED(hr) )
{
printf("\nCannot add user ID to logon trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Add an Action to the task. This task will execute notepad.exe.
IActionCollection *pActionCollection = NULL;

// Get the task action collection pointer.


hr = pTask->get_Actions( &pActionCollection );
if( FAILED(hr) )
{
printf("\nCannot get Task collection pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Create the action, specifying that it is an executable action.


IAction *pAction = NULL;
hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction );
pActionCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create the action: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

IExecAction *pExecAction = NULL;


// QI for the executable task pointer.
hr = pAction->QueryInterface(
IID_IExecAction, (void**) &pExecAction );
pAction->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed for IExecAction: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set the path of the executable to notepad.exe.


hr = pExecAction->put_Path( _bstr_t( wstrExecutablePath.c_str() ) );
pExecAction->Release();
if( FAILED(hr) )
{
printf("\nCannot set path of executable: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;

hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(L"S-1-5-32-544"),
_variant_t(),
TASK_LOGON_GROUP,
_variant_t(L""),
&pRegisteredTask);
if( FAILED(hr) )
{
printf("\nError saving the Task : %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

printf("\n Success! Task successfully registered. " );

// Clean up
pRootFolder->Release();
pTask->Release();
pRegisteredTask->Release();
CoUninitialize();
return 0;
}

Related topics
Using the Task Scheduler
Logon Trigger Example (XML)
8/8/2022 • 2 minutes to read • Edit Online

The XML in this example defines a task that starts Notepad when a user logs on.
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 on system boot


The following XML example shows how to define a task with a single execution action (starting Notepad), a
single logon trigger that starts the task when a user logs on, and several other task settings that affect how the
task is handled by Task Scheduler.

NOTE
Set the value of the UserId element to a user name on the computer on which the task is registered.
<?xml version="1.0" ?>
<!--
This sample schedules a task to start notepad.exe when a user logs on.
-->
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2005-10-11T13:21:17-08:00</Date>
<Author>AuthorName</Author>
<Version>1.0.0</Version>
<Description>Starts Notepad when a specified user logs on.</Description>
</RegistrationInfo>
<Triggers>
<LogonTrigger>
<StartBoundary>2005-10-11T13:21:17-08:00</StartBoundary>
<EndBoundary>2006-01-01T00:00:00-08:00</EndBoundary>
<Enabled>true</Enabled>
<UserId>DOMAIN_NAME\UserName</UserId>
</LogonTrigger>
</Triggers>
<Principals>
<Principal>
<GroupId>Builtin\Administrators</GroupId>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>

TaskScheduler Schema Elements


The following 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.
LogonTrigger : Defines the logon trigger. In this case, three child elements are used: the start and end
boundaries that specify when the trigger is activated and deactivated, and the UserId element that identifier
of the user. The task is started when this user logs on to the computer..
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 the task performs. In this case, running Notepad.

Related topics
Using the Task Scheduler
Starting an Executable on System Boot
8/8/2022 • 2 minutes to read • Edit Online

Writing a task that starts an executable when a system is booted is done by defining a boot trigger and an
executable action.

Boot Trigger
Boot triggers are activated by their start boundary but they do not start the executable until the system is
booted. You can also specify a delay time in the boot trigger that specifies the amount of time between when the
system is booted and when the task is started. This is defined by the Delay property in the IBootTrigger
interface (BootTrigger object for scripting).

Boot Trigger Examples


The following examples start Notepad after the system is booted:
Boot Trigger Example (Scripting)
Boot Trigger Example (C++)
Boot Trigger Example (XML)

Related topics
Using the Task Scheduler
Boot Trigger Example (Scripting)
8/8/2022 • 3 minutes to read • Edit Online

This scripting example shows how to create a task that is scheduled to execute Notepad when the system is
booted. The task contains a boot trigger that specifies a start boundary and delay time for the task to start after
the system is booted. The task also contains an action that specifies the task to execute Notepad. The task is
registered using the Local Service account as a security context to run the task.
The following procedure describes how to schedule an executable such as Notepad to start when the system is
booted.
To schedule Notepad to star t when the system is booted
1. Create a TaskSer vice object. This object allows you to create the task in a specified folder.
2. Get a task folder and create a task. Use the TaskSer vice.GetFolder method to get the folder where the task
is stored and the TaskSer vice.NewTask method to create the TaskDefinition object that represents the
task.
3. Define information about the task using the TaskDefinition object. Use the TaskDefinition.Settings
property to define the settings that determine how the Task Scheduler service performs the task and the
TaskDefinition.RegistrationInfo property to define the information that describes the task.
4. Create a logon trigger using the TaskDefinition.Triggers property. This property provides access to the
TriggerCollection object. Use the TriggerCollection.Create method (specifying the type of trigger that
you want to create) to create a boot trigger. As you create the trigger, set the Star tBoundar y and
EndBoundar y properties of the trigger to activate and deactivate the trigger. You can also specify a value for
the Delay property of the boot trigger.
5. Create an action for the task to execute by using the TaskDefinition.Actions property. This property
provides access to the ActionCollection object. Use the ActionCollection.Create method to specify the
type of action that you want to create. This example uses an ExecAction object, which represents an action
that starts an executable.
6. Register the task using the TaskFolder.RegisterTaskDefinition method. The task is registered using the
Local Service account as a security context to run the task.
The following VBScript example shows how to schedule a task to execute Notepad 30 seconds after the system
is booted.

'---------------------------------------------------------
' This sample schedules a task to start notepad.exe 30 seconds after
' the system is booted.
'---------------------------------------------------------

' A constant that specifies a boot trigger.


const TriggerTypeBoot = 8
' A constant that specifies an executable action.
const ActionTypeExecutable = 0

'********************************************************
' Create the TaskService object.
Set service = CreateObject("Schedule.Service")
call service.Connect()

'********************************************************
' Get a folder to create a task definition in.
Dim rootFolder
Set rootFolder = service.GetFolder("\")
' The taskDefinition variable is the TaskDefinition object.
Dim taskDefinition
' The flags parameter is 0 because it is not supported.
Set taskDefinition = service.NewTask(0)

'********************************************************
' Define information about the task.

' Set the registration info for the task by


' creating the RegistrationInfo object.
Dim regInfo
Set regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Task will execute Notepad when " & _
"the computer is booted."
regInfo.Author = "Author Name"

' Set the task setting info for the Task Scheduler by
' creating a TaskSettings object.
Dim settings
Set settings = taskDefinition.Settings
settings.StartWhenAvailable = True

'********************************************************
' Create a boot trigger.
Dim triggers
Set triggers = taskDefinition.Triggers

Dim trigger
Set trigger = triggers.Create(TriggerTypeBoot)

' Trigger variables that define when the trigger is active.


Dim startTime, endTime
startTime = "2006-05-02T10:49:02"
endTime = "2006-05-02T10:52:02"

WScript.Echo "startTime :" & startTime


WScript.Echo "endTime :" & endTime

trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.ExecutionTimeLimit = "PT5M" ' Five minutes
trigger.Id = "BootTriggerId"
trigger.Delay = "PT30S" ' 30 Seconds

'***********************************************************
' Create the action for the task to execute.

' Add an action to the task. The action executes notepad.


Dim Action
Set Action = taskDefinition.Actions.Create( ActionTypeExecutable )
Action.Path = "C:\Windows\System32\notepad.exe"

WScript.Echo "Task definition created. About to submit the task..."

'***********************************************************
' Register (create) the task.
const createOrUpdateTask = 6
call rootFolder.RegisterTaskDefinition( _
"Test Boot Trigger", taskDefinition, createOrUpdateTask, _
"Local Service", , 5)

WScript.Echo "Task submitted."

Related topics
Using the Task Scheduler
Boot Trigger Example (C++)
8/8/2022 • 5 minutes to read • Edit Online

This topic contains a C++ code example that shows how to create a task that is scheduled to execute
Notepad.exe when the system is started. The task contains a boot trigger that specifies a start boundary and
delay time for the task to start after the system is started. The task also contains an action that specifies the task
execute Notepad.exe. The task is registered using the Local Service account as a security context to run the task.
The following procedure describes how to schedule a task to start an executable when the system is started.
To schedule Notepad to star t when the system is star ted
1. Initialize COM and set general COM security.
2. Create the ITaskSer vice object.
This object enables you to create tasks in a specified folder.
3. Get a task folder to create a task in.
Use the ITaskSer vice::GetFolder method to get the folder, and the ITaskSer vice::NewTask method to
create the ITaskDefinition object.
4. Define information about the task using the ITaskDefinition object, such as the registration information
for the task.
Use the RegistrationInfo proper ty of ITaskDefinition and other properties of the ITaskDefinition
interface to define the task information.
5. Create a boot trigger using the Triggers proper ty of ITaskDefinition to access the
ITriggerCollection for the task.
Use the ITriggerCollection::Create method to specify that you want to create a boot trigger. You can set
the start boundary and delay for the trigger so that the task actions will be scheduled to execute at a
specified time when the system is started.
6. Create an action for the task to execute by using the Actions proper ty of ITaskDefinition to access the
IActionCollection collection for the task.
Use the IActionCollection::Create method to specify the type of action you want to create. This
example uses an IExecAction object, which represents an action that executes a command-line
operation.
7. Register the task using the ITaskFolder ::RegisterTaskDefinition method.
The following C++ code example shows how to schedule a task to execute Notepad.exe 30 seconds after the
system is started.

/********************************************************************
This sample schedules a task to start Notepad.exe 30 seconds after
the system is started.
********************************************************************/

#define _WIN32_DCOM

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <stdio.h>
#include <comdef.h>
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "comsupp.lib")

using namespace std;

int __cdecl wmain()


{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}

// Set general COM security levels.


hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);

if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create a name for the task.
LPCWSTR wszTaskName = L"Boot Trigger Test Task";

// Get the Windows directory and set the path to Notepad.exe.


wstring wstrExecutablePath = _wgetenv( L"WINDIR");
wstrExecutablePath += L"\\SYSTEM32\\NOTEPAD.EXE";

// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to create an instance of ITaskService: %x", hr);
CoUninitialize();
return 1;
}

// Connect to the task service.


hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the pointer to the root task folder.
// This folder will hold the new task that is registered.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// If the same task exists, remove it.


pRootFolder->DeleteTask( _bstr_t( wszTaskName), 0 );

// Create the task builder object to create the task.


ITaskDefinition *pTask = NULL;
hr = pService->NewTask( 0, &pTask );

pService->Release(); // COM clean up. Pointer is no longer used.


if (FAILED(hr))
{
printf("Failed to create a task definition: %x", hr);
pRootFolder->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the registration info for setting the identification.
IRegistrationInfo *pRegInfo= NULL;
hr = pTask->get_RegistrationInfo( &pRegInfo );
if( FAILED(hr) )
{
printf("\nCannot get identification pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pRegInfo->put_Author(L"Author Name");
pRegInfo->Release();
if( FAILED(hr) )
{
printf("\nCannot put identification info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create the settings for the task
ITaskSettings *pSettings = NULL;
hr = pTask->get_Settings( &pSettings );
if( FAILED(hr) )
{
printf("\nCannot get settings pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set setting values for the task.


hr = pSettings->put_StartWhenAvailable(VARIANT_TRUE);
pSettings->Release();
if( FAILED(hr) )
{
printf("\nCannot put setting info: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the trigger collection to insert the boot trigger.
ITriggerCollection *pTriggerCollection = NULL;
hr = pTask->get_Triggers( &pTriggerCollection );
if( FAILED(hr) )
{
printf("\nCannot get trigger collection: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Add the boot trigger to the task.


ITrigger *pTrigger = NULL;
hr = pTriggerCollection->Create( TASK_TRIGGER_BOOT, &pTrigger );
pTriggerCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create the trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

IBootTrigger *pBootTrigger = NULL;


hr = pTrigger->QueryInterface(
IID_IBootTrigger, (void**) &pBootTrigger );
pTrigger->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed for IBootTrigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

hr = pBootTrigger->put_Id( _bstr_t( L"Trigger1" ) );


if( FAILED(hr) )
printf("\nCannot put the trigger ID: %x", hr);

// Set the task to start at a certain time. The time


// format should be YYYY-MM-DDTHH:MM:SS(+-)(timezone).
// For example, the start boundary below
// is January 1st 2005 at 12:05
hr = pBootTrigger->put_StartBoundary( _bstr_t(L"2005-01-01T12:05:00") );
if( FAILED(hr) )
printf("\nCannot put the start boundary: %x", hr);

hr = pBootTrigger->put_EndBoundary( _bstr_t(L"2015-05-02T08:00:00") );
hr = pBootTrigger->put_EndBoundary( _bstr_t(L"2015-05-02T08:00:00") );
if( FAILED(hr) )
printf("\nCannot put the end boundary: %x", hr);

// Delay the task to start 30 seconds after system start.


hr = pBootTrigger->put_Delay( L"PT30S" );
pBootTrigger->Release();
if( FAILED(hr) )
{
printf("\nCannot put delay for boot trigger: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Add an Action to the task. This task will execute Notepad.exe.
IActionCollection *pActionCollection = NULL;

// Get the task action collection pointer.


hr = pTask->get_Actions( &pActionCollection );
if( FAILED(hr) )
{
printf("\nCannot get Task collection pointer: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Create the action, specifying it as an executable action.


IAction *pAction = NULL;
hr = pActionCollection->Create( TASK_ACTION_EXEC, &pAction );
pActionCollection->Release();
if( FAILED(hr) )
{
printf("\nCannot create the action: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

IExecAction *pExecAction = NULL;


// QI for the executable task pointer.
hr = pAction->QueryInterface(
IID_IExecAction, (void**) &pExecAction );
pAction->Release();
if( FAILED(hr) )
{
printf("\nQueryInterface call failed for IExecAction: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

// Set the path of the executable to Notepad.exe.


hr = pExecAction->put_Path( _bstr_t( wstrExecutablePath.c_str() ) );
pExecAction->Release();
if( FAILED(hr) )
{
printf("\nCannot set path of executable: %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}
}

// ------------------------------------------------------
// Save the task in the root folder.
IRegisteredTask *pRegisteredTask = NULL;
VARIANT varPassword;
varPassword.vt = VT_EMPTY;
hr = pRootFolder->RegisterTaskDefinition(
_bstr_t( wszTaskName ),
pTask,
TASK_CREATE_OR_UPDATE,
_variant_t(L"Local Service"),
varPassword,
TASK_LOGON_SERVICE_ACCOUNT,
_variant_t(L""),
&pRegisteredTask);
if( FAILED(hr) )
{
printf("\nError saving the Task : %x", hr );
pRootFolder->Release();
pTask->Release();
CoUninitialize();
return 1;
}

printf("\n Success! Task successfully registered. " );

// Clean up.
pRootFolder->Release();
pTask->Release();
pRegisteredTask->Release();
CoUninitialize();
return 0;
}

Related topics
Using the Task Scheduler
Boot Trigger Example (XML)
8/8/2022 • 2 minutes to read • Edit Online

The XML in this example defines a task that starts Notepad when the system is booted.
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 on system boot


The following XML example shows how to define a task with a single execution action (starting Notepad), a
single boot trigger that starts the task when the system is booted, and several other task settings that affect how
the task is handled by the Task Scheduler.

<?xml version="1.0" ?>


<!--
This sample schedules a task to start notepad.exe when
the system is booted.
-->
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2005-10-11T13:21:17-08:00</Date>
<Author>AuthorName</Author>
<Version>1.0.0</Version>
<Description>Starts Notepad on system boot.</Description>
</RegistrationInfo>
<Triggers>
<BootTrigger>
<StartBoundary>2005-10-11T13:21:17-08:00</StartBoundary>
<EndBoundary>2006-01-01T00:00:00-08:00</EndBoundary>
<Enabled>true</Enabled>
<ExecutionTimeLimit>PT5M</ExecutionTimeLimit>
</BootTrigger>
</Triggers>
<Principals>
<Principal>
<UserId>Administrator</UserId>
<LogonType>InteractiveToken</LogonType>
</Principal>
</Principals>
<Settings>
<Enabled>true</Enabled>
<AllowStartOnDemand>true</AllowStartOnDemand>
<AllowHardTerminate>true</AllowHardTerminate>
</Settings>
<Actions>
<Exec>
<Command>notepad.exe</Command>
</Exec>
</Actions>
</Task>

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.
BootTrigger : Defines the boot trigger. In this case only two child elements are used: the start and end
boundaries that specify when the trigger is activated and deactivated.
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 the task performs. In this case, running Notepad.

Related topics
Using the Task Scheduler
Enumerating Tasks and Displaying Task Information
8/8/2022 • 2 minutes to read • Edit Online

Displaying information about a task, such as the task name, state, or the last time the task was run, is done by
enumerating through running tasks or the tasks in a task folder and displaying the desired information.

Accessing Properties of Registered Tasks


To display a registered task's property value, you must connect to the Task Scheduler service, and then get an
instance of the task folder that contains the tasks you want information about. You then get a collection of all the
registered tasks in the task folder. Then you enumerate through each registered task and get and display a
property value for each task.

Accessing Properties of Running Tasks


To display a running task's property value, you must connect to the Task Scheduler service, and then get a
collection of all the running tasks (including or excluding hidden tasks). Then you enumerate through each
running task and get and display a property value for each task.

Example
The following examples enumerate tasks and display the name and state of the tasks:
Displaying Task Names and States (Scripting)
Displaying Task Names and State (C++)

Related topics
Using the Task Scheduler
Displaying Task Names and States (Scripting)
8/8/2022 • 2 minutes to read • Edit Online

This scripting example shows how to enumerate tasks in a task folder and display property values from each
task.
The following procedure describes how to display task names and states for all the tasks in a task folder.
To display task names and state for all the tasks in a task folder
1. Create the TaskSer vice object.
This object allows you to connect to the Task Scheduler service and access a specific task folder.
2. Get a task folder that holds the tasks you want information about.
Use the TaskSer vice.GetFolder method to get the folder.
3. Get the collection of tasks from the folder.
Use the TaskFolder.GetTasks method to get the collection of tasks (RegisteredTaskCollection ).
4. Get the number of tasks in the collection and enumerate through each task in the collection.
Use the RegisteredTaskCollection collection of objects to get a RegisteredTask object instance. Each
instance will contain a task in the collection. You can then display the information (property values) from
each registered task.
The following VBScript example shows how to enumerate through a collection of registered tasks in the root
task folder and display the name and state for each task.
'---------------------------------------------------------
' This sample enumerates through the tasks on the local computer and
' displays their name and state.
'---------------------------------------------------------

' Create the TaskService object.


Set service = CreateObject("Schedule.Service")
call service.Connect()

' Get the task folder that contains the tasks.


Dim rootFolder
Set rootFolder = service.GetFolder("\")

Dim taskCollection
Set taskCollection = rootFolder.GetTasks(0)

Dim numberOfTasks
numberOfTasks = taskCollection.Count

If numberOfTasks = 0 Then
Wscript.Echo "No tasks are registered."
Else
WScript.Echo "Number of tasks registered: " & numberOfTasks

Dim registeredTask
For Each registeredTask In taskCollection
WScript.Echo "Task Name: " & registeredTask.Name

Dim taskState
Select Case registeredTask.State
Case "0"
taskState = "Unknown"
Case "1"
taskState = "Disabled"
Case "2"
taskState = "Queued"
Case "3"
taskState = "Ready"
Case "4"
taskState = "Running"
End Select

WScript.Echo " Task State: " & taskState


Next
End If

Related topics
Using the Task Scheduler
Displaying Task Names and States (C++)
8/8/2022 • 5 minutes to read • Edit Online

These two C++ examples show how to enumerate tasks. One example shows how to display information for
tasks in a task folder, and the other examples shows how to display information for all running tasks.
The following procedure describes how to display task names and state for all the tasks in a task folder.
To display task names and state for all the tasks in a task folder
1. Initialize COM and set general COM security.
2. Create the ITaskSer vice object.
This object allows you to connect to the Task Scheduler service and access a specific task folder.
3. Get a task folder that holds the tasks you want information about.
Use the ITaskSer vice::GetFolder method to get the folder.
4. Get the collection of tasks from the folder.
Use the ITaskFolder ::GetTasks method to get the collection of tasks (IRegisteredTaskCollection ).
5. Get the number of tasks in the collection, and enumerate through each task in the collection.
Use the Item Proper ty of IRegisteredTaskCollection to get an IRegisteredTask instance. Each
instance will contain a task in the collection. You can then display the information (property values) from
each registered task.
The following C++ example shows how to display the name and state of all the tasks in the root task folder.

/********************************************************************
This sample enumerates through the tasks on the local computer and
displays their name and state.
********************************************************************/

#define _WIN32_DCOM

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "comsupp.lib")

using namespace std;

int __cdecl wmain()


{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}
}

// Set general COM security levels.


hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);

if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
CoUninitialize();
return 1;
}

// Connect to the task service.


hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Get the pointer to the root task folder.
ITaskFolder *pRootFolder = NULL;
hr = pService->GetFolder( _bstr_t( L"\\") , &pRootFolder );

pService->Release();
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
CoUninitialize();
return 1;
}

// -------------------------------------------------------
// Get the registered tasks in the folder.
IRegisteredTaskCollection* pTaskCollection = NULL;
hr = pRootFolder->GetTasks( NULL, &pTaskCollection );

pRootFolder->Release();
if( FAILED(hr) )
{
printf("Cannot get the registered tasks.: %x", hr);
CoUninitialize();
CoUninitialize();
return 1;
}

LONG numTasks = 0;
hr = pTaskCollection->get_Count(&numTasks);

if( numTasks == 0 )
{
printf("\nNo Tasks are currently running" );
pTaskCollection->Release();
CoUninitialize();
return 1;
}

printf("\nNumber of Tasks : %d", numTasks );

TASK_STATE taskState;

for(LONG i=0; i < numTasks; i++)


{
IRegisteredTask* pRegisteredTask = NULL;
hr = pTaskCollection->get_Item( _variant_t(i+1), &pRegisteredTask );

if( SUCCEEDED(hr) )
{
BSTR taskName = NULL;
hr = pRegisteredTask->get_Name(&taskName);
if( SUCCEEDED(hr) )
{
printf("\nTask Name: %S", taskName);
SysFreeString(taskName);

hr = pRegisteredTask->get_State(&taskState);
if (SUCCEEDED (hr) )
printf("\n\tState: %d", taskState);
else
printf("\n\tCannot get the registered task state: %x", hr);
}
else
{
printf("\nCannot get the registered task name: %x", hr);
}
pRegisteredTask->Release();
}
else
{
printf("\nCannot get the registered task item at index=%d: %x", i+1, hr);
}
}

pTaskCollection->Release();
CoUninitialize();
return 0;
}

The following procedure describes how to display task names and state for all running tasks.
To display task names and state for all running tasks
1. Initialize COM and set general COM security.
2. Create the ITaskSer vice object.
This object allows you to connect to the Task Scheduler service and access a specific task folder.
3. Use the ITaskSer vice::GetRunningTasks method to get a collection of all the running tasks
(IRunningTaskCollection ). You can specify to get instances of running task either including or excluding
hidden tasks.
4. Get the number of tasks in the collection, and enumerate through each task in the collection.
Use the Item proper ty of IRunningTaskCollection to get an IRunningTask instance. Each instance
will contain a task in the collection. You can then display the information (property values) from each
registered task.
The following C++ example shows how to display the name and state of all the running tasks, including hidden
tasks.

/********************************************************************
This sample enumerates through all running tasks on the local computer and
displays their name and state.
********************************************************************/

#define _WIN32_DCOM

#include <windows.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
// Include the task header file.
#include <taskschd.h>
#pragma comment(lib, "taskschd.lib")
#pragma comment(lib, "comsupp.lib")

using namespace std;

int __cdecl wmain()


{
// ------------------------------------------------------
// Initialize COM.
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if( FAILED(hr) )
{
printf("\nCoInitializeEx failed: %x", hr );
return 1;
}

// Set general COM security levels.


hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
0,
NULL);

if( FAILED(hr) )
{
printf("\nCoInitializeSecurity failed: %x", hr );
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Create an instance of the Task Service.
ITaskService *pService = NULL;
hr = CoCreateInstance( CLSID_TaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskService,
(void**)&pService );
if (FAILED(hr))
{
printf("Failed to CoCreate an instance of the TaskService class: %x", hr);
CoUninitialize();
return 1;
}

// Connect to the task service.


hr = pService->Connect(_variant_t(), _variant_t(),
_variant_t(), _variant_t());
if( FAILED(hr) )
{
printf("ITaskService::Connect failed: %x", hr );
pService->Release();
CoUninitialize();
return 1;
}

// Get the running tasks.


IRunningTaskCollection* pRunningTasks = NULL;
hr = pService->GetRunningTasks(TASK_ENUM_HIDDEN, &pRunningTasks);

pService->Release();
if( FAILED(hr) )
{
printf("Cannot get Root Folder pointer: %x", hr );
CoUninitialize();
return 1;
}

LONG numTasks = 0;
hr = pRunningTasks->get_Count(&numTasks);

if( numTasks == 0 )
{
printf("\nNo Tasks are currently running" );
pRunningTasks->Release();
CoUninitialize();
return 1;
}

printf("\nNumber of running tasks : %d", numTasks );

TASK_STATE taskState;

for(LONG i=0; i < numTasks; i++)


{
IRunningTask* pRunningTask = NULL;
hr = pRunningTasks->get_Item( _variant_t(i+1), &pRunningTask );

if( SUCCEEDED(hr) )
{
BSTR taskName = NULL;
hr = pRunningTask->get_Name(&taskName);
if( SUCCEEDED(hr) )
{
printf("\nTask Name: %S", taskName);
SysFreeString(taskName);

hr = pRunningTask->get_State(&taskState);
if (SUCCEEDED (hr) )
printf("\n\tState: %d", taskState);
else
printf("\n\tCannot get the registered task state: %x", hr);
}
}
else
{
printf("\nCannot get the registered task name: %x", hr);
}
pRunningTask->Release();
}
else
{
printf("\nCannot get the registered task item at index=%d: %x", i+1, hr);
}
}

pRunningTasks->Release();
CoUninitialize();
return 0;
}

Related topics
Using the Task Scheduler
Task Scheduler 1.0 Examples
8/8/2022 • 2 minutes to read • Edit Online

The examples in this section use the API introduced in Task Scheduler 1.0.

NOTE
For a Windows Server 2003, Windows XP, or Windows 2000 computer to create, monitor, or control tasks on a
Windows Vista computer, certain operations must be completed on the Windows Vista computer. For more information,
see Tasks.

The following topics provide examples that show how to use the functions introduced in Task Scheduler 1.0.

EXA M P L E DESC RIP T IO N

Creating a Task Using NewWorkItem Example Creates a new task.

Enumerating Tasks Example Enumerates all the tasks on the local computer.

Starting a Task Example Starts a known task.

Editing a Work Item using Property Pages Displays the property pages of a task for editing.

Retrieving Work Item Property Examples A set of examples that show how to retrieve properties that
apply to all types of work items.

Setting Work Item Property Examples A set of examples that show how to set properties that
apply to all types of work items.

Retrieving Task Property Examples A set of examples that show how to retrieve properties
unique to tasks.

Setting Task Property Examples A set of examples that show how to set properties unique to
tasks.

Retrieving a Task Page Example Retrieves and displays the general task page of a known
task.

Creating a New Trigger Creates a new trigger for a known task.

Creating an Idle Trigger Example Creates an event-based idle trigger for a known task.

Retrieving Trigger Strings Example Retrieves the trigger string of all triggers associated with a
known task.

Related topics
Using the Task Scheduler
Creating a Task Using NewWorkItem Example
8/8/2022 • 2 minutes to read • Edit Online

When creating a task, you will use two Task Scheduler interfaces: ITaskScheduler and ITask . You must provide
a unique name for the task, the class identifier of the task object, and the interface identifier of ITask . The class
identifier and interface identifier are shown in the code example following this topic.

NOTE
You can also create a task by calling ITaskScheduler ::AddWorkItem . When you take this route, it is your responsibility
to create an instance of the Task object (which supports the ITask interface) and then add the task with the name you
supply.

NOTE
By default, only a member of the Administrators, Backup Operators, or Server Operators group can create tasks on
Windows Server 2003. A member of the Administrators group may change the security descriptor of the Windows\Task
folder to let others create tasks.

The name you supply for the task must be unique within the Scheduled Tasks folder. If a task with the same
name already exists, ITaskScheduler ::NewWorkItem returns ERROR_FILE_EXISTS. If you get this return value,
you should specify a different name and attempt to create the task again.
The following procedure describes how to create a new work item task.
To create a new work item task
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This
example assumes that the Task Scheduler service is running.)
2. Call ITaskScheduler ::NewWorkItem to create a new task. (This method returns a pointer to an ITask
interface.)
3. Save the new task to disk by calling IPersistFile::Save . (The IPersistFile interface is a standard COM
interface supported by the ITask interface.)
4. Call ITask ::Release to release all resources. (Note that Release is an IUnknown method inherited by ITask .)

F O R A C O DE EXA M P L E O F SEE

Creating a single task C/C++ Code Example: Creating a Task Using NewWorkItem

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Creating a Task Using
NewWorkItem
8/8/2022 • 2 minutes to read • Edit Online

This example creates a single task.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <objidl.h>
#include <wchar.h>
#include <stdio.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;
ITaskScheduler *pITS;

/////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
/////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

/////////////////////////////////////////////////////////////////
// Call ITaskScheduler::NewWorkItem to create new task.
/////////////////////////////////////////////////////////////////
LPCWSTR pwszTaskName;
ITask *pITask;
IPersistFile *pIPersistFile;
pwszTaskName = L"Test Task";

hr = pITS->NewWorkItem(pwszTaskName, // Name of task


CLSID_CTask, // Class identifier
IID_ITask, // Interface identifier
(IUnknown**)&pITask); // Address of task

// interface
pITS->Release(); // Release object
if (FAILED(hr))
{
CoUninitialize();
fprintf(stderr, "Failed calling NewWorkItem, error = 0x%x\n",hr);
return 1;
}

/////////////////////////////////////////////////////////////////
// Call IUnknown::QueryInterface to get a pointer to
// IPersistFile and IPersistFile::Save to save
// the new task to disk.
/////////////////////////////////////////////////////////////////

hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

pITask->Release();
if (FAILED(hr))
{
CoUninitialize();
fprintf(stderr, "Failed calling QueryInterface, error = 0x%x\n",hr);
return 1;
}

hr = pIPersistFile->Save(NULL,
TRUE);
pIPersistFile->Release();
if (FAILED(hr))
{
CoUninitialize();
fprintf(stderr, "Failed calling Save, error = 0x%x\n",hr);
return 1;
}

CoUninitialize();
printf("Created task.\n");
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Enumerating Tasks Example
8/8/2022 • 2 minutes to read • Edit Online

To enumerate tasks, you must call ITaskScheduler ::Enum to create an enumeration object. Then, use the
enumeration object's IEnumWorkItems interface to enumerate the tasks in the Scheduled Tasks folder.
The following procedure describes how to enumerate the tasks in the Scheduled Tasks folder.
To enumerate the tasks in the Scheduled Tasks folder
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This
example assumes that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Enum to get an enumeration object.
3. Call IEnumWorkItems::Next to retrieve the tasks. (This example tries to retrieve five tasks with each call.)
4. Process the tasks returned. (This example simply prints the name of each task to the screen.
5. Release resources. Call CoTaskMemFree to free the memory used for names.

F O R A C O DE EXA M P L E O F SEE

Enumerating all the tasks in the Scheduled Tasks folder of C/C++ Code Example: Enumerating Tasks
the local computer

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Enumerating Tasks
8/8/2022 • 2 minutes to read • Edit Online

This example enumerates all the tasks in the Scheduled Tasks folder of the local computer and prints the name
of each task on the screen.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

#define TASKS_TO_RETRIEVE 5

int main(int argc, char **argv)


{
HRESULT hr = S_OK;
ITaskScheduler *pITS;

/////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and
// then call CoCreateInstance to get the Task Scheduler object.
/////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return hr;
}
}
else
{
return hr;
}

/////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Enum to get an enumeration object.
/////////////////////////////////////////////////////////////////
IEnumWorkItems *pIEnum;
hr = pITS->Enum(&pIEnum);
pITS->Release();
if (FAILED(hr))
{
CoUninitialize();
return hr;
}

/////////////////////////////////////////////////////////////////
// Call IEnumWorkItems::Next to retrieve tasks. Note that
// this example tries to retrieve five tasks for each call.
/////////////////////////////////////////////////////////////////
LPWSTR *lpwszNames;
LPWSTR *lpwszNames;
DWORD dwFetchedTasks = 0;
while (SUCCEEDED(pIEnum->Next(TASKS_TO_RETRIEVE,
&lpwszNames,
&dwFetchedTasks))
&& (dwFetchedTasks != 0))
{
///////////////////////////////////////////////////////////////
// Process each task. Note that this example prints the
// name of each task to the screen.
//////////////////////////////////////////////////////////////
while (dwFetchedTasks)
{
wprintf(L"%s\n", lpwszNames[--dwFetchedTasks]);
CoTaskMemFree(lpwszNames[dwFetchedTasks]);
}
CoTaskMemFree(lpwszNames);
}

pIEnum->Release();
CoUninitialize();
return S_OK;
}

Related topics
Task Scheduler 1.0 Examples
Starting a Task Example
8/8/2022 • 2 minutes to read • Edit Online

To start a task, call the Run method of the ITask interface. Run is an asynchronous method that attempts to
execute the task and returns as soon as the task has started. The Task Scheduler service must be running for this
method to succeed.
The following procedure describes how to start a task.
To star t a task
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This
example assumes that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that this example gets the
"Test Task" task.)
3. Call Run to start the task. Note that this method is inherited by the ITask interface.
4. Continue processing as needed.
5. Call ITask ::Release to free resources and CoUninitialize to uninitialize COM. This example calls Release to
free the pointer to the ITask interface. (Note that Release is an IUnknown method inherited by ITask .)

F O R A C O DE EXA M P L E O F SEE

Running an existing task C/C++ Code Example: Starting a Task

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Starting a Task
8/8/2022 • 2 minutes to read • Edit Online

This example attempts to run an existing task. This example assumes that the task and the test task already exist
on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>
#include<stdio.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;
ITaskScheduler *pITS;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

pITS->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate; error = 0x%x\n",hr);
CoUninitialize();
return 1;
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::Run to start the execution of "Test Task".
///////////////////////////////////////////////////////////////////

hr = pITask->Run();
pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::Run, error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Editing a Work Item using Property Pages
8/8/2022 • 2 minutes to read • Edit Online

You can edit the properties of a work item by using the graphic user interface provided by the Task Scheduler
Service. (Currently, the only valid work items are tasks.)
The following procedure describes how to edit a task using its property pages.
To edit a task using its proper ty pages
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (These
examples assume that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that tasks are currently the
only valid type of work item.)
3. Call IScheduledWorkItem::EditWorkItem to display the property pages for the task.
4. Edit the properties of the task as needed, then click OK to accept the new values and remove the displayed
property pages.

F O R A C O DE EXA M P L E O F SEE

Displaying the property pages for a known task and allowing C/C++ Code Example: Editing a Work Item
a user to edit the properties of the work item

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Editing a Work Item
8/8/2022 • 2 minutes to read • Edit Online

This example displays the property pages for a known task and allows a user to edit the properties of the work
item. This example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

//Release ITaskScheduler interface


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate, ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::EditWorkItem. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
HWND hParent = NULL;
DWORD dwReserved = 0;

hr = pITask->EditWorkItem(hParent,
dwReserved);
// Release ITask interface
pITask->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::EditWorkItem, ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Retrieving Work Item Property Examples
8/8/2022 • 2 minutes to read • Edit Online

To retrieve the properties of a work item, call ITaskScheduler ::Activate to retrieve the interface of the work
item object, then call the appropriate method to retrieve the task property you are interested in. Currently, the
only valid work items are tasks.
The code examples listed at the bottom of this page show how to retrieve the properties that apply to all work
items. For other properties that are unique to tasks, see Setting Task Property Examples.

NOTE
In the following code example, all interfaces are released after they are no longer needed.

Note that if you are retrieving a string property (such as comment for a work item), you must call
CoTaskMemFree to free the memory allocated for the returned string.
The following procedure describes how to retrieve a task property.
To retrieve a task proper ty
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (These
examples assume that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that tasks are currently the
only valid type of work item.)
3. Call the appropriate method to retrieve the property you are interested in.
4. Process the property as needed. (These examples simply print the property to the screen.)
5. If the returned property is a string, call CoTaskMemFree to free the memory allocated for the returned
string.

F O R A C O DE EXA M P L E O F SEE

Retrieving the account information of a known task C/C++ Code Example: Retrieving Task Account Information

Retrieving the comment string of a known task C/C++ Code Example: Retrieving a Task Comment

Retrieving the name of the creator of the task and displaying C/C++ Code Example: Retrieving the Task Creator
it on the screen

Retrieving the last exit code returned by a known task C/C++ Code Example: Retrieving Task Exit Code

Retrieving the idle-wait time of the task and displaying it on C/C++ Code Example: Retrieving Task Idle-wait Time
the screen

Retrieving the time the task was last run and displaying it on C/C++ Code Example: Retrieving the Task MostRecentRun
the screen Time

Retrieving the next time the task is scheduled to run and C/C++ Code Example: Retrieving the Task NextRun Time
displaying that time on the screen
F O R A C O DE EXA M P L E O F SEE

Retrieving the run times of the task and displaying them on C/C++ Code Example: Retrieving Task Run Times
the screen

Retrieving the current status of the task and displaying it on C/C++ Code Example: Retrieving Task Status
the screen

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving Task Account
Information
8/8/2022 • 2 minutes to read • Edit Online

This code example retrieves the account information of a known task and displays the account name on the
screen. This example assumes that the task and the test task already exist on the local computer and that the
Task Scheduler is running.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

//Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetAccountInformation. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
LPWSTR pwszAccountName;

hr = pITask->GetAccountInformation(&pwszAccountName);

// Release the ITask interface.


pITask->Release();

if(hr == SCHED_E_NO_SECURITY_SERVICES)
{
wprintf(L"Error: SCHED_E_NO_SECURITY_SERVICES");
wprintf(L"Security services are available only on Windows Server 2003");
wprintf(L", Windows XP, and Windows 2000.");
CoUninitialize();
return 1;

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetAccountInformation: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

wprintf(L"The account name for Test Task is: ");


wprintf(L" %s\n",pwszAccountName);

CoTaskMemFree(pwszAccountName);
CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving a Task Comment
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the comment string of a known task and displays the comment string on the screen. This
example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

//Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetComment. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
LPWSTR ppwszComment;

hr = pITask->GetComment(&ppwszComment);

// Release the ITask interface.


pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetComment: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

wprintf(L"The comment for Test Task is: ");


wprintf(L" %s\n",ppwszComment);

///////////////////////////////////////////////////////////////////
// Call CoTaskMemFree to free the string.
///////////////////////////////////////////////////////////////////
CoTaskMemFree(ppwszComment);

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving the Task Creator
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the name of the creator of the task and displays it on the screen. This example assumes
that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

//Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetCreator. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
LPWSTR ppwszCreator;

hr = pITask->GetCreator(&ppwszCreator);

// Release the ITask interface.


pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetCreator: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

wprintf(L"The creator of Test Task is: ");


wprintf(L" %s\n",ppwszCreator);

///////////////////////////////////////////////////////////////////
// Call CoTaskMemFree to free the string.
///////////////////////////////////////////////////////////////////
CoTaskMemFree(ppwszCreator);

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving Task Exit Code
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the last exit code returned by a known task. (A returned value of "0" indicates the task
was never run.) This example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"TestTask";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetExitCode. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
DWORD pdwExitCode;

hr = pITask->GetExitCode(&pdwExitCode);

// Release ITask interface.


pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetExitCode: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

wprintf(L"The last exit code of Test Task is: %d\n", pdwExitCode);

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving Task Idle-wait
Time
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the idle-wait time of the task and displays it on the screen. This example assumes that the
task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetIdleWait. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
WORD pwIdleMinutes;
WORD pwDeadlineMinutes;

hr = pITask->GetIdleWait(&pwIdleMinutes,
&pwDeadlineMinutes);

// Release the ITask interface.


pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetIdleWait: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

wprintf(L"The idle wait of Test Task is: \n");


wprintf(L" %d minutes\n", pwIdleMinutes);
wprintf(L" %d minutes\n", pwDeadlineMinutes);

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving the Task
MostRecentRun Time
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the time the task was last run and displays it on the screen. This example assumes that
the task and the test task already exist on the local computer.

#include <windows.h>
#include <wchar.h>
#include <stdio.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetMostRecentRunTime and display the most recent
// run time of this task.
///////////////////////////////////////////////////////////////////

SYSTEMTIME pstLastRun;

hr = pITask->GetMostRecentRunTime(&pstLastRun);

// Release the ITask interface.


pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling GetMostRecentRunTime: ");
wprintf(L"error = 0x%x\n", hr);
CoUninitialize();
return 1;
}

wprintf(L"The most recent run time for this task was: \n");
wprintf(L" %u/%u/%u \t %u:%02u\n", pstLastRun.wMonth,
pstLastRun.wDay,
pstLastRun.wYear,
pstLastRun.wHour,
pstLastRun.wMinute);

CoUninitialize();

return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving the Task NextRun
Time
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the next time the task is scheduled to run and displays that time on the screen. This
example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <wchar.h>
#include <stdio.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetNextRunTime and display next run time of
// this task.
///////////////////////////////////////////////////////////////////

SYSTEMTIME pstNextRun;

hr = pITask->GetNextRunTime(&pstNextRun);

// Release the ITask interface.


pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling GetNextRunTime: ");
wprintf(L"error = 0x%x\n", hr);
CoUninitialize();
return 1;
}

wprintf(L"The next runtime for this task is: \n");


wprintf(L" %u/%u/%u \t %u:%02u\n", pstNextRun.wMonth,
pstNextRun.wDay,
pstNextRun.wYear,
pstNextRun.wHour,
pstNextRun.wMinute);

CoUninitialize();

return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving Task Run Times
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the run times of the task and displays them on the screen. This example assumes that the
task and the test task already exist on the local computer.

#include <windows.h>
#include <wchar.h>
#include <stdio.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetRunTimes and display the next five run times for
// this task.
///////////////////////////////////////////////////////////////////

SYSTEMTIME stNow;
LPSYSTEMTIME pstListOfTimes;
LPSYSTEMTIME pstListBegin;
WORD wCountOfRuns = 5;

GetSystemTime(&stNow);
hr = pITask->GetRunTimes(&stNow,
NULL,
&wCountOfRuns,
&pstListBegin);
pstListOfTimes = pstListBegin;

// Release the ITask interface.


pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling GetRunTimes: ");
wprintf(L"error = 0x%x\n", hr);
CoUninitialize();
return 1;
}

wprintf(L"The next %u runtimes for this task are: \n",wCountOfRuns);

for (WORD i = 0; i < wCountOfRuns; i++)


{
wprintf(L"\t%u - %u/%u/%u \t %u:%u\n", i+1, pstListOfTimes->wMonth,
pstListOfTimes->wDay,
pstListOfTimes->wYear,
pstListOfTimes->wHour,
pstListOfTimes->wMinute);
pstListOfTimes++;
}

CoTaskMemFree(pstListBegin);
CoTaskMemFree(pstListOfTimes);
CoUninitialize();

return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving Task Status
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the current status of the task and displays it on the screen. This example assumes that the
task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetStatus. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
HRESULT phrStatus;

hr = pITask->GetStatus(&phrStatus);

// Release the ITask interface.


pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetStatus: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

wprintf(L"The status of Test Task is: ");

switch(phrStatus)
{
case SCHED_S_TASK_READY:
wprintf(L" SCHED_S_TASK_READY\n");
break;
case SCHED_S_TASK_RUNNING:
wprintf(L" SCHED_S_TASK_RUNNING\n");
break;
case SCHED_S_TASK_DISABLED:
wprintf(L" SCHED_S_TASK_DISABLED\n");
break;
case SCHED_S_TASK_HAS_NOT_RUN:
wprintf(L" SCHED_S_TASK_HAS_NOT_RUN\n");
break;
case SCHED_S_TASK_NOT_SCHEDULED:
wprintf(L" SCHED_S_TASK_NOT_SCHEDULED\n");
break;
case SCHED_S_TASK_NO_MORE_RUNS:
wprintf(L" SCHED_S_TASK_NO_MORE_RUNS\n");
break;
case SCHED_S_TASK_NO_VALID_TRIGGERS:
wprintf(L" SCHED_S_TASK_NO_VALID_TRIGGERS\n");
break;
default:
wprintf(L" unknown status flag!\n");
}

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Setting Work Item Property Examples
8/8/2022 • 2 minutes to read • Edit Online

To set the properties of a work item, call ITaskScheduler ::Activate to retrieve the interface of the work item
object, then call the appropriate method to set the task property you are interested in. Currently, the only valid
work items are tasks.
The code examples listed at the bottom of the page show how to set the properties that apply to all work items.
For other properties that are unique to tasks, see Setting Task Property Examples.

NOTE
In the following code example, all interfaces are released after they are no longer needed.

In the following examples, the modified object is always saved to disk by a call to IPersistFile::Save . (The
IPersistFile interface is a standard COM interface inherited by the task object.)
The following procedure describes how to set a task property.
To set a task proper ty
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (These
examples assume that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that tasks are currently the
only valid type of work item.)
3. Call the appropriate IScheduledWorkItem method to set the property you are interested in. Note that
IScheduledWorkItem methods are inherited by the ITask interface.
4. Call IPersistFile::Save to store the modified task object to disk.

F O R A C O DE EXA M P L E O F SEE

Setting the account information for a known task C/C++ Code Example: Setting Task Account Information

Setting the comment of a known task C/C++ Code Example: Setting Task Comment

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Setting Task Account
Information
8/8/2022 • 2 minutes to read • Edit Online

This example sets the account information for a known task. This example assumes that the task "test task"
already exists on the local computer and that the Task Scheduler service is running.

#define _WIN32_DCOM
#include <windows.h>
#include <initguid.h>
#include <iostream>
#include <stdio.h>
#include <comdef.h>
#include <wincred.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

#pragma comment(lib, "comsupp.lib")


#pragma comment(lib, "credui.lib")

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;

hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
wprintf(L"Failed calling CoCreateInstance. ");
CoUninitialize();
return 1;
}
}
else
{
wprintf(L"Failed calling CoInitializeEx. ");
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

// ------------------------------------------------------
// Securely get the user name and password.
CREDUI_INFO cui;
TCHAR pszName[CREDUI_MAX_USERNAME_LENGTH] = "";
TCHAR pszPwd[CREDUI_MAX_PASSWORD_LENGTH] = "";
BOOL fSave;
DWORD dwErr;

cui.cbSize = sizeof(CREDUI_INFO);
cui.hwndParent = NULL;
// Ensure that MessageText and CaptionText identify
// what credentials to use and which application requires them.
cui.pszMessageText = TEXT("Account information for task registration:");
cui.pszCaptionText = TEXT("Enter Account Information for Task Registration");
cui.hbmBanner = NULL;
fSave = FALSE;

// Create the UI asking for the credentials.


dwErr = CredUIPromptForCredentials(
&cui, // CREDUI_INFO structure
TEXT(""), // Target for credentials
NULL, // Reserved
0, // Reason
pszName, // User name
CREDUI_MAX_USERNAME_LENGTH, // Max number for user name
pszPwd, // Password
CREDUI_MAX_PASSWORD_LENGTH, // Max number for password
&fSave, // State of save check box
CREDUI_FLAGS_GENERIC_CREDENTIALS | // Flags
CREDUI_FLAGS_ALWAYS_SHOW_UI |
CREDUI_FLAGS_DO_NOT_PERSIST);

if(dwErr)
{
wprintf(L"Failed calling ITask::SetAccountInformation: ");
wprintf(L"error = 0x%x\n",dwErr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::SetAccountInformation to specify the account name
// and the account password for Test Task.
///////////////////////////////////////////////////////////////////
hr = pITask->SetAccountInformation((LPCWSTR)pszName,
(LPCWSTR)pszPwd);

SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));

if (FAILED(hr))
{
{
wprintf(L"Failed calling ITask::SetAccountInformation: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save the modified task to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;

hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

// Release the ITask interface.


pITask->Release();

hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pIPersistFile->Release();
CoUninitialize();
return 1;
}

// Release the IPersistFile interface.


pIPersistFile->Release();

wprintf(L"Set the account name and password.");


CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Setting Task Comment
8/8/2022 • 2 minutes to read • Edit Online

This example sets the comment for a known task. This example assumes that the task and the test task already
exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;

hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::SetComment to specify the account name
// and the account password for Test Task.
///////////////////////////////////////////////////////////////////
LPCWSTR pwszComment = L"This task is used to test the Task Scheduler APIs.";

hr = pITask->SetComment(pwszComment);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::SetComment: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save the modified task to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;

hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

// Release the ITask interface.


pITask->Release();

hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pIPersistFile->Release();
CoUninitialize();
return 1;
}

// Release the IPersistFile interface.


pIPersistFile->Release();

wprintf(L"Set the comment for Test Task.\n");


CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Retrieving Task Property Examples
8/8/2022 • 2 minutes to read • Edit Online

To retrieve the properties of a task, call ITaskScheduler ::Activate to get retrieve the interface of the task object,
then call the appropriate ITask method to retrieve the task property that you are interested in. The code
examples listed at the bottom of the page show how to retrieve the different task properties.
The code examples listed at the bottom of the page show how to retrieve the properties that are unique to task
objects. For other work item properties that also apply to tasks, see Retrieving Work Item Examples.

NOTE
In the following code example, all interfaces are released after they are no longer needed.

Note that if you are retrieving a string property (such as the application name, parameters, or working
directory), you must call CoTaskMemFree to free the memory allocated for the returned string.
The following procedure describes how to retrieve a task property.
To retrieve a task proper ty
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (These
examples assume that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that this example gets the
"Test Task" task.)
3. Call the appropriate ITask method to retrieve the property you are interested in.
4. Process the property as needed. (These examples print the property to the screen.)
5. If the returned property is a string, call CoTaskMemFree to free the memory allocated for the returned string.

F O R A C O DE EXA M P L E O F SEE

Retrieving the name of the application associated with a C/C++ Code Example: Retrieving the Task Application Name
given task

Retrieving the maximum amount of time the task can run C/C++ Code Example: Retrieving the Task MaxRunTime
and displaying that number on the screen

Retrieving the parameter string that is executed when the C/C++ Code Example: Retrieving Task Parameters
task is run and displaying that string on the screen

Retrieving the priority level of the task C/C++ Code Example: Retrieving Task Priority

Retrieving the working directory of a task and displaying the C/C++ Code Example: Retrieving the Task Working Directory
path to the working directory on the screen

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving the Task
Application Name
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the name of the application associated with a given task and displays that name on the
screen. This example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////

ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

pITS->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate; error = 0x%x\n",hr);
wprintf(L"Failed calling ITaskScheduler::Activate; error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetApplicationName to display the name of the
// application associated with "Test Task".
///////////////////////////////////////////////////////////////////

LPWSTR lpwszApplicationName;
hr = pITask->GetApplicationName(&lpwszApplicationName);
pITask->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetApplicationName\n");
wprintf(L" error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Process the returned string.
///////////////////////////////////////////////////////////////////

wprintf(L"Test Task is associated with: %s\n", lpwszApplicationName);

///////////////////////////////////////////////////////////////////
// Call CoTaskMemFree to free resources.
///////////////////////////////////////////////////////////////////

CoTaskMemFree(lpwszApplicationName);
CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving the Task
MaxRunTime
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the maximum amount of time the task can run (in milliseconds) and displays that
number on the screen. This example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////

ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

pITS->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate;\n");
wprintf(L"Failed calling ITaskScheduler::Activate;\n");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetMaxRunTime to display the maximum time Test Task
// is allowed to run.
///////////////////////////////////////////////////////////////////

DWORD pdwRunTime;
hr = pITask->GetMaxRunTime(&pdwRunTime);
pITask->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetMaxRunTime: \n");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

wprintf(L"Test Task can run for %d milliseconds\n", pdwRunTime);


CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving Task Parameters
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the parameter string that is executed when the task is run and displays that string on the
screen. This example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////

ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

pITS->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate; error = 0x%x\n",hr);
CoUninitialize();
return 1;
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetParameters to display the parameters string
// associated with "Test Task".
///////////////////////////////////////////////////////////////////

LPWSTR lpwszParameters;
hr = pITask->GetParameters(&lpwszParameters);
pITask->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetApplicationName\n");
wprintf(L" error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Process returned parameter string.
///////////////////////////////////////////////////////////////////

wprintf(L"Test Task is associated with the following parameters:\n");


wprintf(L" %s\n", lpwszParameters);

///////////////////////////////////////////////////////////////////
// Call CoTaskMemFree to free resources.
///////////////////////////////////////////////////////////////////

CoTaskMemFree(lpwszParameters);
CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving Task Priority
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the priority level of a task and displays the path to the working directory on the screen.
This example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

pITS->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetPriority to retrieve the priority level
// of Test Task.
///////////////////////////////////////////////////////////////////

DWORD pdwPriority;
hr = pITask->GetPriority(&pdwPriority);
pITask->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetPriority: error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
if(pdwPriority == HIGH_PRIORITY_CLASS)
{
wprintf(L"Test Task is a high priority task.\n");
}
else
{
wprintf(L"Test Task is not a high priority task.\n");
}

CoUninitialize();
return 0;

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving the Task Working
Directory
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves the working directory associated with a task and displays the path to the working
directory on the screen. This example assumes that the task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////

ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

pITS->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: error = 0x%x\n",hr);
wprintf(L"Failed calling ITaskScheduler::Activate: error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::GetWorkingDirectory to display the working
// directory associated with "Test Task".
///////////////////////////////////////////////////////////////////

LPWSTR lpwszWorkDir;
hr = pITask->GetWorkingDirectory(&lpwszWorkDir);
pITask->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetWorkingDirectory: \n");
wprintf(L" error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Process returned string.
///////////////////////////////////////////////////////////////////

wprintf(L"Test Task is associated with : %s\n", lpwszWorkDir);

///////////////////////////////////////////////////////////////////
// Call CoTaskMemFree to free resources.
///////////////////////////////////////////////////////////////////

CoTaskMemFree(lpwszWorkDir);
CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Setting Task Property Examples
8/8/2022 • 2 minutes to read • Edit Online

To set the properties of a task, call ITaskScheduler ::Activate to retrieve the interface of the task object, then
call the appropriate ITask method to set the task property you are interested in.
The code examples listed at the bottom of the page show how to set the properties that are unique to task
objects. For other work item properties that also apply to tasks, see Setting Work Item Property Examples.

NOTE
In the following code example, all interfaces are released after they are no longer needed.

In the following examples, the modified task object is always saved to disk by a call to IPersistFile::Save . (The
IPersistFile interface is a standard COM interface inherited by the task object.)
The following procedure describes how to set a task property.
To set a task proper ty
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (These
examples assume that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that this example gets the
"Test Task" task.)
3. Call the appropriate ITask method to set the property you are interested in.
4. Call IPersistFile::Save to store the modified task object to disk.

F O R A C O DE EXA M P L E O F SEE

Setting the name of the application associated with a known C/C++ Code Example: Setting Application Name
task

Setting the maximum run time of a known task C/C++ Code Example: Setting MaxRunTime

Clearing all command-line parameters associated with a C/C++ Code Example: Setting Task Parameters
known task

This example sets the priority of a test task and then saves C/C++ Code Example: Setting Task Priority
the task. This example assumes that the test task already
exists on the local computer.

Setting the working directory of a known task C/C++ Code Example: Setting Working Directory

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Setting Application Name
8/8/2022 • 2 minutes to read • Edit Online

This example sets the name of the application associated with a known task. This example assumes that the task
"test task" already exists on the local computer and that the Task Scheduler service is running.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;

hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::SetApplicationName to specify the Application name
// for Test Task.
///////////////////////////////////////////////////////////////////
LPCWSTR pwszApplicationName = L"C:\\Windows\\System32\\notepad.exe";

hr = pITask->SetApplicationName(pwszApplicationName);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::SetApplicationName: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save the modified task to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;

hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

// Release the ITask interface.


pITask->Release();

hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pIPersistFile->Release();
CoUninitialize();
return 1;
}

// Release the IPersistFile interface.


pIPersistFile->Release();

wprintf(L"Set the application name for Test Task.\n");


CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Setting MaxRunTime
8/8/2022 • 2 minutes to read • Edit Online

This example sets the maximum run time (set in milliseconds) of a known task. This example assumes that the
task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;

hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::SetMaxRunTime to specify the maximum amount
// of time the task will run.
///////////////////////////////////////////////////////////////////
DWORD dwMaxRunTime = (1000*60*5);

hr = pITask->SetMaxRunTime(dwMaxRunTime);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::SetMaxRunTime: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save the modified task to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;

hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

// Release the ITask interface.


pITask->Release();

hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pIPersistFile->Release();
CoUninitialize();
return 1;
}

// Release the IPersistFile interface.


pIPersistFile->Release();

wprintf(L"The maximum run time is set to 5 minutes.\n");

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Setting Task Parameters
8/8/2022 • 2 minutes to read • Edit Online

This example clears all command-line parameters associated with a known task. This example assumes that the
task and the test task already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;

hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::SetParameters to L"" to clear the parameters for
// Test Task.
///////////////////////////////////////////////////////////////////
LPCWSTR pwszParameters = L"";

hr = pITask->SetParameters(pwszParameters);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::SetParameters: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save the modified task to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;

hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

// Release the ITask interface.


pITask->Release();

hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pIPersistFile->Release();
CoUninitialize();
return 1;
}

// Release the IPersistFile interface.


pIPersistFile->Release();

wprintf(L"Cleared the parameters of TestTask.\n");

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Setting Task Priority
8/8/2022 • 2 minutes to read • Edit Online

This example sets the priority of a test task and then saves the task. This example assumes that the test task
already exists on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;

hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::SetPriority to specify the priority level of
// Test Task.
///////////////////////////////////////////////////////////////////
DWORD dwPriority = HIGH_PRIORITY_CLASS;

hr = pITask->SetPriority(dwPriority);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::SetPriority: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save the modified task to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;

hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

// Release the ITask interface.


pITask->Release();

hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pIPersistFile->Release();
CoUninitialize();
return 1;
}

// Release the IPersistFile interface.


pIPersistFile->Release();

wprintf(L"Set the priority of TestTask to HIGH_PRIORITY_CLASS.\n");

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Setting Working Directory
8/8/2022 • 2 minutes to read • Edit Online

This example sets the working directory of a known task. This example assumes that the task and the test task
already exist on the local computer.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;

hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::SetWorkingDirectory to specify the current
// working directory for Test Task.
///////////////////////////////////////////////////////////////////
LPCWSTR pwszWorkingDirectory = L"C:\\Temp";

hr = pITask->SetWorkingDirectory(pwszWorkingDirectory);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::SetWorkingDirectory: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save the modified task to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;

hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

// Release the ITask interface.


pITask->Release();

hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pIPersistFile->Release();
CoUninitialize();
return 1;
}

// Release the IPersistFile interface.


pIPersistFile->Release();

wprintf(L"Set the working directory to C:\\Temp.\n");

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Retrieving a Task Page Example
8/8/2022 • 2 minutes to read • Edit Online

To retrieve a task page you must call ITask ::Quer yInterface to retrieve the IProvideTaskPage interface, then
call IProvideTaskPage::GetPage . The GetPage method returns a handle to the page, which can then be used
to display the page you requested.

NOTE
In the following code example, all interfaces are released after they are no longer needed.

The following procedure describes how to create a new trigger.


To create a new trigger
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This
example assumes that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that this example gets the
"Test Task" task.)
3. Call ITask ::Quer yInterface to retrieve the IProvideTaskPage interface and IProvideTaskPage::GetPage
to retrieve the page.
4. Using the returned page handle, display the page.

F O R A C O DE EXA M P L E O F SEE

Retrieving and displaying the Task page of a known task Retrieving a Task Page

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving a Task Page
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves and displays the Task page of a known task. Note that in this example, all interfaces are
released when they are no longer needed.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

// Release the ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
}

///////////////////////////////////////////////////////////////////
// Call ITask::QueryInterface to retrieve the IProvideTaskPage
// interface, and call IProvideTaskPage::GetPage to retrieve the
// task page.
///////////////////////////////////////////////////////////////////
TASKPAGE tpType = TASKPAGE_TASK;
BOOL fPersistChanges = TRUE;
HPROPSHEETPAGE phPage;

IProvideTaskPage *pIProvTaskPage;
hr = pITask->QueryInterface(IID_IProvideTaskPage,
(void **)&pIProvTaskPage);
// Release the ITask interface.
pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::QueryInterface: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

hr = pIProvTaskPage->GetPage(tpType,
fPersistChanges,
&phPage);

// Release the IProvideTaskPage interface.


pIProvTaskPage->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling IProvideTaskPage::GetPage: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

//////////////////////////////////////////////////////////////////
// Display the page using additional code.
//////////////////////////////////////////////////////////////////

PROPSHEETHEADER psh;
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_DEFAULT | PSH_NOAPPLYNOW;
psh.phpage = &phPage;
psh.nPages = 1;

int psResult = PropertySheet(&psh);


if (psResult <= 0)
{
wprintf(L"Failed to create the property page: ");
wprintf(L"0x%x\n", GetLastError());
}

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Creating a New Trigger
8/8/2022 • 2 minutes to read • Edit Online

To create a trigger you must use three interfaces. IScheduledWorkItem provides the
IScheduledWorkItem::CreateTrigger method for creating the trigger object, ITaskTrigger provides the
ITaskTrigger ::SetTrigger method for setting the criteria for the trigger, and the COM interface IPersistFile
provides a Save method for saving the new trigger to disk.
The following procedure describes how to create a new trigger.
To create a new trigger
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This
example assumes that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that this example gets the
"Test Task" task.)
3. Call CreateTrigger to create a trigger object. (Note that CreateTrigger is inherited from
IScheduledWorkItem .)
4. Define a TASK_TRIGGER structure. Note that wBeginDay, wBeginMonth, and wBeginYear members of
TASK_TRIGGER must be set to a valid day, month, and year respectively.
5. Call ITaskTrigger ::SetTrigger to set the trigger criteria.
6. Save the task with the new trigger to disk using IPersistFile::Save . (The IPersistFile interface is a standard
COM interface supported by the ITask interface.)
7. Call Release to release all resources. (Note that Release is an IUnknown method inherited by ITask .)

F O R A C O DE EXA M P L E O F SEE

Creating a new trigger for an existing task C/C++ Code Example: Creating a Task Trigger

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Creating a Task Trigger
8/8/2022 • 2 minutes to read • Edit Online

This example creates a new trigger for an existing task named Test Task.

#include <windows.h>
#include <winbase.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;
ITaskScheduler *pITS;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);
pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
}

///////////////////////////////////////////////////////////////////
// Call ITask::CreateTrigger to create new trigger.
///////////////////////////////////////////////////////////////////

ITaskTrigger *pITaskTrigger;
WORD piNewTrigger;
hr = pITask->CreateTrigger(&piNewTrigger,
&pITaskTrigger);
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::CreatTrigger: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

//////////////////////////////////////////////////////
// Define TASK_TRIGGER structure. Note that wBeginDay,
// wBeginMonth, and wBeginYear must be set to a valid
// day, month, and year respectively.
//////////////////////////////////////////////////////

TASK_TRIGGER pTrigger;
ZeroMemory(&pTrigger, sizeof (TASK_TRIGGER));

// Add code to set trigger structure?


pTrigger.wBeginDay =1; // Required
pTrigger.wBeginMonth =1; // Required
pTrigger.wBeginYear =1999; // Required
pTrigger.cbTriggerSize = sizeof (TASK_TRIGGER);
pTrigger.wStartHour = 13;
pTrigger.TriggerType = TASK_TIME_TRIGGER_DAILY;
pTrigger.Type.Daily.DaysInterval = 1;

///////////////////////////////////////////////////////////////////
// Call ITaskTrigger::SetTrigger to set trigger criteria.
///////////////////////////////////////////////////////////////////

hr = pITaskTrigger->SetTrigger (&pTrigger);
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskTrigger::SetTrigger: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
pITaskTrigger->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save trigger to disk.
///////////////////////////////////////////////////////////////////

IPersistFile *pIPersistFile;
hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);
hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
pITaskTrigger->Release();
pIPersistFile->Release();
CoUninitialize();
return 1;
}

wprintf(L"The trigger was created and IPersistFile::Save was \n");


wprintf(L"called to save the new trigger to disk.\n");

///////////////////////////////////////////////////////////////////
// Release resources.
///////////////////////////////////////////////////////////////////

pITask->Release();
pITaskTrigger->Release();
pIPersistFile->Release();
CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Creating an Idle Trigger Example
8/8/2022 • 2 minutes to read • Edit Online

To create an idle trigger, you must specify an idle trigger when you create the trigger, and you must set the idle
time for the task. For information about idle conditions, see Task Idle Conditions.
After creating the idle trigger, call IPersistFile::Save to save the new trigger to disk.
The following procedure describes how to create an idle trigger for a known task.
To create an idle trigger for a known task
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This
example assumes that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that this example gets the
"Test Task" task.)
3. Call SetIdleWait to set how long the system must remain idle before the trigger will fire. (Note that
SetIdleWait is inherited from IScheduledWorkItem .)
4. Define the TASK_TRIGGER structure and call CreateTrigger to create the idle trigger. (Note that
CreateTrigger is inherited from IScheduledWorkItem .)
5. Save the task with the new idle trigger to disk using IPersistFile::Save . (The IPersistFile interface is a
standard COM interface supported by the ITask interface.)
6. Call ITask ::Release to release all resources. (Note that Release is an IUnknown method inherited by ITask .)

F O R A C O DE EXA M P L E O F SEE

Creating an idle trigger for an existing task C/C++ Code Example: Creating an Idle Trigger

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Creating an Idle Trigger
8/8/2022 • 2 minutes to read • Edit Online

This example creates an idle trigger for an existing task. For information about idle conditions, see Task Idle
Conditions.

#include <windows.h>
#include <winbase.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>
#include <comdef.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;
ITaskScheduler *pITS;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::SetIdleWait to specify idle time.
///////////////////////////////////////////////////////////////////

WORD wIdleMinutes = 3;
WORD wDeadlineMinutes = 5;

hr = pITask->SetIdleWait(wIdleMinutes,
wDeadlineMinutes);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::SetIdleWait: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::CreateTrigger to create new trigger.
///////////////////////////////////////////////////////////////////

ITaskTrigger *pITaskTrigger;
WORD piNewTrigger;

hr = pITask->CreateTrigger(&piNewTrigger,
&pITaskTrigger);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::CreatTrigger: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Define TASK_TRIGGER structure and call ITask::CreateTrigger
// to create the idle trigger.
///////////////////////////////////////////////////////////////////
TASK_TRIGGER pTrigger;
ZeroMemory(&pTrigger, sizeof (TASK_TRIGGER));

// Add code to set trigger structure.


pTrigger.wBeginDay = 1;
pTrigger.wBeginMonth = 1;
pTrigger.wBeginYear =1999;
pTrigger.cbTriggerSize = sizeof (TASK_TRIGGER);
pTrigger.TriggerType = TASK_EVENT_TRIGGER_ON_IDLE;

hr = pITaskTrigger->SetTrigger (&pTrigger);
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskTrigger::SetTrigger: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
pITaskTrigger->Release();
CoUninitialize();
return 1;
}
///////////////////////////////////////////////////////////////////
// Call IPersistFile::Save to save setting to disk.
///////////////////////////////////////////////////////////////////
IPersistFile *pIPersistFile;
hr = pITask->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::QueryInterface: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
pITaskTrigger->Release();
CoUninitialize();
return 1;
}

hr = pIPersistFile->Save(NULL,
TRUE);

if (FAILED(hr))
{
wprintf(L"Failed calling IPersistFile::Save: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
pITaskTrigger->Release();
pIPersistFile->Release();
CoUninitialize();
return 1;
}
wprintf(L"The idle trigger was set and IPersistFile::Save \n");
wprintf(L"was called to save the new trigger to disk.\n");

///////////////////////////////////////////////////////////////////
// Release all resources.
///////////////////////////////////////////////////////////////////

pITask->Release();
pITaskTrigger->Release();
pIPersistFile->Release();
CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Terminating a Task Example
8/8/2022 • 2 minutes to read • Edit Online

You can terminate a task while it is running by calling IScheduledWorkItem::Terminate .


The following procedure describes how to terminate a task if it is running.
To terminate a task if it is running
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This
example assumes that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that this example gets the
"Test Task" task.)
3. Call ITask ::GetStatus to find out if the task is running. (Note that GetStatus is an IScheduledWorkItem
method inherited by ITask .)
4. Check the status of the task and then call ITask ::Terminate if the task is running. (Note that Terminate is an
IScheduledWorkItem method inherited by ITask .)

F O R A C O DE EXA M P L E O F SEE

Verifying the status of a known task C/C++ Code Example: Terminating a Task

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Terminating a Task
8/8/2022 • 2 minutes to read • Edit Online

This example verifies the status of a known task and terminates the task if it is running.

#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////
ITask *pITask;
LPCWSTR lpcwszTaskName;
lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

//Release ITaskScheduler interface.


pITS->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
///////////////////////////////////////////////////////////////////
// Call ITask::GetStatus. Note that this method is
// inherited from IScheduledWorkItem.
///////////////////////////////////////////////////////////////////
HRESULT phrStatus;

hr = pITask->GetStatus(&phrStatus);

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetStatus: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITask::Terminate if the status is SCHED_S_TASK_RUNNING.
///////////////////////////////////////////////////////////////////

if(phrStatus==SCHED_S_TASK_RUNNING)
{
hr = pITask->Terminate();
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::Terminate: ");
wprintf(L"error = 0x%x\n",hr);
pITask->Release();
CoUninitialize();
return 1;
}
wprintf(L"Test Task is terminated.\n");
}
else
{
wprintf(L"Test Task is not running.\n");
}

// Release the ITask interface.


pITask->Release();

CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Retrieving Trigger Strings Example
8/8/2022 • 2 minutes to read • Edit Online

You can retrieve the trigger strings of a known trigger using the IScheduledWorkItem or ITaskTrigger
interface, depending on the type of object you are working with.
When working with a task object, use the methods of the IScheduledWorkItem interface to retrieve the trigger
strings of a work item.
When you are working with a task trigger object, use the methods of the ITaskTrigger interface to retrieve the
trigger string of the trigger.
The following example shows how to use IScheduledWorkItem::GetTriggerString to display the strings of all
triggers associated with a known task.
The following procedure describes how to retrieve the trigger strings of a task.
To retrieve the trigger strings of a task
1. Call CoInitialize to initialize the COM library and CoCreateInstance to get a Task Scheduler object. (This
example assumes that the Task Scheduler service is running.)
2. Call ITaskScheduler ::Activate to get the ITask interface of the task object. (Note that this example gets the
"Test Task" task.)
3. Call ITask ::GetTriggerCount to find out how many triggers are associated with a task. (Note that
GetTriggerCount is an IScheduledWorkItem method inherited by ITask .)
4. Display the trigger strings, calling ITask ::GetTriggerString for each trigger associated with the task. (Note
that GetTriggerString is an IScheduledWorkItem method inherited by ITask .)
5. Release all resources. Call CoTaskMemFree to release the trigger strings and ITask ::Release to release the
ITask interface. (Note that Release is an IUnknown method inherited by ITask .)

F O R A C O DE EXA M P L E O F SEE

Retrieving a trigger string for all the triggers associated with Code Example: Retrieving Trigger Strings
a known task

Related topics
Task Scheduler 1.0 Examples
C/C++ Code Example: Retrieving Trigger Strings
8/8/2022 • 2 minutes to read • Edit Online

This example retrieves a trigger string for all the triggers associated with a known task.

#include <windows.h>
#include <winbase.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)


{
HRESULT hr = S_OK;
ITaskScheduler *pITS;

///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// call CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}

///////////////////////////////////////////////////////////////////
// Call ITaskScheduler::Activate to get the Task object.
///////////////////////////////////////////////////////////////////

ITask *pITask;
LPCWSTR lpcwszTaskName = L"Test Task";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);

pITS->Release();
if (FAILED(hr))
{
wprintf(L"Failed calling ITaskScheduler::Activate: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}
///////////////////////////////////////////////////////////////////
// Call ITask::TriggerCount to retrieve the number of triggers
// associated with the task.
///////////////////////////////////////////////////////////////////

WORD plTriggerCount;
hr = pITask->GetTriggerCount (&plTriggerCount);
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetTriggerCount: ");
wprintf(L"error = 0x%x\n",hr);
pTask->Release();
CoUninitialize();
return 1;
}

///////////////////////////////////////////////////////////////////
// Display the trigger stings, calling ITask::GetTriggerString for
// each trigger associated with the task.
///////////////////////////////////////////////////////////////////

wprintf(L"There are %i triggers with Test Task.\n",plTriggerCount);


wprintf(L"They are:\n");

WORD CurrentTrigger=0;
LPWSTR ppwszTrigger;

for (CurrentTrigger=0; CurrentTrigger<plTriggerCount; CurrentTrigger++)


{
pITask->GetTriggerString (CurrentTrigger,
&ppwszTrigger);
if (FAILED(hr))
{
wprintf(L"Failed calling ITask::GetTriggerString: ");
wprintf(L"error = 0x%x\n",hr);
pTask->Release();
CoUninitialize();
return 1;
}

wprintf(L"%i) %s\n",CurrentTrigger+1, ppwszTrigger);


}

///////////////////////////////////////////////////////////////////
// Release resources.
///////////////////////////////////////////////////////////////////

CoTaskMemFree(ppwszTrigger);
pITask->Release();
CoUninitialize();
return 0;
}

Related topics
Task Scheduler 1.0 Examples
Task Scheduler Reference
8/8/2022 • 2 minutes to read • Edit Online

This section describes the APIs, scripting objects, and XML schema that are provided by the Task Scheduler.
API topics include a description of the API, the declaration syntax of the API, remarks that describe special
conditions for the API, and a requirements block that describes what platform, header files, and libraries are
required.
Scripting object topics include a description of the object, the declaration syntax of the object, remarks that
describe special conditions for the object, and a requirements block that describes what platform and type
libraries are required.
XML schema topics include a description of the element, parent, child, and attribute information, and remarks
that describe special conditions.

SEE F O R IN F O RM AT IO N O N

Task Scheduler Objects Scripting objects and their methods and properties.

Task Scheduler Interfaces Interfaces and their methods and properties.

Task Scheduler Structures and Unions Structures and unions.

Task Scheduler Enumerated Types Constants defined by enumerators.

Task Scheduler Schema Elements, simple types, complex types, and attribute groups
defined by the schema.

Task Scheduler Error and Success Constants Error and success constants returned by Task Scheduler APIs.

Schtasks.exe The Schtasks.exe command line tool that is used to create,


delete, query, change, run, and end scheduled tasks on a
local or remote computer.

Related topics
Task Scheduler
Task Scheduler Scripting Objects
8/8/2022 • 2 minutes to read • Edit Online

The scripting objects that are described in the following topics provide programmatic access to the functionality
that is available within the Task Scheduler for Visual Basic and Visual Basic script developers.
The following objects are introduced in Task Scheduler 2.0.

O B JEC T DESC RIP T IO N

Action Provides the common properties that are inherited by all


action objects.

ActionCollection Contains the actions performed by the task.

BootTrigger Represents a trigger that starts a task when the system is


booted.

ComHandlerAction Represents an action that fires a handler.

DailyTrigger Represents a trigger that starts a task based on a daily


schedule.

EmailAction Represents an action that sends an email message.

EventTrigger Represents a trigger that starts a task when a system event


occurs.

ExecAction Represents an action that executes a command-line


operation.

IdleSettings Specifies how the Task Scheduler performs tasks when the
computer is in an idle condition.

IdleTrigger Represents a trigger that starts a task when an idle condition


occurs.

LogonTrigger Represents a trigger that starts a task when a user logs on.

MonthlyDOWTrigger Represents a trigger that starts a task on a monthly day-of-


week schedule.

MonthlyTrigger Represents a trigger that starts a task based on a monthly


schedule.

NetworkSettings Provides the settings that the Task Scheduler service uses to
obtain a network profile.

Principal Provides the security credentials for a principal.


O B JEC T DESC RIP T IO N

RegisteredTask Provides the methods that are used to run the task
immediately, get any running instances of the task, get or
set the credentials that are used to register the task, and the
properties that describe the task.

RegisteredTaskCollection Contains all the tasks that are registered.

RegistrationInfo Provides the administrative information that can be used to


describe the task. This information includes details such as a
description of the task, the author of the task, the date the
task is registered, and the security descriptor of the task.

RegistrationTrigger Represents a trigger that starts a task when the task is


registered.

RepetitionPattern Defines how often the task is run and how long the
repetition pattern is repeated after the task is started.

RunningTask Provides the methods to get information from and control a


running task.

RunningTaskCollection Used to retrieve a running task.

SessionStateChangeTrigger Used to trigger tasks for console connect or disconnect,


remote connect or disconnect, or workstation lock or unlock
notifications.

ShowMessageAction Represents an action that shows a message box when a task


is activated.

TaskDefinition Defines all the components of a task, such as the task


settings, triggers, actions, and registration information.

TaskFolder Provides the methods that are used to register (create) tasks
in the folder, remove tasks from the folder, and create or
remove subfolders from the folder.

TaskFolderCollection Counts the number of folders in the collection and retrieve a


specified folder from the collection.

TaskNamedValuePair Creates a name-value pair in which the name is associated


with the value.

TaskNamedValueCollection Contains a collection of TaskNamedValuePair object


name-value pairs.

TaskSer vice Provides access to the Task Scheduler service for managing
registered tasks.

TaskSettings Provides the settings that the Task Scheduler services uses
to perform the task.
O B JEC T DESC RIP T IO N

TaskVariables Defines task variables that can be passed as parameters to


task handlers and external executables that are launched by
tasks.

TimeTrigger Represents a trigger that starts a task when the trigger is


activated.

Trigger Provides the common properties that are inherited by all


trigger objects.

TriggerCollection Used to add to, remove from, and retrieve the triggers of a
task.

WeeklyTrigger Represents a trigger that starts a task based on a weekly


schedule.

Related topics
Task Scheduler Reference
Task Scheduler
Action object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides the common properties that are inherited by all action objects. An action object is
created by the ActionCollection.Create method.

Members
The Action object has these types of members:
Properties
Properties
The Action object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Id Read/write Gets or sets the identifier of the action.

Type Read-only Gets the type of the action.

Remarks
For information on how actions and tasks work together, see Task Actions. The following table contains the
scripting objects that represent the actions that can be performed:

API DESC RIP T IO N

ComHandlerAction Represents an action that fires a handler.

ExecAction Represents an action that executes a command-line


operation.

EmailAction Represents an action that sends an email message.

ShowMessageAction Represents an action that shows a message box.

When reading or writing XML, the actions of a task are specified in the Actions element of the Task Scheduler
schema.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting) , Event
Trigger Example (Scripting), Daily Trigger Example (Scripting), Registration Trigger Example (Scripting), Weekly
Trigger Example (Scripting), Logon Trigger Example (Scripting), or Boot Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler Scripting Objects
Task Scheduler
Action.Id property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the identifier of the action.

Syntax
Action.Id As String

Property value
The user-defined identifier for the action. This identifier is used by the Task Scheduler for logging purposes.

Remarks
For information on how actions and tasks work together, see Task Actions.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Action
Action.Type property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the type of the action.

Syntax
Action.Type As Integer

Property value
This property returns one of the following TASK_ACTION_TYPE enumeration constants.

VA L UE M EA N IN G

This action performs a command-line operation. For


TASK_ACTION_EXEC example, the action could run a script, launch an executable,
0 or, if the name of a document is provided, find its associated
application and launch the application with the document.

This action fires a handler.


TASK_ACTION_COM_HANDLER
5

This action sends an email message.


TASK_ACTION_SEND_EMAIL
6

This action shows a message box.


TASK_ACTION_SHOW_MESSAGE
7

Remarks
The action type is defined when the action is created and cannot be changed later. For information on creating
an action, see ActionCollection.Create .
For information on how actions and tasks work together, see Task Actions.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


REQ UIREM EN T VA L UE

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TASK_ACTION_TYPE
Task Scheduler
Action
ActionCollection object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that contains the actions performed by the task.

Members
The ActionCollection object has these types of members:
Methods
Properties
Methods
The ActionCollection object has these methods.

M ET H O D DESC RIP T IO N

Clear Clears all the actions from the collection.

Create Creates and adds a new action to the collection.

Remove Removes a specified action from the collection.

Properties
The ActionCollection object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Context Read/write Gets or sets the identifier of the


principal for the task.

Count Read-only Gets the number of actions in the


collection.

Item Read-only Gets a specified action from the


collection.

XmlText Read/write Gets or sets an XML-formatted version


of the collection.

Remarks
When reading or writing XML, the actions of a task are specified in the Actions element of the Task Scheduler
schema.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting), Event
Trigger Example (Scripting), Daily Trigger Example (Scripting), Registration Trigger Example (Scripting), Weekly
Trigger Example (Scripting), Logon Trigger Example (Scripting), or Boot Trigger Example (Scripting).
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
ActionCollection.Context property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the identifier of the principal for the task.

Syntax
ActionCollection.Context As String

Property value
The identifier of the principal for the task. The identifier that is specified here must match the identifier that is
specified in the Id property of the IPrincipal interface that defines the principal.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
ActionCollection
ActionCollection.Count property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the number of actions in the collection.

Syntax
ActionCollection.Count As long

Property value
The number of actions in the collection. The collection can contain up to 32 actions.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
ActionCollection
ActionCollection.Item property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets a specified action from the collection.

Syntax
ActionCollection.Item( _
ByVal Index _
) As Action

Property value
An Action object that represents the requested action.

Remarks
Collections are 1-based. In other words, the index for the first item in the collection is 1.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
ActionCollection
ActionCollection::XmlText property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets an XML-formatted version of the collection.

Syntax
.XmlText As String

Property value
An XML-formatted version of the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
ActionCollection
ActionCollection.Clear method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, clears all the actions from the collection.

Syntax
ActionCollection.Clear()

Parameters
This method has no parameters.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
ActionCollection
ActionCollection.Create method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, creates and adds a new action to the collection.

Syntax
ActionCollection.Create( _
ByVal type _
)

Parameters
type [in]
This parameter is set to one of the following TASK_ACTION_TYPE enumeration constants.

VA L UE M EA N IN G

The action performs a command-line operation. For example,


TASK_ACTION_EXEC the action could run a script, launch an executable, or, if the
0 name of a document is provided, find its associated
application and launch the application with the document.

The action fires a handler.


TASK_ACTION_COM_HANDLER
5

This action sends email message.


TASK_ACTION_SEND_EMAIL
6

This action shows a message box.


TASK_ACTION_SHOW_MESSAGE
7

Return value
An Action object that represents the new action.

Remarks
You cannot add more than 32 actions to the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]


REQ UIREM EN T VA L UE

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TASK_ACTION_TYPE
Task Scheduler
ActionCollection
Action
ExecAction
EmailAction
ShowMessageAction
ComHandlerAction
ActionCollection.Remove method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, removes the specified action from the collection.

Syntax
ActionCollection.Remove( _
ByVal index _
)

Parameters
index [in]
The index of the action to be removed.

Return value
This method does not return a value.

Remarks
When removing items, note that the index for the first item in the collection is 1 and the index for the last item is
the value of the ActionCollection.Count property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
ActionCollection
BootTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task when the system is booted.

Members
The BootTrigger object has these types of members:
Properties
Properties
The BootTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Delay Gets or sets a value that indicates the


amount of time between when the
system is booted and when the task is
started.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time that the task launched by the
trigger is allowed to run.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets how often the task is run
and how long the repetition pattern is
repeated after the task is started.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.
Remarks
The Task Scheduler service is started when the operating system is booted, and boot trigger tasks are set to start
when the Task Scheduler service starts.
Only a member of the Administrators group can create a task with a boot trigger.
When creating your own XML for a task, a boot trigger is specified using the BootTrigger element of the Task
Scheduler schema.

Examples
For more information and example code for this scripting object, see Boot Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
TriggerCollection
TriggerCollection.Create
BootTrigger.Delay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a value that indicates the amount of time between when the system is booted and
when the task is started.

Syntax
BootTrigger.Delay As String

Property value
A value that indicates the amount of time between when the system is booted and when the task is started. The
format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD
is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of minutes,
and nS is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one
month, four days, two hours, and five minutes).

Remarks
When reading or writing your own XML for a task, the boot delay is specified using the Delay element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
BootTrigger
ComHandlerAction object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents an action that fires a handler.

Members
The ComHandlerAction object has these types of members:
Properties
Properties
The ComHandlerAction object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

ClassId Read/write Gets or sets the identifier of the


handler class.

Data Read/write Gets or sets additional data that is


associated with the handler.

Id Read/write Inherited from the Action object. Gets


or sets the identifier of the action.

Type Read-only Inherited from the Action object. Gets


the type of the action.

Remarks
COM handlers must implement the ITaskHandler interface for the Task Scheduler to start and stop the handler.
In turn, the COM handler uses the methods of the TaskHandlerStatus object to communicate the status back
to the Task Scheduler.
When reading or writing XML, a COM handler action is specified in the ComHandler element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
See also
TaskHandlerStatus
Task Scheduler Objects
Task Scheduler
ComHandlerAction.ClassId property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the identifier of the handler class.

Syntax
ComHandlerAction.ClassId As String

Property value
The identifier of the class that defines the handler to be fired.

Remarks
When reading or writing XML, the class of a COM handler is specified in the ClassId element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
ComHandlerAction
ComHandlerAction.Data property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets additional data that is associated with the handler.

Syntax
ComHandlerAction.Data As String

Property value
The arguments that are needed by the handler.

Remarks
When reading or writing XML, the data of a COM handler is specified in the Data element of the Task Scheduler
schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
ComHandlerAction
DailyTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task based on a daily schedule.

Members
The DailyTrigger object has these types of members:
Properties
Properties
The DailyTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

DaysInter val Read/write Gets or sets the interval between the


days in the schedule.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time that the task launched by the
trigger is allowed to run.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

RandomDelay Read/write Gets or sets a delay time that is


randomly added to the start time of
the trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets how often the task is run
and how long the repetition pattern is
repeated after the task is started.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

Remarks
The time of day that the task is started is set by the Star tBoundar y property.
An interval of 1 produces a daily schedule. An interval of 2 produces an every other day schedule and so on.
When reading or writing your own XML for a task, a daily trigger is specified using the ScheduleByDay
element of the Task Scheduler schema.

Examples
For more information and a code example for this scripting object, see Daily Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
TriggerCollection
TriggerCollection.Create
DailyTrigger.DaysInterval property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the interval between the days in the schedule.

Syntax
DailyTrigger.DaysInterval As short

Property value
The interval between the days in the schedule.

Remarks
An interval of 1 produces a daily schedule. An interval of 2 produces an every-other day schedule.
When reading or writing your own XML for a task, the interval for a daily schedule is specified using the
DaysInter val element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
DailyTrigger
DailyTrigger.RandomDelay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a delay time that is randomly added to the start time of the trigger.

Syntax
DailyTrigger.RandomDelay As String

Property value
The delay time that is randomly added to the start time of the trigger. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S (for example, P2DT5S is a 2 day, 5 second delay).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
DailyTrigger
Task Scheduler
EmailAction object
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
Scripting object that represents an action that sends an email message.

Members
The EmailAction object has these types of members:
Properties
Properties
The EmailAction object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Attachments Read/write Gets or sets an array of attachments


that is sent with the email message.

Bcc Read/write Gets or sets the email address or


addresses that you want to Bcc in the
email message.

Body Read/write Gets or sets the body of the email that


contains the email message.

Cc Read/write Gets or sets the email address or


addresses that you want to Cc in the
email message.

From Read/write Gets or sets the email address that


you want to send the email from.

HeaderFields Read/write Gets or sets the header information in


the email that you want to send.

Id Read/write Inherited from the Action object. Gets


or sets the identifier of the action.

ReplyTo Read/write Gets or sets the email address that


you want to reply to.

Ser ver Read/write Gets or sets the name of the server


that you use to send email from.

Subject Read/write Gets or sets the subject of the email


message.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

To Read/write Gets or sets the email address or


addresses that you want to send the
email to.

Type Read-only Inherited from Action object. Gets the


type of the action.

Remarks
The email action must have a valid value for the Ser ver , From , and To or Cc properties for the task to register
and run correctly.
When reading or writing your own XML for a task, an email action is specified using the SendEmail element of
the Task Scheduler schema.

Examples
For more information and example code for this scripting object, see Event Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll
EmailAction.Attachments property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets an array of attachments that is sent with the email message.
This property is read/write.

Syntax
EmailAction.Attachments As String

Property value
An array of attachments that is sent with the email message.

Remarks
A maximum of eight attachments can be in the array of attachments.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.Bcc property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the email address or addresses that you want to Bcc in the email message.
This property is read/write.

Syntax
EmailAction.Bcc As String

Property value
The email address or addresses that you want to Bcc in the email message.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.Body property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the body of the email that contains the email message.
This property is read/write.

Syntax
EmailAction.Body As String

Property value
The body of the email that contains the email message.

Remarks
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, the setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will
set the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.Cc property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the email address or addresses that you want to Cc in the email message.
This property is read/write.

Syntax
EmailAction.Cc As String

Property value
The email address or addresses that you want to Cc in the email message.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.From property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the email address that you want to send the email from.
This property is read/write.

Syntax
EmailAction.From As String

Property value
The email address that you want to send the email from.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.HeaderFields property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the header information in the email you want to send.
This property is read/write.

Syntax
EmailAction.HeaderFields As TaskNamedValueCollection

Property value
The header information in the email you want to send.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.ReplyTo property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the email address that you want to reply to.
This property is read/write.

Syntax
EmailAction.ReplyTo As String

Property value
The email address that you want to reply to.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.Server property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the name of the SMTP server that you use to send email from.
This property is read/write.

Syntax
EmailAction.Server As String

Property value
The name of the server that you use to send email from.

Remarks
Make sure the SMTP server that sends the email is setup correctly. E-mail is sent using NTLM authentication for
Windows SMTP servers, which means that the security credentials used for running the task must also have
privileges on the SMTP server to send email message. If the SMTP server is a non-Windows based server, then
the email will be sent if the server allows anonymous access. For information about setting up the SMTP server,
see SMTP Server Setup, and for information about managing SMTP server settings, see SMTP Administration.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.Subject property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the subject of the email message.
This property is read/write.

Syntax
EmailAction.Subject As String

Property value
The subject of the email message.

Remarks
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, the setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will
set the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EmailAction.To property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. Please use IExecAction with the powershell Send-MailMessage cmdlet as
a workaround.]
For scripting, gets or sets the email address or addresses that you want to send the email to.
This property is read/write.

Syntax
EmailAction.To As String

Property value
The email address or addresses that you want to send the email to.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EmailAction
Task Scheduler
EventTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task when a system event occurs.

Members
The EventTrigger object has these types of members:
Properties
Properties
The EventTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Delay Read/write Gets or sets a value that indicates the


amount of time between when the
event occurs and when the task is
started.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time that the task launched by this
trigger is allowed to run.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets how often the task is run
and how long the repetition pattern is
repeated after the task is started.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.

Subscription Read/write Gets or sets the XPath query string


that identifies the event that fires the
trigger.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

ValueQueries Read/write Gets or sets a collection of named


XPath queries. Each query in the
collection is applied to the last
matching event XML that is returned
from the subscription query specified
in the Subscription property. The
name of the query can be used as a
variable in the message of a
ShowMessageAction action.

Remarks
A maximum of 500 tasks with event subscriptions can be created. An event subscription that queries for a
variety of events can be used to trigger a task that uses the same action in response to the events being logged.
When reading or writing your own XML for a task, an event trigger is specified using the EventTrigger element
of the Task Scheduler schema.

Examples
For more information and a code example for this scripting object, see Event Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Header
Windows.ui.xaml.h

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
TriggerCollection
TriggerCollection.Create
EventTrigger.Delay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a value that indicates the amount of time between when the event occurs and when
the task is started. The format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the
number of months, nD is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the
number of minutes, and nS is the number of seconds (for example, PT5M specifies 5 minutes and
P1M4DT2H5M specifies one month, four days, two hours, and five minutes).

Syntax
EventTrigger.Delay As String

Property value
A value that indicates the amount of time between when the event occurs and when the task is started.

Remarks
When reading or writing your own XML for a task, the event delay is specified using the Delay element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
EventTrigger
EventTrigger.Subscription property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a query string that identifies the event that fires the trigger.

Syntax
EventTrigger.Subscription As String

Property value
A query string that identifies the event that fires the trigger.

Remarks
When reading or writing your own XML for a task, the event subscription is specified using the Subscription
element of the Task Scheduler schema.
For more information about writing a query string for certain events, see Event Selection and Subscribing to
Events.

Examples
The following query string defines a subscription to all level 2 events in the System channel:

"<QueryList>
<Query Id='1'>
<Select Path='System'>*[System/Level=2]</Select>
</Query>
</QueryList>"

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
EventTrigger
EventTrigger.ValueQueries property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a collection of named XPath queries. Each query in the collection is applied to the last
matching event XML that is returned from the subscription query specified in the Subscription property.

Syntax
EventTrigger.ValueQueries As String

Property value
A collection of of name-value pairs. Each name-value pair in the collection defines a unique name for a property
value of the event that triggers the event trigger. The property value of the event is defined as an XPath event
query. For more information about XPath event queries, see Event Selection.

Remarks
The name of the query can be used as a variable in the following action properties:
ShowMessageAction.MessageBody
ShowMessageAction.Title
ExecAction.Arguments
ExecAction.WorkingDirector y
EmailAction.Ser ver
EmailAction.Subject
EmailAction.To
EmailAction.Cc
EmailAction.Bcc
EmailAction.ReplyTo
EmailAction.From
EmailAction.Body
ComHandlerAction.Data
The following code example strings show two name value pairs that can be used in a name-value collection. The
values returned by the XPath queries can replace variables in an action's property. The values are referenced by
name, with $(user) and $(machine) , in the action property. For example, if the $(user) and $(machine)
variables are used in the ShowMessageAction.MessageBody string, then the value of the XPath queries will
replace the variables in the string.

name: user
value: Event/UserData/SubjectUserName

name: machine
value: Event/UserData/MachineName

For more information about writing a query string for certain events, see Event Selection and Subscribing to
Events.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
EventTrigger
ExecAction object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents an action that executes a command-line operation.

Members
The ExecAction object has these types of members:
Properties
Properties
The ExecAction object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Arguments Read/write Gets or sets the arguments associated


with the command-line operation.

Id Read/write Inherited from the Action object. Gets


or sets the identifier of the action.

Path Read/write Gets or sets the path to an executable


file.

Type Read-only Inherited from the Action object. Gets


the type of the action.

WorkingDirector y Read/write Gets or sets the directory that


contains either the executable file or
the files that are used by the
executable file.

Remarks
If environment variables are used in the Path , Arguments , or WorkingDirector y properties, then the values
of the environment variables are cached and used when the Taskeng.exe (the task engine) is launched. Changes
to the environment variables that occur after the task engine is launched will not be used by the task engine.
This action performs a command-line operation. For example, the action could run a script or launch an
executable.
When reading or writing XML, an execution action is specified in the Exec element of the Task Scheduler
schema.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
ExecAction.Arguments property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the arguments associated with the command-line operation.

Syntax
ExecAction.Arguments As String

Property value
The arguments that are needed by the command-line operation.

Remarks
When reading or writing XML, the command-line operation arguments are specified in the Arguments element
of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
ExecAction
Task Scheduler
ExecAction.Path property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the path to an executable file.

Syntax
ExecAction.Path As String

Property value
The path to the executable file to be run by the action.

Remarks
This action performs a command-line operation. For example, the action could run a script or launch an
executable.
When reading or writing XML, the command-line operation path is specified in the Command element of the
Task Scheduler schema.
The path is checked to make sure it is valid when the task is registered, not when this property is set.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
ExecAction
Task Scheduler
ExecAction.WorkingDirectory property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the directory that contains either the executable file or the files that are used by the
executable file.

Syntax
ExecAction.WorkingDirectory As String

Property value
The directory that contains either the executable file or the files that are used by the executable file.

Remarks
When reading or writing XML, the working directory of the application is specified in the WorkingDirector y
element of the Task Scheduler schema.
The path is checked to make sure it is valid when the task is registered, not when this property is set.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
ExecAction
Task Scheduler
IdleSettings object
8/8/2022 • 2 minutes to read • Edit Online

A scripting object that specifies how the Task Scheduler performs tasks when the computer is in an idle
condition. For information about idle conditions, see Task Idle Conditions.

Members
The IdleSettings object has these types of members:
Properties
Properties
The IdleSettings object has these properties.

NOTE
The IdleDuration and WaitTimeout settings are deprecated. They're still present in the Task Scheduler user interface, and
their interface methods may still return valid values, but they're no longer used.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Restar tOnIdle Read/write Gets or sets a Boolean value that


indicates whether the task is restarted
when the computer cycles into an idle
condition more than once.

StopOnIdleEnd Read/write Gets or sets a Boolean value that


indicates that the Task Scheduler will
terminate the task if the idle condition
ends before the task is completed.

Deprecated : IdleDuration Read/write Gets or sets a value that indicates the


amount of time that the computer
must be in an idle state before the task
is run.

Deprecated : WaitTimeout Read/write Gets or sets a value that indicates the


amount of time that the Task
Scheduler will wait for an idle condition
to occur.

Remarks
When reading or writing XML for a task, this setting is specified in the IdleSettings element of the Task
Scheduler schema.
If a task is triggered by an idle trigger, then the IdleSettings.WaitTimeout property is ignored.
NOTE
IdleSettings.IdleDuration and IdleSettings.WaitTimeout are deprecated.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler Objects
Task Scheduler
IdleSettings.IdleDuration property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a value that indicates the amount of time that the computer must be in an idle state
before the task is run.

Syntax
IdleSettings.IdleDuration As String

Property value
A value that indicates the amount of time that the computer must be in an idle state before the task is run). The
format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD
is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of minutes,
and nS is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one
month, four days, two hours, and five minutes). The minimum value is one minute. If this value is NULL , then
the delay will be set to the default of 10 minutes.

Remarks
When reading or writing XML for a task, this setting is specified in the Duration element of the Task Scheduler
schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
IdleSettings
IdleSettings.RestartOnIdle property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates whether the task is restarted when the computer cycles
into an idle condition more than once.

Syntax
IdleSettings.RestartOnIdle As Boolean

Property value
A Boolean value that indicates whether the task must be restarted when the computer cycles into an idle
condition more than once. The default is False.

Remarks
This property is only used if the IdleSettings.StopOnIdleEnd property is set to True.
When reading or writing XML for a task, this setting is specified in the Restar tOnIdle element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
IdleSettings
IdleSettings.StopOnIdleEnd property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the Task Scheduler will terminate the task if the idle
condition ends before the task is completed.

Syntax
IdleSettings.StopOnIdleEnd As Boolean

Property value
A Boolean value that indicates that the Task Scheduler will terminate the task if the idle condition ends before
the task is completed.

Remarks
When reading or writing XML for a task, this setting is specified in the StopOnIdleEnd element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
IdleSettings
IdleSettings.WaitTimeout property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a value that indicates the amount of time that the Task Scheduler will wait for an idle
condition to occur. If no value is specified for this property, then the Task Scheduler service will wait indefinitely
for an idle condition to occur.

Syntax
IdleSettings.WaitTimeout As String

Property value
A value that indicates the amount of time that the Task Scheduler will wait for an idle condition to occur. The
format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD
is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of minutes,
and nS is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one
month, four days, two hours, and five minutes). The minimum time allowed is 1 minute. If this value is NULL ,
then the delay will be set to the default of 1 hour.

Remarks
When reading or writing XML for a task, this setting is specified in the WaitTimeout element of the Task
Scheduler schema.
If a task is triggered by an idle trigger, then the IdleSettings.WaitTimeout property is ignored.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
IdleSettings
IdleTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task when an idle condition occurs. For information about
idle conditions, see Task Idle Conditions.

Members
The IdleTrigger object has these types of members:
Properties
Properties
The IdleTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundary Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time in which the task can be started
by the trigger.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets a value that indicates how
often the task is run and how long the
repetition pattern is repeated after the
task is started.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

Remarks
An idle trigger will only trigger a task action if the computer goes into an idle state after the start boundary of
the trigger.
When reading or writing XML for a task, an idle trigger is specified using the IdleTrigger element of the Task
Scheduler schema.
If a task is triggered by an idle trigger, then the IdleSettings.WaitTimeout property is ignored.
If the initial instance of a task with an idle trigger is still running, then the task is only launched once with no
repetitions, even if multiple repetition is defined in the Repetition property. This behavior does not occur if the
task stops by itself.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
Task Scheduler Objects
Task Scheduler
LogonTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task when a user logs on. When the Task Scheduler service
starts, all logged-on users are enumerated and any tasks registered with logon triggers that match the logged
on user are run.

Members
The LogonTrigger object has these types of members:
Properties
Properties
The LogonTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Delay Read/write Gets or sets a value that indicates the


amount of time between when the
user logs on and when the job is
started.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time that the task launched by the
trigger is allowed to run.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets a value that indicates how
often the task is run and how long the
repetition pattern is repeated after the
task is started.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

UserId Read/write Gets or sets the identifier of the user.

Remarks
If you want a task to be triggered when any member of a group logs on to the computer rather than when a
specific user logs on, then do not assign a value to the LogonTrigger.UserId property. Instead, create a logon
trigger with an empty LogonTrigger.UserId property and assign a value to the principal for the task using the
Principal.GroupId property.
When reading or writing XML for a task, a logon trigger is specified using the LogonTrigger element of the
Task Scheduler schema.

Examples
For more information and example code for this scripting object, see Logon Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
LogonTrigger.Delay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a value that indicates the amount of time between when the user logs on and when
the task is started.

Syntax
LogonTrigger.Delay As String

Property value
A value that indicates the amount of time between when the user logs on and when the task is started. The
format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD
is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of minutes,
and nS is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one
month, four days, two hours, and five minutes).

Remarks
When reading or writing XML for a task, the logon trigger delay is specified using the Delay element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
LogonTrigger
Task Scheduler
LogonTrigger.UserId property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the identifier of the user.

Syntax
LogonTrigger.UserId As String

Property value
The identifier of the user. For example, "MyDomain\MyName" or for a local account, "Administrator".
This property can be in one of the following formats:
User name or SID: The task is started when the user logs on to the computer.
NULL: The task is started when any user logs on to the computer.

Remarks
If you want a task to be triggered when any member of a group logs on to the computer rather than when a
specific user logs on, then do not assign a value to the LogonTrigger.UserId property. Instead, create a logon
trigger with an empty LogonTrigger.UserId property and assign a value to the principal for the task using the
Principal.GroupId property.
When reading or writing XML for a task, the logon user identifier is specified using the UserId element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
LogonTrigger
Task Scheduler
MonthlyDOWTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task on a monthly day-of-week schedule. For example, the
task starts on every first Thursday, May through October.

Members
The MonthlyDOWTrigger object has these types of members:
Properties
Properties
The MonthlyDOWTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

DaysOfWeek Read/write Gets or sets the days of the week


during which the task runs.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundary Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time that the task launched by this
trigger is allowed to run.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

MonthsOfYear Read/write Gets or sets the months of the year


during which the task runs.

RandomDelay Read/write Gets or sets a delay time that is


randomly added to the start time of
the trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets how often the task is run
and how long the repetition pattern is
repeated after the task is started.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

RunOnLastWeekOfMonth Read/write Gets or sets a Boolean value that


indicates that the task runs on the last
week of the month.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

WeeksOfMonth Read/write Gets or sets the weeks of the month


during which the task runs.

Remarks
The time of day that the task is started is set by the Star tBoundar y property.
When reading or writing XML for a task, a monthly day-of-week trigger is specified using the
ScheduleByMonthDayOfWeek element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
Task Scheduler Objects
Task Scheduler
TriggerCollection
TriggerCollection.Create
MonthlyDOWTrigger.DaysOfWeek property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the days of the week during which the task runs.

Syntax
MonthlyDOWTrigger.DaysOfWeek As short

Property value
A bitwise mask that indicates the days of the week during which the task runs.

Remarks
The following table shows the mapping of the bitwise mask used by this property.

DAY O F W EEK H EX VA L UE DEC IM A L VA L UE

Sunday 0x01 1

Monday 0x02 2

Tuesday 0x04 4

Wednesday 0x08 8

Thursday 0x10 16

Friday 0x20 32

Saturday 0x40 64

When reading or writing XML for a task, the days of the week of a monthly day-of-week calendar are specified
by the DaysOfWeek element.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb
REQ UIREM EN T VA L UE

DLL
Taskschd.dll

See also
MonthlyDOWTrigger
Task Scheduler
MonthlyDOWTrigger.MonthsOfYear property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the months of the year during which the task runs.

Syntax
MonthlyDOWTrigger.MonthsOfYear As short

Property value
A bitwise mask that indicates the months of the year during which the task runs.

Remarks
The following table shows the mapping of the bitwise mask used by this property.

MONT H H EX VA L UE DEC IM A L VA L UE

January 0X01 1

February 0x02 2

March 0X04 4

April 0X08 8

May 0X10 16

June 0X20 32

July 0x40 64

August 0X80 128

September 0X100 256

October 0X200 512

November 0X400 1024

December 0X800 2048

When reading or writing XML for a task, the months of the year of a monthly day-of-week calendar are specified
by the Months element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
MonthlyDOWTrigger
Task Scheduler
MonthlyDOWTrigger.RandomDelay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a delay time that is randomly added to the start time of the trigger.

Syntax
MonthlyDOWTrigger.RandomDelay As String

Property value
The delay time that is randomly added to the start time of the trigger. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S (for example, P2DT5S is a 2 day, 5 second delay).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
MonthlyDOWTrigger
MonthlyDOWTrigger.RunOnLastWeekOfMonth
property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the task runs on the last week of the month.

Syntax
MonthlyDOWTrigger.RunOnLastWeekOfMonth As Boolean

Property value
True indicates that the task runs on the last week of the month; otherwise, False.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
MonthlyDOWTrigger
Task Scheduler
MonthlyDOWTrigger.WeeksOfMonth property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the weeks of the month during which the task runs.

Syntax
MonthlyDOWTrigger.WeeksOfMonth As short

Property value
A bitwise mask that indicates the days of the week during which the task runs.

Remarks
The following table shows the mapping of the bitwise mask used by this property.

W EEK H EX VA L UE DEC IM A L VA L UE

First week of the month 0X01 1

Second week of the month 0x02 2

Third week of the month 0X04 4

Fourth week of the month 0X08 8

When reading or writing XML for a task, the days of the week of a monthly day-of-week calendar are specified
by the Weeks element.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
MonthlyDOWTrigger
Task Scheduler
MonthlyTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task based on a monthly schedule. For example, the task
starts on specific days of specific months.

Members
The MonthlyTrigger object has these types of members:
Properties
Properties
The MonthlyTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

DaysOfMonth Read/write Gets or sets the days of the month


during which the task runs.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundary Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time that the task launched by the
trigger is allowed to run.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

MonthsOfYear Read/write Gets or sets the months of the year


during which the task runs.

RandomDelay Read/write Gets or sets a delay time that is


randomly added to the start time of
the trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets how often the task is run
and how long the repetition pattern is
repeated after the task is started.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

RunOnLastDayOfMonth Read/write Gets or sets a Boolean value that


indicates that the task runs on the last
day of the month.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

Remarks
The time of day that the task is started is set by the Star tBoundar y property.
When reading or writing your own XML for a task, a monthly trigger is specified using the ScheduleByMonth
element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
Task Scheduler Objects
Task Scheduler
TriggerCollection
TriggerCollection.Create
MonthlyTrigger.DaysOfMonth property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the days of the month during which the task runs.

Syntax
MonthlyTrigger.DaysOfMonth As long

Property value
A bitwise mask that indicates the days of the month during which the task runs.

Remarks
DAY O F M O N T H H EX VA L UE DEC IM A L VA L UE

1 0x01 1

2 0x02 2

3 0x04 4

4 0x08 8

5 0x10 16

6 0x20 32

7 0x40 64

8 0x80 128

9 0x100 256

10 0x200 512

11 0x400 1024

12 0x800 2048

13 0x1000 4096

14 0x2000 8192

15 0x4000 16384
DAY O F M O N T H H EX VA L UE DEC IM A L VA L UE

16 0x8000 32768

17 0x10000 65536

18 0x20000 131072

19 0x40000 262144

20 0x80000 524288

21 0x100000 1048576

22 0x200000 2097152

23 0x400000 4194304

24 0x800000 8388608

25 0x1000000 16777216

26 0x2000000 33554432

27 0x4000000 67108864

28 0x8000000 134217728

29 0x10000000 268435456

30 0x20000000 536870912

31 0x40000000 1073741824

Last 0x80000000 2147483648

When reading or writing your own XML for a task, the days of the month are specified using the DaysOfMonth
element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
See also
Task Scheduler
MonthlyTrigger
MonthlyTrigger.MonthsOfYear property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the months of the year during which the task runs.

Syntax
MonthlyTrigger.MonthsOfYear As short

Property value
A bitwise mask that indicates the months of the year during which the task runs.

Remarks
The following table shows the mapping of the bitwise mask that is used by this property.

MONT H H EX VA L UE DEC IM A L VA L UE

January 0X01 1

February 0x02 2

March 0X04 4

April 0X08 8

May 0X10 16

June 0X20 32

July 0x40 64

August 0X80 128

September 0X100 256

October 0X200 512

November 0X400 1024

December 0X800 2048

When reading or writing your own XML for a task, the months of the year are specified using the Months
element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
MonthlyTrigger
MonthlyTrigger.RandomDelay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a delay time that is randomly added to the start time of the trigger.

Syntax
MonthlyTrigger.RandomDelay As String

Property value
The delay time that is randomly added to the start time of the trigger. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S (for example, P2DT5S is a 2 day, 5 second delay).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
MonthlyTrigger
MonthlyTrigger.RunOnLastDayOfMonth property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the task runs on the last day of the month.

Syntax
MonthlyTrigger.RunOnLastDayOfMonth As Boolean

Property value
True indicates that the task runs on the last day of the month, regardless of the actual date of that day;
otherwise, False.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
MonthlyTrigger
NetworkSettings object
8/8/2022 • 2 minutes to read • Edit Online

For scripting, provides the settings that the Task Scheduler service uses to obtain a network profile.

Members
The NetworkSettings object has these types of members:
Properties
Properties
The NetworkSettings object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Id Read/write Gets or sets a GUID value that


identifies a network profile.

Name Read/write Gets or sets the name of a network


profile. The name is used for display
purposes.

Remarks
When reading or writing your own XML for a task, network settings are specified using the NetworkSettings
element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler Objects
Task Scheduler
NetworkSettings.Id property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a GUID value that identifies a network profile.

Syntax
NetworkSettings.Id As String

Property value
A GUID value that identifies a network profile.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
NetworkSettings
NetworkSettings.Name property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the name of a network profile. The name is used for display purposes.
This property is read/write.

Syntax
NetworkSettings.Name As String

Property value
The name of a network profile.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
NetworkSettings
Principal object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides the security credentials for a principal. These security credentials define the
security context for the tasks that are associated with the principal.

Members
The Principal object has these types of members:
Properties
Properties
The Principal object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

DisplayName Read/write Gets or sets the name of the principal


that is displayed in the Task Scheduler
UI.

GroupId Read/write Gets or sets the identifier of the user


group that is required to run the tasks
that are associated with the principal.

Id Read/write Gets or sets the identifier of the


principal.

LogonType Read/write Gets or sets the security logon method


that is required to run the tasks that
are associated with the principal.

RunLevel Read/write Gets or sets the identifier that is used


to specify the privilege level that is
required to run the tasks that are
associated with the principal.

UserId Read/write Gets or sets the user identifier that is


required to run the tasks that are
associated with the principal.

Remarks
When specifying an account, remember to properly use the double backslash in code to specify the domain and
user name. For example, use DOMAIN\\UserName to specify a value for the UserId property.
When reading or writing XML for a task, the security credentials for a principal are specified in the Principal
element of the Task Scheduler schema.
If a task is registered using the at.exe command line tool, and this object is used to retrieve information about
the task, then the LogonType property will return 0, the RunLevel property will return 0, and the UserId
property will return Nothing.
Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
Principal.DisplayName property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the name of the principal..

Syntax
Principal.DisplayName As String

Property value
The name of the principal.

Remarks
When reading or writing XML for a task, the display name for a principal is specified in the DisplayName
element of the Task Scheduler schema.
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will set
the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Principal
Principal.GroupId property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the identifier of the user group that is required to run the tasks that are associated
with the principal.

Syntax
Principal.GroupId As String

Property value
The identifier of the user group that is associated with this principal.

Remarks
Do not set this property if a user identifier is specified in the UserId property.
When reading or writing XML for a task, the group identifier for a principal is specified in the GroupId element
of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
UserId
Principal
Task Scheduler
Principal.Id property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the identifier of the principal.

Syntax
Principal.Id As String

Property value
The identifier of the principal.

Remarks
This identifier is also used when specifying the ActionCollection.Context property.
When reading or writing XML for a task, the identifier of the principal is specified in the Id attribute of the
Principal element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
ActionCollection.Context
Principal
Task Scheduler
Principal.LogonType property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the security logon method that is required to run the tasks that are associated with the
principal.

Syntax
Principal.LogonType As Integer

Property value
Set to one of the following TASK_LOGON TYPE enumeration constants.

VA L UE M EA N IN G

The logon method is not specified. Used for non-NT


TASK_LOGON_NONE credentials.
0

Use a password for logging on the user. The password must


TASK_LOGON_PASSWORD be supplied at registration time.
1

Use an existing interactive token to run a task. The user


TASK_LOGON_S4U must log on using a service for user (S4U) logon. When an
2 S4U logon is used, no password is stored by the system and
there is no access to either the network or encrypted files.

User must already be logged on. The task will be run only in
TASK_LOGON_INTERACTIVE_TOKEN an existing interactive session.
3

Group activation. The userId field specifies the group.


TASK_LOGON_GROUP
4

Indicates that a Local System, Local Service, or Network


TASK_LOGON_SERVICE_ACCOUNT Service account is being used as a security context to run
5 the task.

First use the interactive token. If the user is not logged on


TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD (no interactive token is available), then the password is used.
6 The password must be specified when a task is registered.
This flag is not recommended for new tasks because it is less
reliable than TASK_LOGON_PASSWORD.

Remarks
This property is valid only when a user identifier is specified by the UserId property.
When reading or writing XML for a task, the logon type is specified in the <LogonType> element of the Task
Scheduler schema.
For a task, that contains a message box action, the message box will be displayed if the task is activated and the
task has an interactive logon type. To set the task logon type to interactive, specify 3
(TASK_LOGON_INTERACTIVE_TOKEN ) or 4 (TASK_LOGON_GROUP ) in the LogonType property of the
task principal, or in the logonType parameter of TaskFolder.RegisterTask or
TaskFolder.RegisterTaskDefinition .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Principal
Principal.UserId property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the user identifier that is required to run the tasks that are associated with the
principal.

Syntax
Principal.UserId As String

Property value
The user identifier that is required to run the task.

Remarks
Do not set this property if a group identifier is specified in the GroupId property.
When reading or writing XML for a task, the user identifier for the principal is specified using the UserId
element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Principal
Principal.GroupId
Principal.RunLevel property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the identifier that is used to specify the privilege level that is required to run the tasks
that are associated with the principal.
This property is read/write.

Syntax
Principal.RunLevel As Integer

Property value
The identifier that is used to specify the privilege level that is required to run the tasks that are associated with
the principal.

VA L UE M EA N IN G

Tasks will be run with the least privileges (LUA).


TASK_RUNLEVEL_LUA
0

Tasks will be run with the highest privileges.


TASK_RUNLEVEL_HIGHEST
1

Remarks
If a task is registered using the Builtin\Administrator account or the Local System or Local Service accounts, then
the RunLevel property will be ignored. The property value will also be ignored if User Account Control (UAC) is
turned off.
If a task is registered using the Administrators group for the security context of the task, then you must also set
the RunLevel property to TASK_RUNLEVEL_HIGHEST if you want to run the task. For more information, see
Security Contexts for Tasks.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb
REQ UIREM EN T VA L UE

DLL
Taskschd.dll

See also
Principal
RegisteredTask object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides the methods that are used to run the task immediately, get any running instances
of the task, get or set the credentials that are used to register the task, and the properties that describe the task.

Members
The RegisteredTask object has these types of members:
Methods
Properties
Methods
The RegisteredTask object has these methods.

M ET H O D DESC RIP T IO N

GetInstances Returns all instances of the registered task that are currently
running.

GetRunTimes Gets the times that the registered task is scheduled to run
during a specified time.

GetSecurityDescriptor Gets the security descriptor that is used as credentials for


the registered task.

Run Runs the registered task immediately.

RunEx Runs the registered task immediately using specified flags


and a session identifier.

SetSecurityDescriptor Sets the security descriptor that is used as credentials for the
registered task.

Stop Stops the registered task immediately.

Properties
The RegisteredTask object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Definition Read-only Gets the definition of the task.

Enabled Read/write Gets or set a Boolean value that


indicates if the registered task is
enabled.

LastRunTime Read-only Gets the time the registered task was


last run.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

LastTaskResult Read-only Gets the results that were returned the


last time the registered task was run.

Name Read-only Gets the name of the registered task.

NextRunTime Read-only Gets the time when the registered task


is next scheduled to run.

NumberOfMissedRuns Read-only Gets the number of times the


registered task has missed a scheduled
run.

Path Read-only Gets the path to where the registered


task is stored.

State Read-only Gets the operational state of the


registered task.

XML Read-only Gets the XML-formatted registration


information for the registered task.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting) and
Displaying Task Names and States (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
RegisteredTask.Definition property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the definition of the task.


This property is read-only.

Syntax
RegisteredTask.Definition As TaskDefinition

Property value
The definition of the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
RegisteredTask
RegisteredTask.Enabled property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates if the registered task is enabled.

Syntax
RegisteredTask.Enabled As Boolean

Property value
A Boolean value that indicates if the registered task is enabled.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.LastRunTime property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the time the registered task was last run.

Syntax
RegisteredTask.LastRunTime As String

Property value
The time the registered task was last run.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.LastTaskResult property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the results that were returned the last time the registered task was run.

Syntax
RegisteredTask.LastTaskResult As String

Property value
The results that were returned the last time the registered task was run.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.Name property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the name of the registered task.

Syntax
RegisteredTask.Name As String

Property value
The name of the registered task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.NextRunTime property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the time when the registered task is next scheduled to run.

Syntax
RegisteredTask.NextRunTime As String

Property value
The time when the registered task is next scheduled to run.

Remarks
If the registered task contains triggers that are individually disabled, these triggers will still affect the next
scheduled run time that is returned even though they are disabled.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.NumberOfMissedRuns property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the number of times the registered task has missed a scheduled run.

Syntax
RegisteredTask.NumberOfMissedRuns As Integer

Property value
The number of times the registered task missed a scheduled run.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.Path property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the path to where the registered task is stored.

Syntax
RegisteredTask.Path As String

Property value
The path to where the registered task is stored.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.State property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the operational state of the registered task.

Syntax
RegisteredTask.State As Integer

Property value
A TASK_STATE constant that defines the operational state of the task.

VA L UE M EA N IN G

The state of the task is unknown.


TASK_STATE_UNKNOWN
0

The task is registered but is disabled and no instances of the


TASK_STATE_DISABLED task are queued or running. The task cannot be run until it is
1 enabled.

Instances of the task are queued.


TASK_STATE_QUEUED
2

The task is ready to be executed, but no instances are


TASK_STATE_READY queued or running.
3

One or more instances of the task are running.


TASK_STATE_RUNNING
4

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb
REQ UIREM EN T VA L UE

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.XML property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the XML-formatted registration information for the registered task.

Syntax
RegisteredTask.XML As String

Property value
The XML-formatted registration information for the registered task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.GetInstances method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, returns all currently running instances of the registered task.

NOTE
RegisteredTask .GetInstances will only return instances of the currently running registered task that are running at or
below a user's security context. For example, for members of the Administrators group, GetInstances will return all
instances of the currently running registered task, but for members of the Users group, GetInstances will only return
instances of the currently running registered task that are running under the Users group security context.

Syntax
RegisteredTask.GetInstances( _
ByVal flags, _
ByRef runningTasks _
)

Parameters
flags
This parameter is reserved for future use and must be set to 0.
runningTasks [out]
A RunningTaskCollection object that contains all currently running instances of the task.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.GetRunTimes method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the times that the registered task is scheduled to run during a specified time.

Syntax
RegisteredTask.GetRunTimes( _
ByVal begin, _
ByVal end, _
ByRef count, _
ByRef rgstTaskTimes _
)

Parameters
begin [in]
The starting time for the query.
end [in]
The ending time for the query.
count [out]
The number of scheduled times the task will run.
rgstTaskTimes [out]
The scheduled times that the task will run.

Return value
This method does not return a value.

Remarks
If the registered task contains triggers that are individually disabled, these triggers will still affect the next
scheduled run time that is returned even though they are disabled.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb
REQ UIREM EN T VA L UE

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.GetSecurityDescriptor method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the security descriptor that is used as credentials for the registered task.

Syntax
sddl = .GetSecurityDescriptor( _
ByVal securityInformation _
)

Parameters
securityInformation
The security information from SECURITY_INFORMATION .

Return value
The security descriptor for the registered task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
RegisteredTask
TaskFolder.GetSecurityDescriptor
RegisteredTask .SetSecurityDescriptor
RegisteredTask.Run method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, runs the registered task immediately.

Syntax
RegisteredTask.Run( _
ByVal params, _
ByRef ppRunningTask _
)

Parameters
params [in]
The parameters used as values in the task actions. To not specify any parameter values for the task actions, set
this parameter to Nothing . Otherwise, a single string value or an array of string values can be specified.
The string values that you specify are paired with names and stored as name-value pairs. If you specify a single
string value, then Arg0 will be the name assigned to the value. The value can be used in the task action where
the $(Arg0) variable is used in the action properties.
If you pass in values such as "0", "100", and "250" as an array of string values, then "0" will replace the $(Arg0)
variables, "100" will replace the $(Arg1) variables, and "250" will replace the $(Arg2) variables used in the action
properties.
A maximum of 32 string values can be specified.
For more information and a list of action properties that can use $(Arg0), $(Arg1), ..., $(Arg32) variables in their
values, see Task Actions.
ppRunningTask [out]
A RunningTask object that defines the new instance of the task.

Return value
This method does not return a value.

Remarks
The RegisteredTask .Run function is equivalent to the RegisteredTask .RunEx function with the flags
parameter equal to 0 and nothing specified for the user parameter.
This method will return without error, but the task will not run if the TaskSettings.AllowDemandStar t
property is set to false for the registered task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.RunEx method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, runs the registered task immediately using specified flags and a session identifier.

Syntax
RegisteredTask.RunEx( _
ByVal params, _
ByVal flags, _
ByVal sessionID, _
ByRef runningTask _
)

Parameters
params [in]
The parameters used as values in the task actions. To not specify any parameter values for the task actions, set
this parameter to Nothing . Otherwise, a single string value or an array of string values can be specified.
The string values that you specify are paired with names and stored as name-value pairs. If you specify a single
string value, then Arg0 will be the name assigned to the value. The value can be used in the task action where
the $(Arg0) variable is used in the action properties.
If you pass in values such as "0", "100", and "250" as an array of string values, then "0" will replace the $(Arg0)
variables, "100" will replace the $(Arg1) variables, and "250" will replace the $(Arg2) variables used in the action
properties.
A maximum of 32 string values can be specified.
For more information and a list of action properties that can use $(Arg0), $(Arg1), ..., $(Arg32) variables in their
values, see Task Actions.
flags [in]
A TASK_RUN_FLAGS constant that defines how the task is run.
sessionID [in]
The terminal server session in which you want to launch the task.
If the TASK_RUN_USE_SESSION_ID constant (0x4) is not passed into the flags parameter, then the value specified
in this parameter is ignored. If the TASK_RUN_USE_SESSION_ID constant is passed into the flags parameter and
the sessionID value is less than or equal to 0, then an invalid argument error will be returned.
If the TASK_RUN_USE_SESSION_ID constant is passed into the flags parameter and the sessionID value is a valid
session ID greater than 0 and if no value is specified for the user parameter, then the Task Scheduler service will
try to launch the task interactively as the user who is logged on to the specified session.
If the TASK_RUN_USE_SESSION_ID constant is passed into the flags parameter and the sessionID value is a valid
session ID greater than 0 and if a user is specified in the user parameter, then the Task Scheduler service will try
to launch the task interactively as the user who is specified in the user parameter.
runningTask [out]
A RunningTask object that defines the new instance of the task.

Return value
This method does not return a value.

Remarks
This method will return without error, but the task will not run if the TaskSettings.AllowDemandStar t
property is set to false for the registered task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
RegisteredTask.SetSecurityDescriptor method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, sets the security descriptor that is used as credentials for the registered task.

Syntax
RegisteredTask.SetSecurityDescriptor( _
ByVal sddl, _
ByVal flags _
)

Parameters
sddl [in]
The security descriptor that is used as credentials for the registered task.

NOTE
If the Local System account is denied access to a task, then the Task Scheduler service can produce unexpected results.

flags [in]
Flags that specify how to set the security descriptor. The TASK_DONT_ADD_PRINCIPAL_ACE flag (0x10) from the
TASK_CREATION enumeration can be specified.

Return value
This method does not return a value.

Remarks
You can specify the access control list (ACL) in the security descriptor for a task in order to allow or deny certain
users and groups access to a task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb
REQ UIREM EN T VA L UE

DLL
Taskschd.dll

See also
RegisteredTask
TaskFolder.GetSecurityDescriptor
RegisteredTask .SetSecurityDescriptor
RegisteredTask.Stop method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, stops the registered task immediately.

Syntax
RegisteredTask.Stop( _
ByVal flags _
)

Parameters
flags [in]
Reserved. Must be zero.

Return value
This method does not return a value.

Remarks
The RegisteredTask .Stop function stops all instances of the task.
System account users can stop a task, users with Administrator group privileges can stop a task, and if a user
has rights to execute and read a task, then the user can stop the task. A user can stop the task instances that are
running under the same credentials as the user account. In all other cases, the user is denied access to stop the
task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
RegisteredTask
RegisteredTaskCollection object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that contains all the tasks that are registered.

Members
The RegisteredTaskCollection object has these types of members:
Properties
Properties
The RegisteredTaskCollection object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Count Read-only Gets the number of registered tasks in


the collection.

Item Read-only Gets the specified registered task from


the collection.

Examples
For more information and example code for this scripting object, see Displaying Task Names and States
(Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskFolder.GetTasks
RegisteredTaskCollection.Count property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the number of registered tasks in the collection.


This property is read-only.

Syntax
RegisteredTaskCollection.Count As long

Property value
The number of registered tasks in the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTaskCollection.Item property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the specified registered task from the collection.
This property is read-only.

Syntax
RegisteredTaskCollection.Item( _
ByVal Index _
) As RegisteredTask

Property value
A RegisteredTask object that contains the registered task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationInfo object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides the administrative information that can be used to describe the task. This
information includes details such as a description of the task, the author of the task, the date the task is
registered, and the security descriptor of the task.

Members
The RegistrationInfo object has these types of members:
Properties
Properties
The RegistrationInfo object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Author Read/write Gets or sets the author of the task.

Date Read/write Gets or sets the date and time when


the task is registered.

Description Read/write Gets or sets the description of the


task.

Documentation Read/write Gets or sets any additional


documentation for the task.

SecurityDescriptor Gets or sets the security descriptor of


the task.

Source Read/write Gets or sets where the task originated


from. For example, a task may
originate from a component, service,
application, or user.

URI Read/write Gets or sets the URI of the task.

Version Read/write Gets or sets the version number of the


task.

XmlText Read/write Gets or sets an XML-formatted version


of the registration information for the
task.

Remarks
Registration information can be used to identify a task through the Task Scheduler UI, or as search criteria when
enumerating over the registered tasks.
When reading or writing XML for a task, registration information for the task is specified in the
RegistrationInfo element of the Task Scheduler schema.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
RegistrationInfo.Author property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the author of the task.

Syntax
RegistrationInfo.Author As String

Property value
The author of the task.

Remarks
When reading or writing XML for a task, the task author is specified using the Author element of the Task
Scheduler schema.
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, the setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will
set the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationInfo.Date property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the date and time when the task is registered.

Syntax
RegistrationInfo.Date As String

Property value
The registration date of the task.

Remarks
When reading or writing XML for a task, the registration date is specified using the Date element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationInfo.Description property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the description of the task.

Syntax
RegistrationInfo.Description As String

Property value
The description of the task.

Remarks
When reading or writing XML for a task, the description of the task is specified using the Description element
of the Task Scheduler schema.
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, the setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will
set the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationInfo.Documentation property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets any additional documentation for the task.

Syntax
RegistrationInfo.Documentation As String

Property value
Any additional documentation that is associated with the task.

Remarks
When reading or writing XML for a task, the additional documentation for the task is specified using the
Documentation element of the Task Scheduler schema.
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, the setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will
set the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationInfo.SecurityDescriptor property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the security descriptor of the task. If a different security descriptor is supplied during
task registration, it will supersede the security descriptor set with this property.

Syntax
RegistrationInfo.SecurityDescriptor As String

Property value
The security descriptor that is associated with the task.

Remarks
When reading or writing XML for a task, the security descriptor of the task is specified using the
SecurityDescriptor element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationInfo.Source property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets where the task originated from. For example, a task may originate from a component,
service, application, or user.

Syntax
RegistrationInfo.Source As String

Property value
Where the task originated from. For example, from a component, service, application, or user.

Remarks
When reading or writing XML for a task, the task source information is specified using the Source element of
the Task Scheduler schema.
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, the setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will
set the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationInfo.URI property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the URI of the task.


This property is read/write.

Syntax
RegistrationInfo.URI As String

Property value
The URI of the task.

Remarks
When reading or writing XML for a task, the task URI is specified using the URI element of the Task Scheduler
schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
RegistrationInfo.Version property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the version number of the task.

Syntax
RegistrationInfo.Version As String

Property value
The version number of the task.

Remarks
When reading or writing XML for a task, the version number of the task is specified using the Version element
of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationInfo.XmlText property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets an XML-formatted version of the registration information for the task.

Syntax
RegistrationInfo.XmlText As String

Property value
An XML-formatted version of the task registration information.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegistrationTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task when the task is registered or updated.

Members
The RegistrationTrigger object has these types of members:
Properties
Properties
The RegistrationTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Delay Read/write Gets or sets the amount of time


between when the task is registered
and when the task is started.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time that the task launched by the
trigger is allowed to run.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets how often the task is run
and how long the repetition pattern is
repeated after the task is started.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

Remarks
When creating your own XML for a task, a registration trigger is specified using the RegistrationTrigger
element of the Task Scheduler schema.
If a task with a delayed registration trigger is registered, and the computer that the task is registered on is
shutdown or restarted during the delay, before the task runs, then the task will not run and the delay will be lost.

Examples
For more information and a code example for this scripting object, see Registration Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
TriggerCollection
TriggerCollection.Create
RegistrationTrigger.Delay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the amount of time between when the task is registered and when the task is started.
The format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months,
nD is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of
minutes, and nS is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies
one month, four days, two hours, and five minutes).

Syntax
RegistrationTrigger.Delay As String

Property value
The amount of time between when the system is registered and when the task is started.

Remarks
When reading or writing XML for a task, the boot delay is specified using the Delay element of the Task
Scheduler schema.
If a task with a delayed registration trigger is registered, and the computer that the task is registered on is
shutdown or restarted during the delay, before the task runs, then the task will not run and the delay will be lost.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RepetitionPattern object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that defines how often the task is run and how long the repetition pattern is repeated after the
task is started.

Members
The RepetitionPattern object has these types of members:
Properties
Properties
The RepetitionPattern object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Duration Read/write Gets or sets how long the pattern is


repeated.

Inter val Read/write Gets or sets the amount of time


between each restart of the task.

StopAtDurationEnd Read/write Gets or sets a Boolean value that


indicates if a running instance of the
task is stopped at the end of the
repetition pattern duration.

Remarks
If you specify a repetition duration for a task, you must also specify the repetition interval.
If you register a task that contains a trigger with a repetition interval equal to one minute and a repetition
duration equal to four minutes, the task will be launched five times. The five repetitions can be defined by the
following pattern.
1. A task starts at the beginning of the first minute.
2. The next task starts at the end of the first minute.
3. The next task starts at the end of the second minute.
4. The next task starts at the end of the third minute.
5. The next task starts at the end of the fourth minute.
Windows Ser ver 2003, Windows XP and Windows 2000: If you register a task that contains a trigger with
a repetition interval equal to one minute and a repetition duration equal to four minutes, the task will be
launched four times.
When reading or writing XML for a task, the repetition pattern is specified using the Repetition element of the
Task Scheduler schema.

Examples
For more information and example code for this property, see Daily Trigger Example (Scripting).
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler Objects
Task Scheduler
RepetitionPattern.Duration property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets how long the pattern is repeated.

Syntax
RepetitionPattern.Duration As String

Property value
How long the pattern is repeated. The format for this string is PnYnMnDTnHnMnS, where nY is the number of
years, nM is the number of months, nD is the number of days, 'T' is the date/time separator, nH is the number of
hours, nM is the number of minutes, and nS is the number of seconds (for example, PT5M specifies 5 minutes
and P1M4DT2H5M specifies one month, four days, two hours, and five minutes). The minimum time allowed is
one minute.
If no value is specified for the duration, then the pattern is repeated indefinitely.

Remarks
If you specify a repetition duration for a task, you must also specify the repetition interval.
When reading or writing XML for a task, the repetition duration is specified in the Duration element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RepetitionPattern.Interval property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the amount of time between each restart of the task.

Syntax
RepetitionPattern.Interval As String

Property value
The amount of time between each restart of the task. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S (for example, "PT5M" is 5 minutes, "PT1H" is 1 hour, and "PT20M" is 20
minutes). The maximum time allowed is 31 days, and the minimum time allowed is 1 minute.

Remarks
If you specify a repetition duration for a task, you must also specify the repetition interval.
When reading or writing XML for a task, the repetition interval is specified in the Inter val element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RepetitionPattern.StopAtDurationEnd property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates if a running instance of the task is stopped at the end of
the repetition pattern duration.

Syntax
RepetitionPattern.StopAtDurationEnd As Boolean

Property value
A Boolean value that indicates if a running instance of the task is stopped at the end of the repetition pattern
duration.

Remarks
When reading or writing XML for a task, this information is specified in the StopAtDurationEnd element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RunningTask object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides the methods to get information from and control a running task.

Members
The RunningTask object has these types of members:
Methods
Properties
Methods
The RunningTask object has these methods.

M ET H O D DESC RIP T IO N

Refresh Refreshes all of the local instance variables of the task.

Stop Stops this instance of the task.

Properties
The RunningTask object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

CurrentAction Read-only Gets the name of the current action


that the running task is performing.

EnginePID Read-only Gets the process ID for the engine


(process) which is running the task.

InstanceGuid Read-only Gets the GUID identifier for this


instance of the task.

Name Read-only Gets the name of the task.

Path Read-only Gets the path to where the task is


stored.

State Read-only Gets the state of the running task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


REQ UIREM EN T VA L UE

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler Objects
Task Scheduler
RunningTaskCollection
RegisteredTask .Run
RegisteredTask .RunEx
RunningTask.CurrentAction property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the name of the current action that the running task is performing.
This property is read-only.

Syntax
RunningTask.CurrentAction As String

Property value
The name of the current action that the running task is performing.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
RunningTask.EnginePID property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the process ID for the engine (process) which is running the task.
This property is read-only.

Syntax
RunningTask.EnginePID As Integer

Property value
The process ID for the engine which is running the task.

Remarks
The process ID returned by this property cannot be appended directly to a string. The returned value needs to be
converted to an integer value first by calling the CInt function on the returned value.

ProcessId = cint(RunningTask.EnginePID)
wscript.echo "Process Id of Engine is " & "ProcessId

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
RunningTask.InstanceGuid property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the GUID identifier for this instance of the task.

Syntax
RunningTask.InstanceGuid As string

Property value
The GUID identifier for this instance of the task. An identifier is generated by the Task Scheduler service each
time the task is run.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RunningTask.Name property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the name of the task.

Syntax
RunningTask.Name As string

Property value
The name of the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RunningTask.Path property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the path to where the task is stored.

Syntax
RunningTask.Path As string

Property value
The path to where the task is stored.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RunningTask.State property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets an identifier for the state of the running task.
This property is read-only.

Syntax
RunningTask.State As String

Property value
An identifier for the state of the running task.

VA L UE M EA N IN G

The state of the task is unknown.


TASK_STATE_UNKNOWN
0

The task is registered but is disabled and no instances of the


TASK_STATE_DISABLED task are queued or running. The task cannot be run until it is
1 enabled.

Instances of the task are queued.


TASK_STATE_QUEUED
2

The task is ready to be executed, but no instances are


TASK_STATE_READY queued or running.
3

One or more instances of the task are running.


TASK_STATE_RUNNING
4

Remarks
The RunningTask .Refresh method is called before the property value is returned.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


REQ UIREM EN T VA L UE

Type library
Taskschd.tlb

DLL
Taskschd.dll
RunningTask.Refresh method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, refreshes all of the local instance variables of the task.

Syntax
RunningTask.Refresh()

Parameters
This method has no parameters.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RunningTask.Stop method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, stops this instance of the task.

Syntax
RunningTask.Stop()

Parameters
This method has no parameters.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RunningTaskCollection object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides a collection that is used to control running tasks.

Members
The RunningTaskCollection object has these types of members:
Properties
Properties
The RunningTaskCollection object has these properties.

P RO P ERT Y DESC RIP T IO N

Count Gets the number of running tasks in the collection.

Item Gets the specified task from the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler Objects
Task Scheduler
RunningTask
TaskSer vice.GetRunningTasks
RegisteredTask .GetInstances
RunningTaskCollection.Count property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the number of running tasks in the collection.

Syntax
RunningTaskCollection.Count As long

Property value
The number of running tasks in the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RunningTaskCollection.Item property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the specified task from the collection.

Syntax
RunningTaskCollection.Item( _
ByVal Index _
) As RunningTask

Property value
A RunningTask object that contains the requested context.

Remarks
Collections are 1-based. In other words, the index for the first item in the collection is 1.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
SessionStateChangeTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that triggers tasks for console connect or disconnect, remote connect or disconnect, or
workstation lock or unlock notifications.

Members
The SessionStateChangeTrigger object has these types of members:
Properties
Properties
The SessionStateChangeTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Delay Read/write Gets or sets a value that indicates how


long of a delay takes place before a
task is started after a Terminal Server
session state change is detected.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time in which the task can be started
by the trigger.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets a value that indicates how
often the task is run and how long the
repetition pattern is repeated after the
task is started.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

StateChange Read/write Gets or sets the kind of Terminal


Server session change that would
trigger a task launch.

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

UserId Read/write Gets or sets the user for the Terminal


Server session. When a session state
change is detected for this user, a task
is started.

Remarks
When reading or writing your own XML for a task, a session state change trigger is specified using the
SessionStateChangeTrigger element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TriggerCollection
TriggerCollection.Create
SessionStateChangeTrigger.Delay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a value that indicates how long of a delay takes place before a task is started after a
Terminal Server session state change is detected. The format for this string is PnYnMnDTnHnMnS, where nY is
the number of years, nM is the number of months, nD is the number of days, 'T' is the date/time separator, nH is
the number of hours, nM is the number of minutes, and nS is the number of seconds (for example, PT5M
specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours, and five minutes).

Syntax
SessionStateChangeTrigger.Delay As String

Property value
The delay that takes place before a task is started after a Terminal Server session state change is detected.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
SessionStateChangeTrigger.StateChange property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the kind of Terminal Server session change that would trigger a task launch.

Syntax
SessionStateChangeTrigger.StateChange As Integer

Property value
The kind of Terminal Server session change that triggers a task to launch.
The possible values are from the TASK_SESSION_STATE_CHANGE_TYPE enumeration.

VA L UE M EA N IN G

Terminal Server console connection state change. For


TASK_CONSOLE_CONNECT example, when you connect to a user session on the local
1 computer by switching users on the computer.

Terminal Server console disconnection state change. For


TASK_CONSOLE_DISCONNECT example, when you disconnect to a user session on the local
2 computer by switching users on the computer.

Terminal Server remote connection state change. For


TASK_REMOTE_CONNECT example, when a user connects to a user session by using
3 the Remote Desktop Connection program from a remote
computer.

Terminal Server remote disconnection state change. For


TASK_REMOTE_DISCONNECT example, when a user disconnects from a user session while
4 using the Remote Desktop Connection program from a
remote computer.

Terminal Server session locked state change. For example,


TASK_SESSION_LOCK this state change causes the task to run when the computer
7 is locked.

Terminal Server session unlocked state change. For example,


TASK_SESSION_UNLOCK this state change causes the task to run when the computer
8 is unlocked.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]


REQ UIREM EN T VA L UE

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
SessionStateChangeTrigger.UserId property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the user for the Terminal Server session. When a session state change is detected for
this user, a task is started.

Syntax
SessionStateChangeTrigger.UserId As String

Property value
The user for the Terminal Server session.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
ShowMessageAction object
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. You can use IExecAction with the Windows scripting MsgBox function to
show a message in the user session.]
For scripting, represents an action that shows a message box when a task is activated.

Members
The ShowMessageAction object has these types of members:
Properties
Properties
The ShowMessageAction object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Id Read/write Inherited from the Action object. Gets


or sets the identifier of the action.

MessageBody Read/write Gets or sets the message text that is


displayed in the body of the message
box.

Title Read/write Gets or sets the title of the message


box.

Type Read-only Inherited from the Action object. Gets


the type of the action.

Remarks
For a task, that contains a message box action, the message box will be displayed if the task is activated and the
task has an interactive logon type. To set the task logon type to interactive, specify 3
(TASK_LOGON_INTERACTIVE_TOKEN ) or 4 (TASK_LOGON_GROUP ) in the LogonType property of the
task principal, or in the logonType parameter of TaskFolder.RegisterTask or
TaskFolder.RegisterTaskDefinition .
When reading or writing your own XML for a task, a message box action is specified using the ShowMessage
element of the Task Scheduler schema.

Examples
For more information and example code for this scripting object, see Message Box Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll
ShowMessageAction.MessageBody property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. You can use IExecAction with the Windows scripting MsgBox function to
show a message in the user session.]
For scripting, gets or sets the message text that is displayed in the body of the message box.

Syntax
ShowMessageAction.MessageBody As String

Property value
The message text that is displayed in the body of the message box.

Remarks
Parameterized strings can be used in the message text of the message box. For more information, see the
Examples section in EventTrigger.ValueQueries .
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, the setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will
set the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
ShowMessageAction
ShowMessageAction.Title property
8/8/2022 • 2 minutes to read • Edit Online

[This object is no longer supported. You can use IExecAction with the Windows scripting MsgBox function to
show a message in the user session.]
For scripting, gets or sets the title of the message box.

Syntax
ShowMessageAction.Title As String

Property value
The title of the message box.

Remarks
Parameterized strings can be used in the title text of the message box. For more information, see the Examples
section in EventTrigger.ValueQueries .
When setting this property value, the value can be text that is retrieved from a resource .dll file. A specialized
string is used to reference the text from the resource file. The format of the string is $(@ [Dll], [ResourceID])
where [Dll] is the path to the .dll file that contains the resource and [ResourceID] is the identifier for the resource
text. For example, the setting this property value to $(@ %SystemRoot%\System32\ResourceName.dll, -101) will
set the property to the value of the resource text with an identifier equal to -101 in the
%SystemRoot%\System32\ResourceName.dll file.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
ShowMessageAction
TaskDefinition object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that defines all the components of a task, such as the task settings, triggers, actions, and
registration information.

Members
The TaskDefinition object has these types of members:
Properties
Properties
The TaskDefinition object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Actions Read/write Gets or sets a collection of actions that


are performed by the task.

Data Read/write Gets or sets the data that is associated


with the task. This data is ignored by
the Task Scheduler service, but is used
by third-parties who wish to extend
the task format.

Principal Read/write Gets or sets the principal for the task


that provides the security credentials
for the task.

RegistrationInfo Read/write Gets or sets the registration


information that is used to describe a
task, such as the description of the
task, the author of the task, and the
date the task is registered.

Settings Read/write Gets or sets the settings that define


how the Task Scheduler service
performs the task.

Triggers Read/write Gets or sets a collection of triggers


that are used to start a task.

XmlText Read/write Gets or sets the XML-formatted


definition of the task.

Remarks
When reading or writing your own XML for a task, a task definition is specified using the Task element of the
Task Scheduler schema.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting) , Event
Trigger Example (Scripting), Daily Trigger Example (Scripting), Registration Trigger Example (Scripting), Weekly
Trigger Example (Scripting), Logon Trigger Example (Scripting), or Boot Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskDefinition.Actions property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a collection of actions that are performed by the task.

Syntax
TaskDefinition.Actions As ActionCollection

Property value
A collection of actions that are performed by the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
ActionCollection
Action
TaskDefinition.Data property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the data that is associated with the task. This data is ignored by the Task Scheduler
service, but is used by third-parties who wish to extend the task format.

Syntax
TaskDefinition.Data As String

Property value
The data that is associated with the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskDefinition.Principal property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the principal for the task that provides the security credentials for the task.
This property is read/write.

Syntax
TaskDefinition.Principal As Principal

Property value
The principal for the task that provides the security credentials for the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Principal
TaskDefinition.RegistrationInfo property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the registration information that is used to describe a task, such as the description of
the task, the author of the task, and the date the task is registered.

Syntax
TaskDefinition.RegistrationInfo As RegistrationInfo

Property value
The registration information that is used to describe a task, such as the description of the task, the author of the
task, and the date the task is registered.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
RegistrationInfo
TaskDefinition.Settings property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the settings that define how the Task Scheduler service performs the task.

Syntax
TaskDefinition.Settings As TaskSettings

Property value
The settings that define how the Task Scheduler service performs the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskSettings
TaskDefinition.Triggers property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a collection of triggers that are used to start a task.

Syntax
TaskDefinition.Triggers As TriggerCollection

Property value
A collection of triggers that are used to start a task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TriggerCollection
Trigger
TaskDefinition.XmlText property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the XML-formatted definition of the task.

Syntax
TaskDefinition.XmlText As String

Property value
The XML-formatted definition of the task.

Remarks
The XML for a task is defined by the Task Scheduler Schema. For an example of task XML, see Daily Trigger
Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskFolder object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides the methods that are used to register (create) tasks in the folder, remove tasks
from the folder, and create or remove subfolders from the folder.

Members
The TaskFolder object has these types of members:
Methods
Properties
Methods
The TaskFolder object has these methods.

M ET H O D DESC RIP T IO N

CreateFolder Creates a folder for related tasks.

DeleteFolder Deletes a subfolder from the parent folder.

DeleteTask Deletes a task from the folder.

GetFolder Gets a folder that contains tasks at a specified location.

GetFolders Gets all the subfolders in the folder.

GetSecurityDescriptor Gets the security descriptor for the folder.

GetTask Gets a task at a specified location in a folder.

GetTasks Gets all the tasks in the folder.

RegisterTask Registers (creates) a new task in the folder using XML to


define the task.

RegisterTaskDefinition Registers (creates) a task in a specified location using the


ITaskDefinition interface to define a task.

SetSecurityDescriptor Sets the security descriptor for the folder.

Properties
The TaskFolder object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Name Read-only Gets the name that is used to identify


the folder that contains a task.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Path Read-only Gets the path to where the folder is


stored.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting), Event
Trigger Example (Scripting), Daily Trigger Example (Scripting), Registration Trigger Example (Scripting), Weekly
Trigger Example (Scripting), Logon Trigger Example (Scripting), Boot Trigger Example (Scripting), or Displaying
Task Names and States (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler Objects
Task Scheduler
TaskFolder.CreateFolder method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, creates a folder for related tasks.

Syntax
ppFolder = .CreateFolder( _
ByVal folderName, _
ByVal sddl _
)

Parameters
folderName [in]
The name that is used to identify the folder. If "FolderName\SubFolder1\SubFolder2" is specified, the entire
folder tree will be created if the folders do not exist. This parameter can be a relative path to the current
TaskFolder instance. The root task folder is specified with a backslash (\). An example of a task folder path,
under the root task folder, is \MyTaskFolder. The '.' character cannot be used to specify the current task folder
and the '..' characters cannot be used to specify the parent task folder in the path.
sddl [in]
The security descriptor that is associated with the folder.

Return value
A TaskFolder object that represents the new subfolder.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskFolder.DeleteFolder method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, deletes a subfolder from the parent folder.

Syntax
TaskFolder.DeleteFolder( _
ByVal folderName, _
ByVal flags _
)

Parameters
folderName [in]
The name of the subfolder to be removed. The root task folder is specified with a backslash (\). This parameter
can be a relative path to the folder you want to delete. An example of a task folder path, under the root task
folder, is \MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters
cannot be used to specify the parent task folder in the path.
flags [in]
Not supported.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskFolder
Task Scheduler
TaskFolder.DeleteTask method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, deletes a task from the folder.

Syntax
TaskFolder.DeleteTask( _
ByVal Name, _
ByVal flags _
)

Parameters
Name [in]
The name of the task that is specified when the task was registered. The '.' character cannot be used to specify
the current task folder and the '..' characters cannot be used to specify the parent task folder in the path.
flags [in]
Not supported. Value is 0

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskFolder.GetFolder property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets a folder that contains tasks at a specified location.

Syntax
TaskFolder.GetFolder( _
ByVal path _
)

Property value
The path (location) to the folder. Do not use a backslash following the last folder name in the path. The root task
folder is specified with a backslash (\). An example of a task folder path, under the root task folder, is
\MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be
used to specify the parent task folder in the path.

Error codes
The folder at the specified location. The folder is a TaskFolder object.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskFolder.GetFolders property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets all the subfolders in the folder.

Syntax
TaskFolder.GetFolders( _
ByVal flags, _
ByRef folders _
)

Property value
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskFolderCollection
TaskFolder.GetSecurityDescriptor property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the security descriptor for the folder.

Syntax
TaskFolder.GetSecurityDescriptor( _
ByVal securityInformation, _
ByRef pSddl _
)

Property value
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskFolder.SetSecurityDescriptor
RegisteredTask .SetSecurityDescriptor
TaskFolder.GetTask property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets a task at a specified location in a folder.

Syntax
TaskFolder.GetTask( _
ByVal path _
)

Property value
The path (location) to the task in a folder. The root task folder is specified with a backslash (\). An example of a
task folder path, under the root task folder, is \MyTaskFolder. The '.' character cannot be used to specify the
current task folder and the '..' characters cannot be used to specify the parent task folder in the path.

Error codes
The task at the specified location. The task is a RegisteredTask object.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskFolder.GetTasks property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets all the tasks in the folder.

Syntax
TaskFolder.GetTasks( _
ByVal flags, _
ByRef ppTasks _
)

Property value
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
RegisteredTaskCollection
TaskFolder.Name property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the name that is used to identify the folder that contains a task.

Syntax
TaskFolder.Name As String

Property value
The name that is used to identify the folder.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskFolder.Path property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the path to where the folder is stored.

Syntax
TaskFolder.Path As String

Property value
The path to where the folder is stored. The root task folder is specified with a backslash (\). An example of a task
folder path, under the root task folder, is \MyTaskFolder.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskFolder.RegisterTask method
8/8/2022 • 4 minutes to read • Edit Online

For scripting, registers (creates) a new task in the folder using XML to define the task.

Syntax
TaskFolder.RegisterTask( _
ByVal path, _
ByVal xmlText, _
ByVal flags, _
ByVal userId, _
ByVal password, _
ByVal logonType, _
[ ByVal sddl ], _
ByRef pTask _
)

Parameters
path [in]
The name of the task. If this value is Nothing , the task will be registered in the root task folder and the task
name will be a GUID value that is created by the Task Scheduler service.
A task name cannot begin or end with a space character. The '.' character cannot be used to specify the current
task folder and the '..' characters cannot be used to specify the parent task folder in the path.
xmlText [in]
An XML-formatted description of the task.
The following topics contain tasks defined using XML.
Time Trigger Example (XML)
Event Trigger Example (XML)
Daily Trigger Example (XML)
Registration Trigger Example (XML)
Weekly Trigger Example (XML)
Logon Trigger Example (XML)
Boot Trigger Example (XML)
flags [in]
A TASK_CREATION constant.

VA L UE M EA N IN G

The Task Scheduler checks the syntax of the XML that


TASK_VALIDATE_ONLY describes the task but does not register the task. This
0x1 constant cannot be combined with the TASK_CREATE ,
TASK_UPDATE , or TASK_CREATE_OR_UPDATE values.
VA L UE M EA N IN G

The Task Scheduler registers the task as a new task.


TASK_CREATE
0x2

The Task Scheduler registers the task as an updated version


TASK_UPDATE of an existing task. When a task with a registration trigger is
0x4 updated, the task will execute after the update occurs.

The Task Scheduler either registers the task as a new task or


TASK_CREATE_OR_UPDATE as an updated version if the task already exists. Equivalent to
0x6 TASK_CREATE | TASK_UPDATE.

The Task Scheduler disables the existing task.


TASK_DISABLE
0x8

The Task Scheduler is prevented from adding the allow


TASK_DONT_ADD_PRINCIPAL_ACE access-control entry (ACE) for the context principal. When
0x10 the TaskFolder.RegisterTask function is called with this flag
to update a task, the Task Scheduler service does not add
the ACE for the new context principal and does not remove
the ACE from the old context principal.

The Task Scheduler creates the task, but ignores the


TASK_IGNORE_REGISTRATION_TRIGGERS registration triggers in the task. By ignoring the registration
0x20 triggers, the task will not execute when it is registered unless
a time-based trigger causes it to execute on registration.

userId [in]
The user credentials that are used to register the task.

NOTE
If the task is defined as a Task Scheduler 1.0 task, then do not use a group name (rather than a specific user name) in this
userId parameter. A task is defined as a Task Scheduler 1.0 task when the version attribute of the Task element in the
task's XML is set to 1.1.

password [in]
The password for the userId that is used to register the task. When the TASK_LOGON_SERVICE_ACCOUNT logon
type is used, the password must be an empty VARIANT value such as VT_NULL or VT_EMPTY .
logonType [in]
Defines what logon technique is used to run the registered task.

VA L UE M EA N IN G

The logon method is not specified. Used for non-NT


TASK_LOGON_NONE credentials.
0
VA L UE M EA N IN G

Use a password for logging on the user. The password must


TASK_LOGON_PASSWORD be supplied at registration time.
1

Use an existing interactive token to run a task. The user


TASK_LOGON_S4U must log on using a service for user (S4U) logon. When an
2 S4U logon is used, no password is stored by the system and
there is no access to either the network or to encrypted files.

User must already be logged on. The task will be run only in
TASK_LOGON_INTERACTIVE_TOKEN an existing interactive session.
3

Group activation. The groupId field specifies the group.


TASK_LOGON_GROUP
4

Indicates that a Local System, Local Service, or Network


TASK_LOGON_SERVICE_ACCOUNT Service account is being used as a security context to run
5 the task.

First use the interactive token. If the user is not logged on


TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD (no interactive token is available), then the password is used.
6 The password must be specified when a task is registered.
This flag is not recommended for new tasks because it is less
reliable than TASK_LOGON_PASSWORD.

sddl [in, optional]


The security descriptor that is associated with the registered task. You can specify the access control list (ACL) in
the security descriptor for a task in order to allow or deny certain users and groups access to a task.

NOTE
If the Local System account is denied access to a task, then the Task Scheduler service can produce unexpected results.

pTask [out]
A RegisteredTask object that represents the new task.

Return value
This method does not return a value.

Remarks
For a task, that contains a message box action, the message box will be displayed if the task is activated and the
task has an interactive logon type. To set the task logon type to interactive, specify 3
(TASK_LOGON_INTERACTIVE_TOKEN ) or 4 (TASK_LOGON_GROUP ) in the LogonType property of the
task principal, or in the logonType parameter of TaskFolder.RegisterTask or
TaskFolder.RegisterTaskDefinition .
Only a member of the Administrators group can create a task with a boot trigger.
You can successfully register a task with a group specified in the userId parameter and 3
(TASK_LOGON_INTERACTIVE_TOKEN ) specified in the logonType parameter of TaskFolder.RegisterTask or
TaskFolder.RegisterTaskDefinition , but the task will not run.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
TaskFolder
TaskFolder.RegisterTaskDefinition method
8/8/2022 • 4 minutes to read • Edit Online

For scripting, registers (creates) a task in a specified location using the TaskDefinition object to define a task.

Syntax
TaskFolder.RegisterTaskDefinition( _
ByVal path, _
ByVal definition, _
ByVal flags, _
ByVal userId, _
ByVal password, _
ByVal logonType, _
[ ByVal sddl ], _
ByRef task _
)

Parameters
path [in]
The name of the task. If this value is Nothing , the task will be registered in the root task folder and the task
name will be a GUID value that is created by the Task Scheduler service.
A task name cannot begin or end with a space character. The '.' character cannot be used to specify the current
task folder and the '..' characters cannot be used to specify the parent task folder in the path.
definition [in]
The definition of the task that is registered.
flags [in]
A TASK_CREATION constant.

VA L UE M EA N IN G

The Task Scheduler checks the syntax of the XML that


TASK_VALIDATE_ONLY describes the task but does not register the task. This
0x1 constant cannot be combined with the TASK_CREATE ,
TASK_UPDATE , or TASK_CREATE_OR_UPDATE values.

The Task Scheduler registers the task as a new task.


TASK_CREATE
0x2

The Task Scheduler registers the task as an updated version


TASK_UPDATE of an existing task. When a task with a registration trigger is
0x4 updated, the task will execute after the update occurs.
VA L UE M EA N IN G

The Task Scheduler either registers the task as a new task or


TASK_CREATE_OR_UPDATE as an updated version if the task already exists. Equivalent to
0x6 TASK_CREATE | TASK_UPDATE.

The Task Scheduler disables the existing task.


TASK_DISABLE
0x8

The Task Scheduler is prevented from adding the allow


TASK_DONT_ADD_PRINCIPAL_ACE access-control entry (ACE) for the context principal. When
0x10 the TaskFolder.RegisterTaskDefinition function is called
with this flag to update a task, the Task Scheduler service
does not add the ACE for the new context principal and does
not remove the ACE from the old context principal.

The Task Scheduler creates the task, but ignores the


TASK_IGNORE_REGISTRATION_TRIGGERS registration triggers in the task. By ignoring the registration
0x20 triggers, the task will not execute when it is registered unless
a time-based trigger causes it to execute on registration.

userId [in]
The user credentials that are used to register the task. If present, these credentials take priority over the
credentials specified in the task definition object pointed to by the definition parameter.

NOTE
If the task is defined as a Task Scheduler 1.0 task, then do not use a group name (rather than a specific user name) in this
userId parameter. A task is defined as a Task Scheduler 1.0 task when the Compatibility property is set to 1 in the task's
settings.

password [in]
The password for the userId that is used to register the task. When the TASK_LOGON_SERVICE_ACCOUNT logon
type is used, the password must be an empty VARIANT value such as VT_NULL or VT_EMPTY .
logonType [in]
Defines what logon technique is used to run the registered task.

VA L UE M EA N IN G

The logon method is not specified. Used for non-NT


TASK_LOGON_NONE credentials.
0

Use a password for logging on the user. The password must


TASK_LOGON_PASSWORD be supplied at registration time.
1

Use an existing interactive token to run a task. The user


TASK_LOGON_S4U must log on using a service for user (S4U) logon. When an
2 S4U logon is used, no password is stored by the system and
there is no access to either the network or to encrypted files.
VA L UE M EA N IN G

User must already be logged on. The task will be run only in
TASK_LOGON_INTERACTIVE_TOKEN an existing interactive session.
3

Group activation. The groupId field specifies the group.


TASK_LOGON_GROUP
4

Indicates that a Local System, Local Service, or Network


TASK_LOGON_SERVICE_ACCOUNT Service account is being used as a security context to run
5 the task.

First use the interactive token. If the user is not logged on


TASK_LOGON_INTERACTIVE_TOKEN_OR_PASSWORD (no interactive token is available), then the password is used.
6 The password must be specified when a task is registered.
This flag is not recommended for new tasks because it is less
reliable than TASK_LOGON_PASSWORD.

sddl [in, optional]


The security descriptor that is associated with the registered task. You can specify the access control list (ACL) in
the security descriptor for a task in order to allow or deny certain users and groups access to a task.

NOTE
If the Local System account is denied access to a task, then the Task Scheduler service can produce unexpected results.

task [out]
A RegisteredTask object that represents the new task.

Return value
This method does not return a value.

Remarks
For a task, that contains a message box action, the message box will be displayed if the task is activated and the
task has an interactive logon type. To set the task logon type to interactive, specify 3
(TASK_LOGON_INTERACTIVE_TOKEN ) or 4 (TASK_LOGON_GROUP ) in the LogonType property of the
task principal, or in the logonType parameter of TaskFolder.RegisterTask or
TaskFolder.RegisterTaskDefinition .
Only a member of the Administrators group can create a task with a boot trigger.
You can successfully register a task with a group specified in the userId parameter and 3
(TASK_LOGON_INTERACTIVE_TOKEN ) specified in the logonType parameter of TaskFolder.RegisterTask or
TaskFolder.RegisterTaskDefinition , but the task will not run.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RegisteredTask
TaskFolder
TaskFolder.SetSecurityDescriptor property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, sets the security descriptor for the folder.

Syntax
TaskFolder.SetSecurityDescriptor( _
ByVal sddl, _
ByVal flags _
)

Property value
Remarks
You can specify the access control list (ACL) in the security descriptor for a task folder in order to allow or deny
certain users and groups access to a task folder.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
RegisteredTask .SetSecurityDescriptor
TaskFolder.GetSecurityDescriptor
TaskFolderCollection object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides information and control for a collection of folders that contain tasks.

Members
The TaskFolderCollection object has these types of members:
Properties
Properties
The TaskFolderCollection object has these properties.

P RO P ERT Y DESC RIP T IO N

Count Gets the number of folders in the collection.

Item Gets the specified folder from the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskFolder.GetFolders
TaskFolderCollection.Count property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the number of folders in the collection.

Syntax
TaskFolderCollection.Count As long

Property value
The number of triggers in the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskFolderCollection.Item property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the specified folder from the collection.

Syntax
TaskFolderCollection.Item( _
ByVal Index _
) As TaskFolder

Property value
A TaskFolder object that represents the requested folder.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskNamedValueCollection object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that contains a collection of TaskNamedValuePair object name-value pairs.

Members
The TaskNamedValueCollection object has these types of members:
Methods
Properties
Methods
The TaskNamedValueCollection object has these methods.

M ET H O D DESC RIP T IO N

Clear Clears the entire collection of name-value pairs.

Create Creates a name-value pair in the collection.

Remove Removes a selected name-value pair from the collection.

Properties
The TaskNamedValueCollection object has these properties.

P RO P ERT Y DESC RIP T IO N

Count Gets the number of name-value pairs in the collection.

Item Gets the specified name-value pair from the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
EventTrigger.ValueQueries
EmailAction.HeaderFields
TaskNamedValueCollection.Clear method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, clears the entire collection of name-value pairs.

Syntax
TaskNamedValueCollection.Clear()

Parameters
This method has no parameters.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskNamedValueCollection.Count property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the number of name-value pairs in the collection.

Syntax
TaskNamedValueCollection.Count As long

Property value
The number of name-value pairs in the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskNamedValueCollection.Create method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, creates a name-value pair in the collection.

Syntax
TaskNamedValueCollection.Create( _
ByVal name, _
ByVal value, _
ByRef pair _
)

Parameters
name [in]
The name that is associated with a value in a name-value pair.
value [in]
The value that is associated with a name in a name-value pair.
pair [out]
The name-value pair that is created in the collection.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskNamedValueCollection.Item property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the specified name-value pair from the collection.

Syntax
TaskNamedValueCollection.Item( _
ByVal index, _
ByRef pair _
) As long

Property value
A TaskNamedValuePair object that represents the requested pair.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskNamedValueCollection.Remove method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, removes a selected name-value pair from the collection.

Syntax
TaskNamedValueCollection.Remove( _
ByVal index _
)

Parameters
index [in]
The index of the name-value pair to be removed.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskNamedValuePair object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that is used to create a name-value pair in which the name is associated with the value.

Members
The TaskNamedValuePair object has these types of members:
Properties
Properties
The TaskNamedValuePair object has these properties.

P RO P ERT Y DESC RIP T IO N

Name Gets or sets the name that is associated with a value in a


name-value pair.

Value Gets or sets the value that is associated with a name in a


name-value pair.

Remarks
When reading or writing your own XML for a task, a name-value pair is specified using the ValueQueries
element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskNamedValueCollection
TaskNamedValuePair.Name property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the name that is associated with a value in a name-value pair.

Syntax
TaskNamedValuePair.Name As String

Property value
The name that is associated with a value in a name-value pair.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskNamedValuePair.Value property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the value that is associated with a name in a name-value pair.

Syntax
TaskNamedValuePair.Value As String

Property value
The value that is associated with a name in a name-value pair.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskService object
8/8/2022 • 2 minutes to read • Edit Online

For scripting, provides access to the Task Scheduler service for managing registered tasks.
The TaskSer vice.Connect method should be called before calling any of the other TaskSer vice methods.

Members
The TaskSer vice object has these types of members:
Methods
Properties
Methods
The TaskSer vice object has these methods.

M ET H O D DESC RIP T IO N

Connect Connects to a remote machine and associates all subsequent


calls on this interface with a remote session.

GetFolder Gets the path to a folder of registered tasks.

GetRunningTasks Gets a collection of running tasks.

NewTask Returns an empty task definition object to be filled in with


settings and properties and then registered using the
TaskFolder.RegisterTaskDefinition method.

Properties
The TaskSer vice object has these properties.

P RO P ERT Y DESC RIP T IO N

Connected Gets a Boolean value that indicates if you are connected to


the Task Scheduler service.

ConnectedDomain Gets the name of the domain to which the TargetSer ver
computer is connected.

ConnectedUser Gets the name of the user that is connected to the Task
Scheduler service.

HighestVersion Gets the highest version of Task Scheduler that a computer


supports.

TargetSer ver Gets the name of the computer that is running the Task
Scheduler service that the user is connected to.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting), Event
Trigger Example (Scripting), Daily Trigger Example (Scripting), Registration Trigger Example (Scripting), Weekly
Trigger Example (Scripting), Logon Trigger Example (Scripting), Boot Trigger Example (Scripting), or Displaying
Task Names and States (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskService.Connect method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, connects to a remote machine and associates all subsequent calls on this interface with a remote
session. If the serverName parameter is empty, then this method will execute on the local computer. If the userId
is not specified, then the current token is used.

Syntax
TaskService.Connect( _
[ ByVal serverName ], _
[ ByVal user ], _
[ ByVal domain ], _
[ ByVal password ] _
)

Parameters
serverName [in, optional]
The name of the computer that you want to connect to. If the serverName parameter is empty, then this method
will execute on the local computer.
user [in, optional]
The user name that is used during the connection to the computer. If the user is not specified, then the current
token is used.
domain [in, optional]
The domain of the user specified in the user parameter.
password [in, optional]
The password that is used to connect to the computer. If the user name and password are not specified, then the
current token is used.

Return value
This method does not return a value.

Remarks
The TaskSer vice.Connect method should be called before calling any of the other TaskSer vice methods.
If the Connect method fails, you can collect the error identifier to find the meaning of the error. The following
table lists the error identifiers and their descriptions.

ERRO R IDEN T IF IER DESC RIP T IO N

0x80070005 Access is denied to connect to the Task Scheduler service.


ERRO R IDEN T IF IER DESC RIP T IO N

0x80041315 The Task Scheduler service is not running.

0x8007000e The application does not have enough memory to complete


the operation or the user, password, or domain has at least
one null and one non-null value.

53 This error is returned in the following situations:


The computer name specified in the serverName
parameter does not exist.
When you are trying to connect to a Windows Server
2003 or Windows XP computer, and the remote
computer does not have the File and Printer Sharing
firewall exception enabled or the Remote Registry
service is not running.
When you are trying to connect to a Windows Vista
computer, and the remote computer does not have
the Remote Scheduled Tasks Management firewall
exception enabled and the File and Printer Sharing
firewall exception enabled, or the Remote Registry
service is not running.

50 The user, password, or domain parameters cannot be


specified when connecting to a remote Windows XP or
Windows Server 2003 computer from a Windows Vista
computer.

If you are to connecting to a remote Windows Vista computer from a Windows Vista, you need to allow the
Remote Scheduled Tasks Management firewall exception on the remote computer. To allow this exception click
Start, Control Panel, Security, Allow a program through Windows Firewall, and then select the Remote Scheduled
Tasks Management check box. Then click the Ok button in the Windows Firewall Settings dialog box.
If you are connecting to a remote Windows XP or Windows Server 2003 computer from a Windows Vista
computer, you need to allow the File and Printer Sharing firewall exception on the remote computer. To allow
this exception click Start, Control Panel, double-click Windows Firewall, select the Exceptions tab, and then select
the File and Printer Sharing firewall exception. Then click the OK button in the Windows Firewall dialog box. The
Remote Registry service must also be running on the remote computer.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskService.Connected property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets a Boolean value that indicates if you are connected to the Task Scheduler service.
This property is read-only.

Syntax
TaskService.Connected

Property value
A Boolean value that indicates if you are connected to the Task Scheduler service.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskService.ConnectedDomain property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the name of the domain to which the TargetSer ver computer is connected.

Syntax
TaskService.ConnectedDomain As String

Property value
The domain to which the TargetSer ver computer is connected.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskService.ConnectedUser property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the name of the user that is connected to the Task Scheduler service.

Syntax
TaskService.ConnectedUser As String

Property value
The name of the user that is connected to the Task Scheduler service.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskService.GetFolder method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets a folder of registered tasks.

Syntax
TaskService.GetFolder( _
ByVal path _
)

Parameters
path [in]
The path to the folder to be retrieved. Do not use a backslash following the last folder name in the path. The root
task folder is specified with a backslash (\). An example of a task folder path, under the root task folder, is
\MyTaskFolder. The '.' character cannot be used to specify the current task folder and the '..' characters cannot be
used to specify the parent task folder in the path.

Return value
A TaskFolder object for the requested folder.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskService.GetRunningTasks method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets a collection of running tasks.

NOTE
TaskSer vice.GetRunningTasks will only return a collection of running tasks that are running at or below a user's
security context. For example, for members of the Administrators group, GetRunningTasks will return a collection of all
running tasks, but for members of the Users group, GetRunningTasks will only return a collection of tasks that are
running under the Users group security context.

Syntax
TaskService.GetRunningTasks( _
ByVal flags _
)

Parameters
flags [in]
Pass in 1 to return all running tasks, including hidden tasks. Pass in 0 to return a collection of running tasks that
are not hidden tasks.

Return value
A RunningTaskCollection object that contains the currently running tasks.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskService.HighestVersion property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, indicates the highest version of Task Scheduler that a computer supports.

Syntax
TaskService.HighestVersion As Integer

Property value
The highest version of Task Scheduler that a computer supports. The highest version is a value that is split into
MajorVersion/MinorVersion on the 16-bit boundary. The Task Scheduler service returns 1 for the major version
and 2 for the minor version. Use the CLng function to get the integer value of the property.

Examples
The following code shows how to use the CLng function to get the value of the HighestVersion property.

wscript.echo service.HighestVersion
Test = clng( service.HighestVersion )
If Test <> 65538 Then
wscript.echo "Fail"

Else
wscript.echo "Pass"
End If

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskService.NewTask method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, returns an empty task definition object to be filled in with settings and properties and then
registered using the TaskFolder.RegisterTaskDefinition method.

Syntax
TaskService.NewTask( _
ByVal flags _
)

Parameters
flags [in]
This parameter is reserved for future use and must be set to 0.

Return value
The task definition that specifies all the information required to create a new task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskService.TargetServer property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the name of the computer that is running the Task Scheduler service that the user is
connected to.

Syntax
TaskService.TargetServer As String

Property value
The name of the computer that is running the Task Scheduler service that the user is connected to.

Remarks
This property returns an empty string when the user passes an IP address, Localhost, or '.' as a parameter, and it
returns the name of the computer that is running the Task Scheduler service when the user does not pass any
parameter value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskSettings object
8/8/2022 • 3 minutes to read • Edit Online

A scripting object that provides the settings that the Task Scheduler service uses to perform the task.

Members
The TaskSettings object has these types of members:
Properties
Properties
The TaskSettings object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

AllowDemandStar t Read/write Gets or sets a Boolean value that


indicates that the task can be started
by using either the Run command or
the Context menu.

AllowHardTerminate Read/write Gets or sets a Boolean value that


indicates that the task may be
terminated by using
TerminateProcess .

Compatibility Read/write Gets or sets an integer value that


indicates which version of Task
Scheduler a task is compatible with.

DeleteExpiredTaskAfter Read/write Gets or sets the amount of time that


the Task Scheduler will wait before
deleting the task after it expires.

DisallowStar tIfOnBatteries Read/write Gets or sets a Boolean value that


indicates that the task will not be
started if the computer is running on
battery power.

Enabled Read/write Gets or sets a Boolean value that


indicates that the task is enabled. The
task can be performed only when this
setting is True.

ExecutionTimeLimit Read/write Gets or sets the amount of time


allowed to complete the task.

Hidden Read/write Gets or sets a Boolean value that


indicates that the task will not be
visible in the UI. However,
administrators can override this setting
through the use of a "master switch"
that makes all tasks visible in the UI.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

IdleSettings Read/write Gets or sets the information that


specifies how the Task Scheduler
performs tasks when the computer is
in an idle state.

MultipleInstances Read/write Gets or sets the policy that defines


how the Task Scheduler deals with
multiple instances of the task.

NetworkSettings Read/write Gets or sets the network settings


object that contains a network profile
identifier and name. If the
RunOnlyIfNetworkAvailable
property of TaskSettings is True and
a network propfile is specified in the
NetworkSettings property, then the
task will run only if the specified
network profile is available.

Priority Read/write Gets or sets the priority level of the


task.

Restar tCount Read/write Gets or sets the number of times that


the Task Scheduler will attempt to
restart the task.

Restar tInter val Read/write Gets or sets a value that specifies how
long the Task Scheduler will attempt to
restart the task.

RunOnlyIfIdle Read/write Gets or sets a Boolean value that


indicates that the Task Scheduler will
run the task only if the computer is in
an idle state.

RunOnlyIfNetworkAvailable Read/write Gets or sets a Boolean value that


indicates that the Task Scheduler will
run the task only when a network is
available.

Star tWhenAvailable Read/write Gets or sets a Boolean value that


indicates that the Task Scheduler can
start the task at any time after its
scheduled time has passed.

StopIfGoingOnBatteries Read/write Gets or sets a Boolean value that


indicates that the task will be stopped
if the computer begins to run on
battery power.

WakeToRun Read/write Gets or sets a Boolean value that


indicates that the Task Scheduler will
wake the computer when it is time to
run the task.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

XmlText Read/write Gets or sets an XML-formatted


definition of the task settings.

Remarks
By default, a task will be stopped 72 hours after it starts to run. You can change this by changing the
ExecutionTimeLimit setting.
When reading or writing XML for a task, the task settings are defined in the Settings element of the Task
Scheduler schema.

Examples
For more information and a code example for this scripting object, see Time Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskDefinition
NetworkSettings
IdleSettings
TaskSettings.AllowDemandStart property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the task can be started by using either the Run
command or the Context menu.
This property is read/write.

Syntax
TaskSettings.AllowDemandStart As Boolean

Property value
If True, the task can be run by using the Run command or the Context menu. If False, the task cannot be run
using the Run command or the Context menu. The default is True.

Remarks
When this property is set to True, the task can be started independent of when any triggers start the task.
When reading or writing XML for a task, this setting is specified in the AllowStartOnDemand element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.AllowHardTerminate property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the task may be terminated by the Task Scheduler
service using TerminateProcess . The service will try to close the running task by sending the WM_CLOSE
notification, and if the task does not respond, the task will be terminated only if this property is set to true.
This property is read/write.

Syntax
TaskSettings.AllowHardTerminate As Boolean

Property value
If True, the task can be terminated by using TerminateProcess . If False, the task cannot be terminated by using
TerminateProcess .

Remarks
When reading or writing XML for a task, this setting is specified in the AllowHardTerminate element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.Compatibility property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets an integer value that indicates which version of Task Scheduler a task is compatible
with.
This property is read/write.

Syntax
TaskSettings.Compatibility As Integer

Property value
VA L UE M EA N IN G

The task is compatible with the AT command.


TASK_COMPATIBILITY_AT
0

The task is compatible with Task Scheduler 1.0.


TASK_COMPATIBILITY_V1
1

The task is compatible with Task Scheduler 2.0.


TASK_COMPATIBILITY_V2
2

Remarks
Task compatibility, which is set through the Compatibility property, should only be set to
TASK_COMPATIBILITY_V1 if a task needs to be accessed or modified from a Windows XP, Windows Server 2003,
or Windows 2000 computer. Otherwise, it is recommended that Task Scheduler 2.0 compatibility be used
because the task will have more features.
Tasks compatible with the AT command can only have one time trigger.
Tasks compatible with Task Scheduler 1.0 can only have a time trigger, a logon trigger, or a boot trigger, and the
task can only have an executable action.
For more information about task compatibility, see What's New in Task Scheduler and Tasks.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]


REQ UIREM EN T VA L UE

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TASK_COMPATIBILITY
Task Scheduler
TaskSettings.DeleteExpiredTaskAfter property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the amount of time that the Task Scheduler will wait before deleting the task after it
expires. If no value is specified for this property, then the Task Scheduler service will not delete the task.
This property is read/write.

Syntax
TaskSettings.DeleteExpiredTaskAfter As String

Property value
A string that gets or sets the amount of time that the Task Scheduler will wait before deleting the task after it
expires. The format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of
months, nD is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of
minutes, and nS is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies
one month, four days, two hours, and five minutes).

Remarks
A task expires after the end boundary has been exceeded for all triggers associated with the task. The end
boundary for a trigger is specified by the EndBoundary property inherited by all trigger objects.
When reading or writing XML for a task, this setting is specified in the DeleteExpiredTaskAfter
(settingsType) element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.DisallowStartIfOnBatteries property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the task will not be started if the computer is
running on batteries.
This property is read/write.

Syntax
TaskSettings.DisallowStartIfOnBatteries As Boolean

Property value
A Boolean value that indicates that the task will not be started if the computer is running on batteries. If True, the
task will not be started if the computer is running on batteries. If False, the task will be started if the computer is
running on batteries. The default is True.

Remarks
When reading or writing XML for a task, this setting is specified in the DisallowStar tIfOnBatteries element of
the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.Enabled property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the task is enabled. The task can be performed only
when this setting is True.
This property is read/write.

Syntax
TaskSettings.Enabled As Boolean

Property value
If True, the task is enabled. If False, the task is not enabled.

Remarks
When reading or writing XML for a task, this setting is specified in the Enabled (settingsType) element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.ExecutionTimeLimit property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the amount of time that is allowed to complete the task. By default, a task will be
stopped 72 hours after it starts to run. You can change this by changing this setting.
This property is read/write.

Syntax
TaskSettings.ExecutionTimeLimit As String

Property value
The amount of time that is allowed to complete the task. The format for this string is PnYnMnDTnHnMnS, where
nY is the number of years, nM is the number of months, nD is the number of days, 'T' is the date/time separator,
nH is the number of hours, nM is the number of minutes, and nS is the number of seconds (for example, PT5M
specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours, and five minutes). A value of
PT0S will enable the task to run indefinitely. When this parameter is set to Nothing, the execution time limit is
infinite.

Remarks
When reading or writing XML for a task, this setting is specified in the ExecutionTimeLimit element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.Hidden property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the task will not be visible in the UI. However,
administrators can override this setting through the use of a "master switch" that makes all tasks visible in the
UI.
This property is read/write.

Syntax
TaskSettings.Hidden As Boolean

Property value
If True , the value indicates that the task will not be visible in the UI. If False , the task will be visible in the UI. The
default is False .

Remarks
When reading or writing XML for a task, this setting is specified in the Hidden (settingsType) element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.IdleSettings property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the information that specifies how the Task Scheduler performs tasks when the
computer is in an idle condition. For information about idle conditions, see Task Idle Conditions.
This property is read/write.

Syntax
TaskSettings.IdleSettings As IdleSettings

Property value
An IdleSettings object that specifies how the Task Scheduler handles the task when the computer goes into an
idle condition.

Remarks
When reading or writing XML for a task, this setting is specified in the IdleSettings element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.MultipleInstances property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the policy that defines how the Task Scheduler deals with multiple instances of the
task.
This property is read/write.

Syntax
TaskSettings.MultipleInstances As Integer

Property value
TASK_INSTANCES_POLICY constants.

VA L UE M EA N IN G

Starts a new instance while an existing instance of the task is


TASK_INSTANCES_PARALLEL running.
0

Starts a new instance of the task after all other instances of


TASK_INSTANCES_QUEUE the task are complete.
1

Does not start a new instance if an existing instance of the


TASK_INSTANCES_IGNORE_NEW task is running.
2

Stops an existing instance of the task before it starts new


TASK_INSTANCES_STOP_EXISTING instance.
3

Remarks
When reading or writing XML for a task, this setting is specified in the MultipleInstancesPolicy element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


REQ UIREM EN T VA L UE

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TASK_INSTANCES_POLICY
Task Scheduler
TaskSettings.NetworkSettings property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the network settings object that contains a network profile identifier and name. If the
RunOnlyIfNetworkAvailable property of TaskSettings is True and a network propfile is specified in the
NetworkSettings property, then the task will run only if the specified network profile is available.

Syntax
TaskSettings.NetworkSettings As NetworkSettings

Property value
A NetworkSettings object that contains a network profile identifier and name.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskSettings
NetworkSettings
TaskSettings.Priority property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the priority level of the task.


This property is read/write.

Syntax
TaskSettings.Priority As Integer

Property value
The priority level (0-10) of the task. The default is 7.

Remarks
Priority level 0 is the highest priority, and priority level 10 is the lowest priority. The default value is 7. Priority
levels 7 and 8 are used for background tasks, and priority levels 4, 5, and 6 are used for interactive tasks.
The task's action is started in a process with a priority that is based on a Priority Class value. A Priority Level
value (thread priority) is used for COM handler, message box, and email task actions. For more information
about the Priority Class and Priority Level values, see Scheduling Priorities. The following table lists the possible
values for the priority parameter, and the corresponding Priority Class and Priority Level values.

TA SK P RIO RIT Y P RIO RIT Y C L A SS P RIO RIT Y L EVEL

0 REALTIME_PRIORITY_CLASS THREAD_PRIORITY_TIME_CRITICAL

1 HIGH_PRIORITY_CLASS THREAD_PRIORITY_HIGHEST

2 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL

3 ABOVE_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_ABOVE_NORMAL

4 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL

5 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL

6 NORMAL_PRIORITY_CLASS THREAD_PRIORITY_NORMAL

7 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL

8 BELOW_NORMAL_PRIORITY_CLASS THREAD_PRIORITY_BELOW_NORMAL

9 IDLE_PRIORITY_CLASS THREAD_PRIORITY_LOWEST

10 IDLE_PRIORITY_CLASS THREAD_PRIORITY_IDLE
When reading or writing XML for a task, this setting is specified in the Priority (settingsType) element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskSettings
TaskSettings.RestartCount property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the number of times that the Task Scheduler will attempt to restart the task.
This property is read/write.

Syntax
TaskSettings.RestartCount As Integer

Property value
The number of times that the Task Scheduler will attempt to restart the task.

Remarks
When reading or writing XML for a task, this setting is specified in the Count element of the Task Scheduler
schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.RestartInterval property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a value that specifies how long the Task Scheduler will attempt to restart the task.
This property is read/write.

Syntax
TaskSettings.RestartInterval As String

Property value
A value that specifies how long the Task Scheduler will attempt to restart the task. If this property is set, the
Restar tCount property must also be set. The format for this string is P<days>DT<hours>H<minutes>M<seconds>S
(for example, "PT5M" is 5 minutes, "PT1H" is 1 hour, and "PT20M" is 20 minutes). The maximum time allowed is
31 days, and the minimum time allowed is 1 minute.

Remarks
When reading or writing XML for a task, this setting is specified in the Inter val element of the Task Scheduler
schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.RunOnlyIfIdle property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the Task Scheduler will run the task only if the
computer is in an idle condition.
This property is read/write.

Syntax
TaskSettings.RunOnlyIfIdle As Boolean

Property value
If True, the property indicates that the Task Scheduler will run the task only if the computer is in an idle
condition. The default is False.

Remarks
When reading or writing XML for a task, this setting is specified in the RunOnlyIfIdle element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.RunOnlyIfNetworkAvailable property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the Task Scheduler will run the task only when a
network is available.
This property is read/write.

Syntax
TaskSettings.RunOnlyIfNetworkAvailable As Boolean

Property value
If True, the property indicates that the Task Scheduler will run the task only when a network is available. The
default is False.

Remarks
When reading or writing XML for a task, this setting is specified in the RunOnlyIfNetworkAvailable element
of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.StartWhenAvailable property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the Task Scheduler can start the task at any time
after its scheduled time has passed.
This property is read/write.

Syntax
TaskSettings.StartWhenAvailable As Boolean

Property value
If True, the property indicates that the Task Scheduler can start the task at any time after its scheduled time has
passed. The default is False.

Remarks
This property applies only to time-based tasks with an end boundary or time-based tasks that are set to repeat
infinitely.
Tasks that are started after the scheduled time has passed (because of the Star tWhenAvailable property being
set to True) are queued in the Task Scheduler service's queue of tasks and they are started after a delay. The
default delay is 10 minutes.
When reading or writing XML for a task, this setting is specified in the Star tWhenAvailable element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.StopIfGoingOnBatteries property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the task will be stopped if the computer is going
onto batteries.
This property is read/write.

Syntax
TaskSettings.StopIfGoingOnBatteries As Boolean

Property value
A Boolean value that indicates that the task will be stopped if the computer is going onto batteries. If True, the
property indicates that the task will be stopped if the computer is going onto batteries. If False, the property
indicates that the task will not be stopped if the computer is going onto batteries. The default is True. See
Remarks for more details.

Remarks
When reading or writing XML for a task, this setting is specified in the StopIfGoingOnBatteries element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.WakeToRun property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates that the Task Scheduler will wake the computer when it
is time to run the task.
This property is read/write.

Syntax
TaskSettings.WakeToRun As Boolean

Property value
If True, the property indicates that the Task Scheduler will wake the computer when it is time to run the task.

Remarks
When the Task Scheduler service wakes the computer to run a task, the screen may remain off even though the
computer is no longer in the sleep or hibernate mode. The screen will turn on when Windows Vista detects that
a user has returned to use the computer.
When reading or writing XML for a task, this setting is specified in the WakeToRun element of the Task
Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskSettings.XmlText property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets an XML-formatted definition of the task settings.


This property is read/write.

Syntax
TaskSettings.XmlText As String

Property value
An XML-formatted definition of the task settings.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TaskVariables object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that defines task variables that can be passed as parameters to task handlers and external
executables that are launched by tasks.

Members
The TaskVariables object has these types of members:
Methods
Methods
The TaskVariables object has these methods.

M ET H O D DESC RIP T IO N

GetContext Used to share the context between different steps and tasks
that are in the same job instance.

GetInput Gets the input variables for a task.

SetOutput Sets the output variables for a task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
TaskVariables.GetContext method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, used to share the context between different steps and tasks that are in the same job instance. This
method is not implemented.

Syntax
TaskVariables.GetContext( _
ByRef context _
)

Parameters
context [out]
The context that is used to share the context between different steps and tasks that are in the same job instance.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskVariables
TaskVariables.GetInput method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the input variables for a task. This method is not implemented.

Syntax
TaskVariables.GetInput( _
ByRef input _
)

Parameters
input [out]
The input variables for a task.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskVariables
TaskVariables.SetOutput method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, sets the output variables for a task. This method is not implemented.

Syntax
TaskVariables.SetOutput( _
ByVal input _
)

Parameters
input [in]
The output variables for a task.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TaskVariables
TimeTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task at a specific date and time.

Members
The TimeTrigger object has these types of members:
Properties
Properties
The TimeTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Enabled Read/write Inherited from Trigger . Gets or sets a


Boolean value that indicates whether
the trigger is enabled.

EndBoundar y Read/write Inherited from Trigger . Gets or sets


the date and time when the trigger is
deactivated. The trigger cannot start
the task after it is deactivated.

ExecutionTimeLimit Read/write Inherited from Trigger . Gets or sets


the maximum amount of time that the
task launched by the trigger is allowed
to run.

Id Read/write Inherited from Trigger . Gets or sets


the identifier for the trigger.

RandomDelay Read/write Gets or sets a delay time that is


randomly added to the start time of
the trigger.

Repetition Read/write Inherited from Trigger . Gets or sets


how often the task is run and how
long the repetition pattern is repeated
after the task is started.

Star tBoundar y Read/write Inherited from Trigger . Gets or sets


the date and time when the trigger is
activated. This element is required.

Type Read-only Inherited from Trigger . Gets the type


of the trigger.

Remarks
The Star tBoundar y element is a required element for time and calendar triggers (TimeTrigger and
CalendarTrigger ).
When reading or writing XML for a task, an idle trigger is specified using the TimeTrigger element of the Task
Scheduler schema.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Header
Windows.applicationmodel.background.h

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
TriggerCollection
TriggerCollection.Create
TimeTrigger.RandomDelay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a delay time that is randomly added to the start time of the trigger.

Syntax
TimeTrigger.RandomDelay As String

Property value
The delay time that is randomly added to the start time of the trigger. The format for this string is
PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days, 'T'
is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of
seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours,
and five minutes).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
Trigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that provides the common properties that are inherited by all trigger objects.

Members
The Trigger object has these types of members:
Properties
Properties
The Trigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Enabled Read/write Gets or sets a Boolean value that


indicates whether the trigger is
enabled.

EndBoundar y Read/write Gets or sets the date and time when


the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Gets or sets the maximum amount of


time that the task launched by the
trigger is allowed to run.

Id Read/write Gets or sets the identifier for the


trigger.

Repetition Read/write Gets or sets a value that indicates how


often the task is run and how long the
repetition pattern is repeated after the
task is started.

Star tBoundar y Read/write Gets or sets the date and time when
the trigger is activated. The trigger can
start the task after the trigger is
activated.

Type Gets the type of the trigger.

Remarks
The Task Scheduler provides the following individual objects for the different triggers that a task can use:
BootTrigger
DailyTrigger
EventTrigger
IdleTrigger
LogonTrigger
MonthlyDOWTrigger
MonthlyTrigger
RegistrationTrigger
TimeTrigger
WeeklyTrigger
SessionStateChangeTrigger
When reading or writing XML, the triggers of a task are specified in the Triggers element of the Task Scheduler
schema.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TriggerCollection
Trigger.Enabled property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a Boolean value that indicates whether the trigger is enabled.

Syntax
Trigger.Enabled As Boolean

Property value
True if the trigger is enabled; otherwise, false. The default is true.

Remarks
When reading or writing XML for a task, the enabled property is specified using the Enabled element of the
Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Trigger.EndBoundary property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the date and time when the trigger is deactivated. The trigger cannot start the task
after it is deactivated.

Syntax
Trigger.EndBoundary As String

Property value
The date and time when the trigger is deactivated. The date and time must be in the following format: YYYY-
MM-DDTHH:MM:SS(+-)HH:MM. For example the date October 11th, 2005 at 1:21:17 in the Pacific time zone
would be written as 2005-10-11T13:21:17-08:00. The (+-)HH:MM section of the format describes the time zone
as a certain number of hours ahead or behind Coordinated Universal Time (Greenwich Mean Time).

Remarks
When reading or writing XML for a task, the enabled property is specified using the EndBoundar y element of
the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Trigger.ExecutionTimeLimit property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the maximum amount of time that the task launched by the trigger is allowed to run.

Syntax
Trigger.ExecutionTimeLimit As String

Property value
The maximum amount of time that the task launched by the trigger is allowed to run. The format for this string
is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days,
'T' is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of
seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours,
and five minutes).

Remarks
When reading or writing XML for a task, the execution time limit is specified in the ExecutionTimeLimit
element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Trigger.Id property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the identifier for the trigger.

Syntax
Trigger.Id As String

Property value
The identifier for the trigger. This identifier is used by the Task Scheduler for logging purposes.

Remarks
When reading or writing XML for a task, the trigger identifier is specified in the Id attribute of the individual
trigger elements (for example, the Id attribute of the BootTrigger element) of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Trigger.Repetition property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a value that indicates how often the task is run and how long the repetition pattern is
repeated after the task is started.

Syntax
Trigger.Repetition As RepetitionPattern

Property value
A RepetitionPattern object that defines how often the task is run and how long the repetition pattern is
repeated after the task is started.

Remarks
When reading or writing your own XML for a task, the repetition pattern for a trigger is specified in the
Repetition element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
RepetitionPattern
Trigger.StartBoundary property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the date and time when the trigger is activated.

Syntax
Trigger.StartBoundary As String

Property value
The date and time when the trigger is activated. The date and time must be in the following format: YYYY-MM-
DDTHH:MM:SS(+-)HH:MM. For example the date October 11th, 2005 at 1:21:17 in the Pacific Time zone would
be written as 2005-10-11T13:21:17-08:00. The (+-)HH:MM section of the format describes the time zone as a
certain number of hours ahead or behind Coordinated Universal Time (Greenwich Mean Time).

Remarks
When reading or writing XML for a task, the trigger start boundary is specified in the Star tBoundar y element
of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Trigger.Type property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the type of the trigger. The trigger type is defined when the trigger is created and cannot be
changed later. For information on creating a trigger, see TriggerCollection.Create .

Syntax
Trigger.Type As TASK_TRIGGER_TYPE2

Property value
One of the following TASK_TRIGGER_TYPE2 enumeration values.

VA L UE M EA N IN G

Starts the task when a specific event occurs.


TASK_TRIGGER_EVENT
0

Starts the task at a specific time of day.


TASK_TRIGGER_TIME
1

Starts the task daily.


TASK_TRIGGER_DAILY
2

Starts the task weekly.


TASK_TRIGGER_WEEKLY
3

Starts the task monthly.


TASK_TRIGGER_MONTHLY
4

Starts the task every month on a specific day of the week.


TASK_TRIGGER_MONTHLYDOW
5

Starts the task when the computer goes into an idle state.
TASK_TRIGGER_IDLE
6

Starts the task when the task is registered.


TASK_TRIGGER_REGISTRATION
7
VA L UE M EA N IN G

Starts the task when the computer boots.


TASK_TRIGGER_BOOT
8

Starts the task when a specific user logs on.


TASK_TRIGGER_LOGON
9

Triggers the task when a specific session state changes.


TASK_TRIGGER_SESSION_STATE_CHANGE
11

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
TriggerCollection.Create
TASK_TRIGGER_TYPE2
Task Scheduler
TriggerCollection object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that is used to add to, remove from, and retrieve the triggers of a task.

Members
The TriggerCollection object has these types of members:
Methods
Properties
Methods
The TriggerCollection object has these methods.

M ET H O D DESC RIP T IO N

Clear Clears all triggers from the collection.

Create Creates a new trigger for the task.

Remove Removes the specified trigger from the collection of triggers


used by the task.

Properties
The TriggerCollection object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Count Read-only Gets the number of triggers in the


collection.

Item Read-only Gets the specified trigger from the


collection.

Remarks
When reading or writing XML for a task, the triggers for the task are specified in the Triggers element of the
Task Scheduler schema.
For information about each trigger type see Trigger Types.

Examples
For more information and example code for this scripting object, see Time Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Header
Windows.ui.xaml.h

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
TriggerCollection.Count property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the number of triggers in the collection.

Syntax
TriggerCollection.Count As long

Property value
The number of triggers in the collection.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TriggerCollection.Item property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets the specified trigger from the collection.

Syntax
TriggerCollection.Item( _
ByVal index _
) As Trigger

Property value
A Trigger object that represents the requested trigger.

Remarks
Collections are 1-based. In other words, the index for the first item in the collection is 1.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TriggerCollection.Clear method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, clears all triggers from the collection.

Syntax
TriggerCollection.Clear()

Parameters
This method has no parameters.

Return value
This method does not return a value.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
TriggerCollection.Create method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, creates a new trigger for the task.

Syntax
TriggerCollection.Create( _
ByVal type _
)

Parameters
type [in]
This parameter is set to one of the following TASK_TRIGGER_TYPE2 enumeration constants.

VA L UE M EA N IN G

Triggers the task when a specific event occurs.


TASK_TRIGGER_EVENT
0

Triggers the task at a specific time of day.


TASK_TRIGGER_TIME
1

Triggers the task on a daily schedule. For example, the task


TASK_TRIGGER_DAILY starts at a specific time every day, every-other day, every
2 third day, and so on.

Triggers the task on a weekly schedule. For example, the task


TASK_TRIGGER_WEEKLY starts at 8:00 AM on a specific day every week or other
3 week.

Triggers the task on a monthly schedule. For example, the


TASK_TRIGGER_MONTHLY task starts on specific days of specific months.
4

Triggers the task on a monthly day-of-week schedule. For


TASK_TRIGGER_MONTHLYDOW example, the task starts on a specific days of the week,
5 weeks of the month, and months of the year.

Triggers the task when the computer goes into an idle state.
TASK_TRIGGER_IDLE
6
VA L UE M EA N IN G

Triggers the task when the task is registered.


TASK_TRIGGER_REGISTRATION
7

Triggers the task when the computer boots.


TASK_TRIGGER_BOOT
8

Triggers the task when a specific user logs on.


TASK_TRIGGER_LOGON
9

Triggers the task when a specific session state changes.


TASK_TRIGGER_SESSION_STATE_CHANGE
11

Return value
A Trigger object that represents the new trigger.

Remarks
For information about each trigger type see Trigger Types.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Trigger
TriggerCollection.Remove method
8/8/2022 • 2 minutes to read • Edit Online

For scripting, removes the specified trigger from the collection of triggers used by the task.

Syntax
TriggerCollection.Remove( _
ByVal index _
)

Parameters
index [in]
The index of the trigger to be removed.

Return value
This method does not return a value.

Remarks
When removing items, note that the index for the first item in the collection is 1 and the index for the last item is
the value of the TriggerCollection.Count property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
WeeklyTrigger object
8/8/2022 • 2 minutes to read • Edit Online

Scripting object that represents a trigger that starts a task based on a weekly schedule. For example, the task
starts at 8:00 A.M. on a specific day of the week every week or every other week.

Members
The WeeklyTrigger object has these types of members:
Properties
Properties
The WeeklyTrigger object has these properties.

P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

DaysOfWeek Read/write Gets or sets the days of the week on


which the task runs.

Enabled Read/write Inherited from the Trigger object.


Gets or sets a Boolean value that
indicates whether the trigger is
enabled.

EndBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit Read/write Inherited from the Trigger object.


Gets or sets the maximum amount of
time that the task launched by the
trigger is allowed to run.

Id Read/write Inherited from the Trigger object.


Gets or sets the identifier for the
trigger.

RandomDelay Read/write Gets or sets a delay time that is


randomly added to the start time of
the trigger.

Repetition Read/write Inherited from the Trigger object.


Gets or sets how often the task is run
and how long the repetition pattern is
repeated after the task is started.

Star tBoundar y Read/write Inherited from the Trigger object.


Gets or sets the date and time when
the trigger is activated.
P RO P ERT Y A C C ESS T Y P E DESC RIP T IO N

Type Read-only Inherited from the Trigger object.


Gets the type of the trigger.

WeeksInter val Read/write Gets or sets the interval between the


weeks in the schedule.

Remarks
The time of day that the task is started is set by the Star tBoundar y property.
When reading or writing your own XML for a task, a weekly trigger is specified using the ScheduleByWeek
element of the Task Scheduler schema.

Examples
For more information and a code example for this scripting object, see Weekly Trigger Example (Scripting).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Trigger
TriggerCollection
TriggerCollection.Create
WeeklyTrigger.DaysOfWeek property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the days of the week on which the task runs.

Syntax
WeeklyTrigger.DaysOfWeek As short

Property value
A bitwise mask that indicates the days of the week on which the task runs.

Remarks
The following table shows the mapping of the bitwise mask used by this property.

MONT H H EX VA L UE DEC IM A L VA L UE

Sunday 0X01 1

Monday 0x02 2

Tuesday 0X04 4

Wednesday 0X08 8

Thursday 0X10 16

Friday 0x20 32

Saturday 0X40 64

When reading or writing your own XML for a task, the days of the week are specified using the DaysOfWeek
element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb
REQ UIREM EN T VA L UE

DLL
Taskschd.dll

See also
Task Scheduler
WeeklyTrigger.RandomDelay property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets a delay time that is randomly added to the start time of the trigger.

Syntax
WeeklyTrigger.RandomDelay As String

Property value
The delay time that is randomly added to the start time of the trigger. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S (for example, P2DT5S is a 2 day, 5 second delay).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll
WeeklyTrigger.WeeksInterval property
8/8/2022 • 2 minutes to read • Edit Online

For scripting, gets or sets the interval between the weeks in the schedule.

Syntax
WeeklyTrigger.WeeksInterval As short

Property value
The interval between the weeks in the schedule.

Remarks
An interval of 1 produces a weekly schedule. An interval of 2 produces an every-other week schedule.
When reading or writing your own XML for a task, the interval for a weekly schedule is specified using the
WeeksInter val element of the Task Scheduler schema.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Type library
Taskschd.tlb

DLL
Taskschd.dll

See also
Task Scheduler
Task Scheduler Interfaces
8/8/2022 • 3 minutes to read • Edit Online

The interfaces that are described in the following topics provide programmatic access to the functionality that is
available within the Task Scheduler.
These topics contain a description of the interface, a list of the properties and methods defined by the interface,
and remarks about any special circumstances that should be noted when using the interface.
The following interfaces are introduced in Task Scheduler 2.0, which is used in the Windows Vista operating
system.

IN T ERFA C E DESC RIP T IO N

IAction Provides the common properties that are inherited by all


action objects.

IActionCollection Contains the actions that are performed by the task. Its
methods can be used to add to, remove from, and retrieve
the actions of a task.

IBootTrigger Represents a trigger that starts a task when the system is


started.

IComHandlerAction Represents an action that fires a handler.

IDailyTrigger Represents a trigger that starts a task based on a daily


schedule.

IEmailAction Represents an action that sends an email message.

IEventTrigger Represents a trigger that starts a task when a system event


occurs.

IExecAction Represents an action that executes a command-line


operation.

IIdleSettings Specifies how the Task Scheduler performs tasks when the
computer is in an idle condition.

IIdleTrigger Represents a trigger that starts a task when the computer


goes into an idle state.

ILogonTrigger Represents a trigger that starts a task when a user logs on.

IMaintenanceSettings Provides the settings that the Task Scheduler uses to


perform task during Automatic maintenance.

IMonthlyDOWTrigger Represents a trigger that starts a task on a monthly day-of-


week schedule.
IN T ERFA C E DESC RIP T IO N

IMonthlyTrigger Represents a trigger that starts a task based on a monthly


schedule.

INetworkSettings Provides the settings that the Task Scheduler service uses to
obtain a network profile.

IPrincipal Provides the security credentials for a principal.

IPrincipal2 Provides additional security credentials for a principal.

IRegisteredTask Provides the methods that are used to run the task
immediately, get any running instances of the task, get or
set the credentials that are used to register the task, and the
properties that describe the task.

IRegisteredTaskCollection Contains all the tasks that are registered.

IRegistrationInfo Provides the administrative information that can be used to


describe the task. This information includes details such as a
description of the task, the author of the task, the date the
task is registered, and the security descriptor of the task.

IRegistrationTrigger Represents a trigger that starts a task when the task is


registered.

IRepetitionPattern Defines how often the task is run and how long the
repetition pattern is repeated after the task is started.

IRunningTask Provides the methods to get information from and control a


running task.

IRunningTaskCollection Provides a collection that is used to control running tasks.

ISessionStateChangeTrigger Triggers tasks for console connect or disconnect, remote


connect or disconnect, or workstation lock or unlock
notifications.

IShowMessageAction Represents an action that shows a message box when a task


is activated.

ITaskDefinition Defines all the components of a task, such as the task


settings, triggers, actions, and registration information.

ITaskFolder Provides the methods that are used to register (create) tasks
in the folder, remove tasks from the folder, and create or
remove subfolders from the folder.

ITaskFolderCollection Provides information and control for a collection of folders


that contain tasks.

ITaskHandler Defines the methods that are called by the Task Scheduler
service to manage a COM handler.
IN T ERFA C E DESC RIP T IO N

ITaskHandlerStatus Provides the methods that are used by COM handlers to


notify the Task Scheduler about the status of the handler.

ITaskNamedValuePair Creates a name-value pair in which the name is associated


with the value.

ITaskNamedValueCollection Contains a collection of ITaskNamedValuePair interface


name-value pairs.

ITaskSer vice Provides access to the Task Scheduler service for managing
registered tasks.

ITaskSettings Provides the settings that the Task Scheduler service uses to
perform the task.

ITaskSettings2 Provides additional settings that the Task Scheduler uses to


perform the task.

ITaskVariables Defines task variables that can be passed as parameters to


task handlers and external executables that are launched by
tasks. Task handlers that need to input and output data to
job variables should do a query interface on the services
pointer for ITaskVariables .

ITimeTrigger Represents a trigger that starts a task when the trigger is


activated.

ITrigger Provides the common properties that are inherited by all


trigger interfaces.

ITriggerCollection Provides the methods that are used to add to, remove from,
and get the triggers of a task.

IWeeklyTrigger Represents a trigger that starts a task based on a weekly


schedule.

WARNING
The Task Scheduler 1.0 interfaces are available only in Windows 2000, Windows XP, and Windows Server 2003 operating
systems. They are deprecated as of Windows Vista and may be removed completely in the future. Please use the Task
Scheduler 2.0 interfaces listed above instead.
Task Scheduler 1.0 Interfaces
8/8/2022 • 2 minutes to read • Edit Online

[[This API may be altered or unavailable in subsequent versions of the operating system or product. Please use
the Task Scheduler 2.0 Interfaces or Task Scheduler 2.0 Enumerated Types instead.] ]
The interfaces that are described in the following topics provide programmatic access to the functionality that is
available within the Task Scheduler that is used in the Windows 2000, Windows XP, and Windows Server 2003
operating systems.
These topics contain a description of the interface, a list of the properties and methods defined by the interface,
and remarks about any special circumstances that should be noted when using the interface.
The following interfaces are introduced by Task Scheduler 1.0.

IN T ERFA C E DESC RIP T IO N

IEnumWorkItems Provides the methods for enumerating the tasks in the


Scheduled Tasks folder.

IProvideTaskPage Provides the methods to access the property sheet settings


of a task.

IScheduledWorkItem Provides the methods for managing specific work items.

ITask Provides the methods for running tasks, getting or setting


task information, and terminating tasks. It is derived from
the IScheduledWorkItem interface and inherits all the
methods of that interface.

ITaskScheduler Provides the methods for scheduling tasks.

ITaskTrigger Provides the methods for accessing and setting triggers for a
task. Triggers specify task start times, repetition criteria, and
other parameters that control when a task is run.
Task Scheduler 2.0 Interfaces
8/8/2022 • 3 minutes to read • Edit Online

The interfaces that are described in the following topics provide programmatic access to the functionality that is
available within the Task Scheduler that is used in the Windows Vista operating system.
These topics contain a description of the interface, a list of the properties and methods defined by the interface,
and remarks about any special circumstances that should be noted when using the interface.
The following interfaces are introduced in Task Scheduler 2.0.

IN T ERFA C E DESC RIP T IO N

IAction Provides the common properties that are inherited by all


action objects.

IActionCollection Contains the actions that are performed by the task. Its
methods can be used to add to, remove from, and retrieve
the actions of a task.

IBootTrigger Represents a trigger that starts a task when the system is


started

IComHandlerAction Represents an action that fires a handler.

IDailyTrigger Represents a trigger that starts a task based on a daily


schedule.

IEmailAction Represents an action that sends an email message.

IEventTrigger Represents a trigger that starts a task when a system event


occurs.

IExecAction Represents an action that executes a command-line


operation.

IIdleSettings Specifies how the Task Scheduler performs tasks when the
computer is in an idle condition.

IIdleTrigger Represents a trigger that starts a task when the computer


goes into an idle state.

ILogonTrigger Represents a trigger that starts a task when a user logs on.

IMaintenanceSettings Provides the settings that the Task Scheduler uses to


perform task during Automatic maintenance.

IMonthlyDOWTrigger Represents a trigger that starts a task on a monthly day-of-


week schedule.

IMonthlyTrigger Represents a trigger that starts a task based on a monthly


schedule.
IN T ERFA C E DESC RIP T IO N

INetworkSettings Provides the settings that the Task Scheduler service uses to
obtain a network profile.

IPrincipal Provides the security credentials for a principal.

IPrincipal2 Provides additional security credentials for a principal.

IRegisteredTask Provides the methods that are used to run the task
immediately, get any running instances of the task, get or
set the credentials that are used to register the task, and the
properties that describe the task.

IRegisteredTaskCollection Contains all the tasks that are registered.

IRegistrationInfo Provides the administrative information that can be used to


describe the task. This information includes details such as a
description of the task, the author of the task, the date the
task is registered, and the security descriptor of the task.

IRegistrationTrigger Represents a trigger that starts a task when the task is


registered.

IRepetitionPattern Defines how often the task is run and how long the
repetition pattern is repeated after the task is started.

IRunningTask Provides the methods to get information from and control a


running task.

IRunningTaskCollection Provides a collection that is used to control running tasks.

ISessionStateChangeTrigger Triggers tasks for console connect or disconnect, remote


connect or disconnect, or workstation lock or unlock
notifications.

IShowMessageAction Represents an action that shows a message box when a task


is activated.

ITaskDefinition Defines all the components of a task, such as the task


settings, triggers, actions, and registration information.

ITaskFolder Provides the methods that are used to register (create) tasks
in the folder, remove tasks from the folder, and create or
remove subfolders from the folder.

ITaskFolderCollection Provides information and control for a collection of folders


that contain tasks.

ITaskHandler Defines the methods that are called by the Task Scheduler
service to manage a COM handler.

ITaskHandlerStatus Provides the methods that are used by COM handlers to


notify the Task Scheduler about the status of the handler.
IN T ERFA C E DESC RIP T IO N

ITaskNamedValuePair Creates a name-value pair in which the name is associated


with the value.

ITaskNamedValueCollection Contains a collection of ITaskNamedValuePair interface


name-value pairs.

ITaskSer vice Provides access to the Task Scheduler service for managing
registered tasks.

ITaskSettings Provides the settings that the Task Scheduler services uses
to perform the task.

ITaskSettings2 Provides additional settings that the Task Scheduler services


uses to perform the task.

ITaskSettings3 Provides the extended settings that the Task Scheduler uses
to run the task.

ITaskVariables Defines task variables that can be passed as parameters to


task handlers and external executables that are launched by
tasks. Task handlers that need to input and output data to
job variables should do a query interface on the services
pointer for ITaskVariables .

ITimeTrigger Represents a trigger that starts a task when the trigger is


activated.

ITrigger Provides the common properties that are inherited by all


trigger interfaces.

ITriggerCollection Provides the methods that are used to add to, remove from,
and get the triggers of a task.

IWeeklyTrigger Represents a trigger that starts a task based on a weekly


schedule.
Task Scheduler Structures and Unions
8/8/2022 • 2 minutes to read • Edit Online

This section describes the structures and unions used by the Task Scheduler APIs.
All the structures and unions below are used by Task Scheduler 1.0.

NAME DESC RIP T IO N

DAILY Defines the interval, in days, at which a task is run.

MONTHLYDATE Defines the day of the month the task will run.

MONTHLYDOW Defines the date(s) that the task runs by month, week, and
day of the week.

TASK_TRIGGER Defines the times to run a scheduled work item.

TRIGGER_TYPE_UNION Defines the invocation schedule of the trigger within the


Type member of a TASK_TRIGGER structure.

WEEKLY Defines the interval, in weeks, between invocations of a task.


Task Scheduler Enumerated Types
8/8/2022 • 2 minutes to read • Edit Online

Describes the enumerated types that define the constants that are used by the Task Scheduler APIs.
The following enumerated types are introduced in Task Scheduler 2.0.

EN UM ERAT IO N DESC RIP T IO N

TASK_ACTION_TYPE Defines the type of actions that a task can perform.

TASK_COMPATIBILITY Defines what versions of Task Scheduler or the AT command


that the task is compatible with.

TASK_CREATION Defines how the Task Scheduler service creates, updates, or


disables the task.

TASK_ENUM_FL AGS Defines how the Task Scheduler enumerates through


registered tasks.

TASK_INSTANCES_POLICY Defines how the Task Scheduler handles existing instances of


the task when it starts a new instance of the task.

TASK_LOGON TYPE Defines what logon technique is required to run a task.

TASK_PROCESSTOKENSID TYPE Defines the types of process SID that can used by tasks.

TASK_RUN_FL AGS Defines how a task is run.

TASK_RUNLEVEL_TYPE Defines LUA elevation flags that specify with what privilege
level the task will be run.

TASK_SESSION_STATE_CHANGE_TYPE Defines what kinds of Terminal Server session state change


you can use to trigger a task to start.

TASK_STATE Defines the different states that a registered task can be in.

TASK_TRIGGER_TYPE2 Defines the type of triggers that can be used by tasks.

WARNING
The Task Scheduler 1.0 enumerations are available only in Windows 2000, Windows XP, and Windows Server 2003
operating systems. They are deprecated as of Windows Vista and may be removed completely in the future. Please use
the Task Scheduler 2.0 enumerations listed above instead.

Related topics
Task Scheduler
Task Scheduler Reference
Task Scheduler 1.0 Enumerated Types
8/8/2022 • 2 minutes to read • Edit Online

[[This API may be altered or unavailable in subsequent versions of the operating system or product. Please use
the Task Scheduler 2.0 Interfaces or Task Scheduler 2.0 Enumerated Types instead.] ]
Describes the enumerated types that define the constants that are used by the Task Scheduler 1.0 APIs.
The following enumerated types are introduced by Task Scheduler 1.0.

NAME DESC RIP T IO N

TASK_TRIGGER_TYPE Defines the types of triggers associated with a task.

TASKPAGE Defines the type of task page to be retrieved.

Related topics
Task Scheduler
Task Scheduler Reference
Task Scheduler 2.0 Enumerated Types
8/8/2022 • 2 minutes to read • Edit Online

Describes the enumerated types that define the constants that are used by the Task Scheduler 2.0 APIs.
The following enumerated types are introduced in Task Scheduler 2.0.

EN UM ERAT IO N DESC RIP T IO N

TASK_ACTION_TYPE Defines the type of actions that a task can perform.

TASK_COMPATIBILITY Defines what versions of Task Scheduler or the AT command


that the task is compatible with.

TASK_CREATION Defines how the Task Scheduler service creates, updates, or


disables the task.

TASK_ENUM_FL AGS Defines how the Task Scheduler enumerates through


registered tasks.

TASK_INSTANCES_POLICY Defines how the Task Scheduler handles existing instances of


the task when it starts a new instance of the task.

TASK_LOGON TYPE Defines what logon technique is required to run a task.

TASK_PROCESSTOKENSID_TYPE Defines the types of process SID that can be used by tasks.

TASK_RUN_FL AGS Defines how a task is run.

TASK_RUNLEVEL_TYPE Defines LUA elevation flags that specify with what privilege
level the task will be run.

TASK_SESSION_STATE_CHANGE_TYPE Defines what kinds of Terminal Server session state change


you can use to trigger a task to start.

TASK_STATE Defines the different states that a registered task can be in.

TASK_TRIGGER_TYPE2 Defines the type of triggers that can be used by tasks.

Related topics
Task Scheduler
Task Scheduler Reference
Task Scheduler Schema
8/8/2022 • 8 minutes to read • Edit Online

The Task Scheduler schema defines valid XML used to register tasks with the Task Scheduler service. Developers
can create their own XML, validate it against this schema, and register tasks using the
ITaskFolder ::RegisterTask method.
The types and elements of the Task Scheduler schema are individually documented in the following sections.
Task Scheduler Schema Elements
Task Scheduler Schema Simple Types
Task Scheduler Schema Complex Types
Task Scheduler Schema Groups
The entire Task Scheduler schema is defined by the following XSD file.

<?xml version="1.0" encoding="utf-8" ?>


<xs:schema
targetNamespace="http://schemas.microsoft.com/windows/2004/02/mit/task"
xmlns:xs="https://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"
xmlns:td="http://schemas.microsoft.com/windows/2004/02/mit/task"
elementFormDefault="qualified">

<xs:element name="Task" type="taskType">

<xs:key name="PrincipalKey">
<xs:selector xpath="td:Principals/td:Principal" />
<xs:field xpath="@id" />
</xs:key>

<!-- Principal id in Context attribute should match an id of


some principal in Principals section. -->
<xs:keyref name="ContextKeyRef" refer="PrincipalKey">
<xs:selector xpath="td:Actions" />
<xs:field xpath="@Context" />
</xs:keyref>

<!-- All ids must be unique -->


<xs:unique name="UniqueId">
<xs:selector
xpath="td:Principals/td:Principal|td:Triggers/td:BootTrigger|td:Triggers/td:RegistrationTrigger|td:Triggers/
td:IdleTrigger|td:Triggers/td:TimeTrigger|td:Triggers/td:EventTrigger|td:Triggers/td:LogonTrigger|td:Trigger
s/td:SessionStateChangeTrigger|td:Triggers/td:CalendarTrigger|td:Actions/td:Exec|td:Actions/td:ComHandler|td
:Actions/td:SendEmail" />
<xs:field xpath="@id" />
</xs:unique>

</xs:element>

<xs:simpleType name="nonEmptyString">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="pathType">
<xs:restriction base="nonEmptyString">
<xs:maxLength value="260"/>
</xs:restriction>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="versionType">
<xs:restriction base="xs:string">
<xs:pattern value="\d+(\.\d+){1,3}" />
</xs:restriction>
</xs:simpleType>

<!-- Task -->


<xs:complexType name="taskType">
<xs:all>
<xs:element name="RegistrationInfo" type="registrationInfoType" minOccurs="0" />
<xs:element name="Triggers" type="triggersType" minOccurs="0" />
<xs:element name="Settings" type="settingsType" minOccurs="0" />
<xs:element name="Data" type="dataType" minOccurs="0" />
<xs:element name="Principals" type="principalsType" minOccurs="0" />
<xs:element name="Actions" type="actionsType" />
</xs:all>
<xs:attribute name="version" use="optional" fixed="1.3" type="versionType" />
</xs:complexType>

<!-- RegistrationInfo -->


<xs:complexType name="registrationInfoType">
<xs:all>
<xs:element name="URI" type="xs:anyURI" minOccurs="0" />
<xs:element name="SecurityDescriptor" type="xs:string" minOccurs="0" />
<xs:element name="Source" type="xs:string" minOccurs="0" />
<xs:element name="Date" type="xs:dateTime" minOccurs="0" />
<xs:element name="Author" type="xs:string" minOccurs="0" />
<xs:element name="Version" type="xs:string" minOccurs="0" />
<xs:element name="Description" type="xs:string" minOccurs="0" />
<xs:element name="Documentation" type="xs:string" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- Triggers -->


<xs:complexType name="triggersType">
<xs:group ref="triggerGroup" minOccurs="0" maxOccurs="48"/>
</xs:complexType>
<xs:group name="triggerGroup">
<xs:choice>
<xs:element name="BootTrigger" type="bootTriggerType" minOccurs="0"
/>
<xs:element name="RegistrationTrigger" type="registrationTriggerType" minOccurs="0"
/>
<xs:element name="IdleTrigger" type="idleTriggerType" minOccurs="0"
/>
<xs:element name="TimeTrigger" type="timeTriggerType" minOccurs="0"
/>
<xs:element name="EventTrigger" type="eventTriggerType" minOccurs="0"
/>
<xs:element name="LogonTrigger" type="logonTriggerType" minOccurs="0"
/>
<xs:element name="SessionStateChangeTrigger" type="sessionStateChangeTriggerType" minOccurs="0"
/>
<xs:element name="CalendarTrigger" type="calendarTriggerType" minOccurs="0"
/>
</xs:choice>
</xs:group>

<!-- Base type for all triggers -->


<xs:complexType name="triggerBaseType" abstract="true">
<xs:sequence>
<xs:element name="Enabled" type="xs:boolean" default="true" minOccurs="0" />
<xs:element name="StartBoundary" type="xs:dateTime" minOccurs="0" />
<xs:element name="EndBoundary" type="xs:dateTime" minOccurs="0" />
<xs:element name="Repetition" type="repetitionType" minOccurs="0" />
<xs:element name="ExecutionTimeLimit" type="xs:duration" default="PT72H" minOccurs="0" />
</xs:sequence>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="optional" />
</xs:complexType>

<!-- Repetition -->


<xs:complexType name="repetitionType">
<xs:all>
<xs:element name="Interval">
<xs:simpleType>
<xs:restriction base="xs:duration">
<xs:minInclusive value="PT1M"/>
<xs:maxInclusive value="P31D"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Duration" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:duration">
<xs:minInclusive value="PT1M"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="StopAtDurationEnd" type="xs:boolean" default="false" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- BootTrigger -->


<xs:complexType name="bootTriggerType">
<xs:complexContent>
<xs:extension base="triggerBaseType">
<xs:sequence>
<xs:element name="Delay" type="xs:duration" default="PT0M" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- RegistrationTrigger -->


<xs:complexType name="registrationTriggerType">
<xs:complexContent>
<xs:extension base="triggerBaseType">
<xs:sequence>
<xs:element name="Delay" type="xs:duration" default="PT0M" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- IdleTrigger -->


<xs:complexType name="idleTriggerType">
<xs:complexContent>
<xs:extension base="triggerBaseType" />
</xs:complexContent>
</xs:complexType>

<!-- TimeTrigger -->


<xs:complexType name="timeTriggerType">
<xs:complexContent>
<xs:extension base="triggerBaseType">
<xs:sequence>
<xs:element name="RandomDelay" type="xs:duration" default="PT0M" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!--valueQueries-->
<xs:complexType name="namedValues">
<xs:sequence>
<xs:element name="Value" type="namedValue" minOccurs="1" maxOccurs="32"/>
<xs:element name="Value" type="namedValue" minOccurs="1" maxOccurs="32"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="namedValue">
<xs:simpleContent>
<xs:extension base="nonEmptyString">
<xs:attribute name="name" type="nonEmptyString" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<!-- EventTrigger -->


<xs:complexType name="eventTriggerType">
<xs:complexContent>
<xs:extension base="triggerBaseType">
<xs:sequence>
<xs:element name="Subscription" type="nonEmptyString" />
<xs:element name="Delay" type="xs:duration" default="PT0M" minOccurs="0" />
<xs:element name="PeriodOfOccurrence" type="xs:duration" default="PT0M" minOccurs="0"
/>
<xs:element name="NumberOfOccurrences" default="1" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:unsignedByte">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="32"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="MatchingElement" type="nonEmptyString" minOccurs="0" />
<xs:element name="ValueQueries" type="namedValues" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- LogonTrigger -->


<xs:complexType name="logonTriggerType">
<xs:complexContent>
<xs:extension base="triggerBaseType">
<xs:sequence>
<xs:element name="UserId" type="nonEmptyString" minOccurs="0" maxOccurs="1" />
<xs:element name="Delay" type="xs:duration" default="PT0M" minOccurs="0" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- SessionStateChangeTrigger -->


<xs:simpleType name="sessionStateChangeType">
<xs:restriction base="xs:string">
<xs:enumeration value="ConsoleConnect" />
<xs:enumeration value="ConsoleDisconnect" />
<xs:enumeration value="RemoteConnect" />
<xs:enumeration value="RemoteDisconnect" />
<xs:enumeration value="SessionLock" />
<xs:enumeration value="SessionUnlock" />
</xs:restriction>
</xs:simpleType>

<xs:complexType name="sessionStateChangeTriggerType">
<xs:complexContent>
<xs:extension base="triggerBaseType">
<xs:sequence>
<xs:element name="UserId" type="nonEmptyString"
minOccurs="0" maxOccurs="1"/>
<xs:element name="Delay" type="xs:duration" default="PT0M"
minOccurs="0" />
<xs:element name="StateChange" type="sessionStateChangeType"
minOccurs="1" maxOccurs="1"/>
minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- CalendarTrigger -->


<xs:complexType name="calendarTriggerType">
<xs:complexContent>
<xs:extension base="triggerBaseType">
<xs:sequence>
<xs:element name="RandomDelay" type="xs:duration" default="PT0M" minOccurs="0" />
<xs:choice>
<xs:element name="ScheduleByDay" type="dailyScheduleType" />
<xs:element name="ScheduleByWeek" type="weeklyScheduleType" />
<xs:element name="ScheduleByMonth" type="monthlyScheduleType" />
<xs:element name="ScheduleByMonthDayOfWeek" type="monthlyDayOfWeekScheduleType" />
</xs:choice>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- DailySchedule -->


<xs:complexType name="dailyScheduleType">
<xs:all>
<xs:element name="DaysInterval" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:unsignedInt">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="365"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>

<!-- WeeklySchedule -->


<xs:complexType name="weeklyScheduleType">
<xs:all>
<xs:element name="WeeksInterval" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:unsignedByte">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="52"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DaysOfWeek" type="daysOfWeekType" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- MonthlySchedule -->


<xs:complexType name="monthlyScheduleType">
<xs:all>
<xs:element name="DaysOfMonth" type="daysOfMonthType" minOccurs="0" />
<xs:element name="Months" type="monthsType" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- MonthlyDayOfWeekSchedule -->


<xs:complexType name="monthlyDayOfWeekScheduleType">
<xs:all>
<xs:element name="Weeks" type="weeksType" minOccurs="0" />
<xs:element name="DaysOfWeek" type="daysOfWeekType" />
<xs:element name="Months" type="monthsType" minOccurs="0" />
</xs:all>
</xs:complexType>
<!-- DaysOfWeek -->
<xs:complexType name="daysOfWeekType">
<xs:all>
<xs:element name="Monday" fixed="" minOccurs="0" />
<xs:element name="Tuesday" fixed="" minOccurs="0" />
<xs:element name="Wednesday" fixed="" minOccurs="0" />
<xs:element name="Thursday" fixed="" minOccurs="0" />
<xs:element name="Friday" fixed="" minOccurs="0" />
<xs:element name="Saturday" fixed="" minOccurs="0" />
<xs:element name="Sunday" fixed="" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- Months -->


<xs:complexType name="monthsType">
<xs:all>
<xs:element name="January" fixed="" minOccurs="0" />
<xs:element name="February" fixed="" minOccurs="0" />
<xs:element name="March" fixed="" minOccurs="0" />
<xs:element name="April" fixed="" minOccurs="0" />
<xs:element name="May" fixed="" minOccurs="0" />
<xs:element name="June" fixed="" minOccurs="0" />
<xs:element name="July" fixed="" minOccurs="0" />
<xs:element name="August" fixed="" minOccurs="0" />
<xs:element name="September" fixed="" minOccurs="0" />
<xs:element name="October" fixed="" minOccurs="0" />
<xs:element name="November" fixed="" minOccurs="0" />
<xs:element name="December" fixed="" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- DaysOfMonth -->


<xs:complexType name="daysOfMonthType">
<xs:sequence>
<xs:element name="Day" type="dayOfMonthType" minOccurs="0" maxOccurs="32" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="dayOfMonthType">
<xs:restriction base="xs:string">
<xs:pattern value="[1-9]|[1-2][0-9]|3[0-1]|Last" />
</xs:restriction>
</xs:simpleType>

<!-- Weeks -->


<xs:complexType name="weeksType">
<xs:sequence>
<xs:element name="Week" type="weekType" minOccurs="0" maxOccurs="5" />
</xs:sequence>
</xs:complexType>
<xs:simpleType name="weekType">
<xs:restriction base="xs:string">
<xs:pattern value="[1-4]|Last" />
</xs:restriction>
</xs:simpleType>

<!-- Settings -->


<xs:complexType name="settingsType">
<xs:all>
<xs:element name="AllowStartOnDemand" type="xs:boolean"
default="true" minOccurs="0" />
<xs:element name="RestartOnFailure" type="restartType"
minOccurs="0" />
<xs:element name="MultipleInstancesPolicy" type="multipleInstancesPolicyType"
default="IgnoreNew" minOccurs="0" />
<xs:element name="DisallowStartIfOnBatteries" type="xs:boolean"
default="true" minOccurs="0" />
<xs:element name="StopIfGoingOnBatteries" type="xs:boolean"
default="true" minOccurs="0" />
<xs:element name="AllowHardTerminate" type="xs:boolean"
default="true" minOccurs="0" />
<xs:element name="StartWhenAvailable" type="xs:boolean"
default="false" minOccurs="0" />
<xs:element name="NetworkProfileName" type="xs:string"
minOccurs="0" />
<xs:element name="RunOnlyIfNetworkAvailable" type="xs:boolean"
default="false" minOccurs="0" />
<xs:element name="WakeToRun" type="xs:boolean"
default="false" minOccurs="0" />
<xs:element name="Enabled" type="xs:boolean"
default="true" minOccurs="0" />
<xs:element name="Hidden" type="xs:boolean"
default="false" minOccurs="0" />
<xs:element name="DeleteExpiredTaskAfter" type="xs:duration"
default="PT0S" minOccurs="0" />
<xs:element name="IdleSettings" type="idleSettingsType"
minOccurs="0" />
<xs:element name="NetworkSettings" type="networkSettingsType"
minOccurs="0" />
<xs:element name="ExecutionTimeLimit" type="xs:duration"
default="PT72H" minOccurs="0" />
<xs:element name="Priority" type="priorityType"
default="7" minOccurs="0" />
<xs:element name="RunOnlyIfIdle" type="xs:boolean"
default="false" minOccurs="0" />
<xs:element name="UseUnifiedSchedulingEngine" type="xs:boolean"
default="false" minOccurs="0" />
<xs:element name="DisallowStartOnRemoteAppSession" type="xs:boolean"
default="false" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- MultipleInstancesPolicy -->


<xs:simpleType name="multipleInstancesPolicyType">
<xs:restriction base="xs:string">
<xs:enumeration value="Parallel" />
<xs:enumeration value="Queue" />
<xs:enumeration value="IgnoreNew" />
<xs:enumeration value="StopExisting" />
</xs:restriction>
</xs:simpleType>

<!-- Lower number means higher priority. -->


<xs:simpleType name="priorityType">
<xs:restriction base="xs:byte">
<xs:minInclusive value="0" fixed="true" />
<xs:maxInclusive value="10" fixed="true" />
</xs:restriction>
</xs:simpleType>

<!-- IdleSettings -->


<xs:complexType name="idleSettingsType">
<xs:all>
<xs:element name="Duration" default="PT10M" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:duration">
<xs:minInclusive value="PT1M"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="WaitTimeout" default="PT1H" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:duration">
<xs:minInclusive value="PT1M"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="StopOnIdleEnd" type="xs:boolean" default="true" minOccurs="0" />
<xs:element name="RestartOnIdle" type="xs:boolean" default="false" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- NetworkSettings -->


<xs:complexType name="networkSettingsType">
<xs:all>
<xs:element name="Name" type="nonEmptyString" minOccurs="0" />
<xs:element name="Id" type="guidType" minOccurs="0" />
</xs:all>
</xs:complexType>

<!-- RestartOnFailure -->


<xs:complexType name="restartType">
<xs:all>
<xs:element name="Interval">
<xs:simpleType>
<xs:restriction base="xs:duration">
<xs:minInclusive value="PT1M"/>
<xs:maxInclusive value="P31D"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Count">
<xs:simpleType>
<xs:restriction base="xs:unsignedByte">
<xs:minInclusive value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>

<!-- Data -->


<xs:complexType name="dataType">
<xs:sequence>
<xs:any />
</xs:sequence>
</xs:complexType>

<!-- Principals -->


<xs:complexType name="principalsType">
<xs:sequence>
<xs:element name="Principal" type="principalType" maxOccurs="1" />
</xs:sequence>
</xs:complexType>

<!-- Principal -->


<xs:complexType name="principalType">
<xs:all>
<xs:element name="UserId" type="nonEmptyString" minOccurs="0" />
<xs:element name="LogonType" type="logonType" minOccurs="0" maxOccurs="1"/>
<xs:element name="GroupId" type="nonEmptyString" minOccurs="0" />
<xs:element name="DisplayName" type="xs:string" minOccurs="0" />
<xs:element name="RunLevel" type="runLevelType" minOccurs="0" maxOccurs="1"/>
<xs:element name="ProcessTokenSidType" type="processTokenSidType" minOccurs="0" maxOccurs="1"/>
<xs:element name="RequiredPrivileges" type="requiredPrivilegesType" minOccurs="0" />
</xs:all>
<xs:attribute name="id" type="xs:ID" use="optional" />
</xs:complexType>
<xs:simpleType name="logonType">
<xs:restriction base="xs:string">
<xs:enumeration value="S4U" />
<xs:enumeration value="Password" />
<xs:enumeration value="InteractiveToken" />
<!-- for backward compatibility -->
<xs:enumeration value="InteractiveTokenOrPassword" />
</xs:restriction>
</xs:simpleType>
</xs:simpleType>

<xs:simpleType name="runLevelType">
<xs:restriction base="xs:string">
<xs:enumeration value="LeastPrivilege" />
<xs:enumeration value="HighestAvailable" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="processTokenSidType">
<xs:restriction base="xs:string">
<xs:enumeration value="None" />
<xs:enumeration value="Unrestricted" />
</xs:restriction>
</xs:simpleType>

<xs:complexType name="requiredPrivilegesType">
<xs:sequence>
<xs:element name="Privilege" type="privilegeType" minOccurs="1" maxOccurs="64"/>
</xs:sequence>
</xs:complexType>

<xs:simpleType name="privilegeType">
<xs:restriction base="xs:string">
<xs:enumeration value="SeCreateTokenPrivilege" />
<xs:enumeration value="SeAssignPrimaryTokenPrivilege" />
<xs:enumeration value="SeLockMemoryPrivilege" />
<xs:enumeration value="SeIncreaseQuotaPrivilege" />
<xs:enumeration value="SeUnsolicitedInputPrivilege" />
<xs:enumeration value="SeMachineAccountPrivilege" />
<xs:enumeration value="SeTcbPrivilege" />
<xs:enumeration value="SeSecurityPrivilege" />
<xs:enumeration value="SeTakeOwnershipPrivilege" />
<xs:enumeration value="SeLoadDriverPrivilege" />
<xs:enumeration value="SeSystemProfilePrivilege" />
<xs:enumeration value="SeSystemtimePrivilege" />
<xs:enumeration value="SeProfileSingleProcessPrivilege" />
<xs:enumeration value="SeIncreaseBasePriorityPrivilege" />
<xs:enumeration value="SeCreatePagefilePrivilege" />
<xs:enumeration value="SeCreatePermanentPrivilege" />
<xs:enumeration value="SeBackupPrivilege" />
<xs:enumeration value="SeRestorePrivilege" />
<xs:enumeration value="SeShutdownPrivilege" />
<xs:enumeration value="SeDebugPrivilege" />
<xs:enumeration value="SeAuditPrivilege" />
<xs:enumeration value="SeSystemEnvironmentPrivilege" />
<xs:enumeration value="SeChangeNotifyPrivilege" />
<xs:enumeration value="SeRemoteShutdownPrivilege" />
<xs:enumeration value="SeUndockPrivilege" />
<xs:enumeration value="SeSyncAgentPrivilege" />
<xs:enumeration value="SeEnableDelegationPrivilege" />
<xs:enumeration value="SeManageVolumePrivilege" />
<xs:enumeration value="SeImpersonatePrivilege" />
<xs:enumeration value="SeCreateGlobalPrivilege" />
<xs:enumeration value="SeTrustedCredManAccessPrivilege" />
<xs:enumeration value="SeRelabelPrivilege" />
<xs:enumeration value="SeIncreaseWorkingSetPrivilege" />
<xs:enumeration value="SeTimeZonePrivilege" />
<xs:enumeration value="SeCreateSymbolicLinkPrivilege" />
</xs:restriction>
</xs:simpleType>

<!-- Actions -->


<xs:complexType name="actionsType">
<xs:sequence>
<xs:group ref="actionGroup" maxOccurs="32" />
</xs:sequence>
<xs:attribute name="Context" type="xs:IDREF" use="optional" />
</xs:complexType>
<xs:group name="actionGroup">
<xs:group name="actionGroup">
<xs:choice>
<xs:element name="Exec" type="execType" />
<xs:element name="ComHandler" type="comHandlerType" />
<xs:element name="SendEmail" type="sendEmailType" />
<xs:element name="ShowMessage" type="showMessageType" />
</xs:choice>
</xs:group>

<!-- Base type for actions. -->


<xs:complexType name="actionBaseType" abstract="true">
<xs:attribute name="id" type="xs:ID" use="optional" />
</xs:complexType>

<!-- Exec -->


<xs:complexType name="execType">
<xs:complexContent>
<xs:extension base="actionBaseType">
<xs:all>
<xs:element name="Command" type="pathType"/>
<xs:element name="Arguments" type="xs:string" minOccurs="0"/>
<xs:element name="WorkingDirectory" type="pathType" minOccurs="0"/>
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<!-- ComHandler -->


<xs:complexType name="comHandlerType">
<xs:complexContent>
<xs:extension base="actionBaseType">
<xs:all>
<xs:element name="ClassId" type="guidType" />
<xs:element name="Data" type="dataType" minOccurs="0" />
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:simpleType name="guidType">
<xs:restriction base="xs:string">
<!-- GUID should be in a form:
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
where x is a hexadecimal digit. -->
<xs:pattern value="\{([0-9a-fA-F]){8}(\-[0-9a-fA-F]{4}){3}\-[0-9a-fA-F]{12}\}" />
</xs:restriction>
</xs:simpleType>

<!-- SendEmail -->


<xs:complexType name="sendEmailType">
<xs:complexContent>
<xs:extension base="actionBaseType">
<xs:all>
<xs:element name="Server" type="nonEmptyString" />
<xs:element name="Subject" type="xs:string" minOccurs="0" />
<xs:element name="To" type="xs:string" minOccurs="0" />
<xs:element name="Cc" type="xs:string" minOccurs="0" />
<xs:element name="Bcc" type="xs:string" minOccurs="0" />
<xs:element name="ReplyTo" type="xs:string" minOccurs="0" />
<xs:element name="From" type="xs:string" minOccurs="0" />
<xs:element name="HeaderFields" type="headerFieldsType" minOccurs="0" />
<xs:element name="Body" type="xs:string" minOccurs="0" />
<xs:element name="Attachments" type="attachmentsType" minOccurs="0" />
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="headerFieldsType">
<xs:sequence>
<xs:sequence>
<xs:element name="HeaderField" type="headerFieldType" minOccurs="0" maxOccurs="32"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="headerFieldType">
<xs:all>
<xs:element name="Name" type="nonEmptyString" />
<xs:element name="Value" type="xs:string" />
</xs:all>
</xs:complexType>

<xs:complexType name="attachmentsType">
<xs:sequence>
<xs:element name="File" type="nonEmptyString" minOccurs="0" maxOccurs="8"/>
</xs:sequence>
</xs:complexType>

<!-- ShowMessage -->


<xs:complexType name="showMessageType">
<xs:complexContent>
<xs:extension base="actionBaseType">
<xs:all>
<xs:element name="Title" type="nonEmptyString" />
<xs:element name="Body" type="nonEmptyString" />
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>

</xs:schema>
Task Scheduler Schema Elements
8/8/2022 • 2 minutes to read • Edit Online

The elements listed here are defined by the Task Scheduler schema. These elements are used when reading or
writing XML for a task.
The topics in this section include a description of the element; how it is defined in the XSD;, and information
about all related parents, children, and attributes.
Actions (taskType)
AllowHardTerminate (settingsType)
AllowStar tOnDemand (settingsType)
April (monthsType)
Arguments (execType)
Attachments (sendMailType)
August (monthsType)
Author (registrationInfoType)
Body (sendMailType)
Body (showMessageType)
BootTrigger (triggerGroup)
Bcc (sendMailType)
CalendarTrigger (triggerGroup)
Cc (sendMailType)
ClassId (comHandlerType)
ComHandler (actionGroup)
Command (execType)
Count (restar tType)
Data (comHandlerType)
Data (taskType)
Date (registrationInfoType)
Day (daysOfMonthType)
DaysInter val (dailyScheduleType)
DaysOfMonth (monthlyScheduleType)
DaysOfWeek (monthlyDayOfWeekScheduleType)
DaysOfWeek (weeklyScheduleType)
December (monthsType)
Delay (bootTriggerType)
Delay (eventTriggerType)
Delay (logonTriggerType)
Delay (registrationTriggerType)
Delay (sessionStateChangeTriggerType)
DeleteExpiredTaskAfter (settingsType)
Description (registrationInfoType)
DisallowStar tIfOnBatteries (settingsType)
DisallowStar tOnRemoteAppSession (settingsType)
DisplayName (principalType)
Documentation (registrationInfoType)
Duration (idleSettingsType)
Duration (repetitionType)
Enabled (settingsType)
Enabled (triggerBaseType)
EndBoundar y (triggerBaseType)
EventTrigger (triggerGroup)
Exec (actionGroup)
ExecutionTimeLimit (settingsType)
ExecutionTimeLimit (triggerBaseType)
Februar y (monthsType)
File (attachmentsType)
Friday (daysOfWeekType)
From (sendMailType)
GroupId (principalType)
HeaderFields (sendMailType)
HeaderField (headerFieldsType)
Hidden (settingsType)
IdleSettings (settingsType)
IdleTrigger (triggerGroup)
Id (networkSettingsType)
Inter val (repetitionType)
Inter val (restar tType)
Januar y (monthsType)
July (monthsType)
June (monthsType)
LogonTrigger (triggerGroup)
LogonType (principalType)
March (monthsType)
May (monthsType)
Monday (daysOfWeekType)
Months (monthlyDayOfWeekScheduleType)
Months (monthlyScheduleType)
MultipleInstancesPolicy (settingsType)
Name (headerFieldType)
Name (networkSettingsType)
November (monthsType)
October (monthsType)
Principal (principalsType)
Principals (taskType)
ProcessTokenSidType (principalType)
Priority (settingsType)
Privilege (requiredPrivilegesType)
RandomDelay (calendarTriggerType)
RandomDelay (timeTriggerType)
RegistrationInfo (taskType)
RegistrationTrigger (triggerGroup)
Repetition (triggerBaseType)
RequiredPrivileges (requiredPrivilegesType)
ReplyTo (sendMailType)
Restar tOnFailure (settingsType)
Restar tOnIdle (idleSettingsType)
RunLevel (principalType)
RunOnlyIfIdle (settingsType)
RunOnlyIfNetworkAvailable (settingsType)
Saturday (daysOfWeekType)
ScheduleByDay (calendarTriggerType)
ScheduleByMonthDayOfWeek (calendarTriggerType)
ScheduleByMonth (calendarTriggerType)
ScheduleByWeek (calendarTriggerType)
SecurityDescriptor (registrationInfoType)
SendEmail (actionGroup) Element
September (monthsType)
SessionStateChangeTrigger (triggerGroup)
Ser ver (sendMailType)
Settings (taskType)
ShowMessage (actionGroup)
Source (registrationInfoType)
Star tBoundar y (triggerBaseType)
Star tWhenAvailable (settingsType)
StateChange (sessionStateChangeTriggerType)
StopAtDurationEnd (repetitionType)
StopIfGoingOnBatteries (settingsType)
StopOnIdleEnd (idleSettingsType)
Subject (sendMailType)
Subscription (eventTriggerType)
Sunday (daysOfWeekType)
Task
Thursday (daysOfWeekType)
TimeTrigger (triggerGroup)
Title (showMessageType) Element
To (sendMailType)
Triggers (taskType)
Tuesday (daysOfWeekType)
URI (registrationInfoType)
UserId (logonTriggerType)
UserId (principalType)
UserId (sessionStateChangeTriggerType)
UseUnifiedSchedulingEngine (settingsType)
ValueQueries (eventTriggerType)
Value (headerFieldType)
Version (registrationInfoType)
WaitTimeout (idleSettingsType)
WakeToRun (settingsType)
Wednesday (daysOfWeekType)
Week (weeksType)
WeeksInter val (weeklyScheduleType)
Weeks (monthlyDayOfWeekScheduleType)
WorkingDirector y (execType)
Actions (taskType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the actions performed by the task.

<xs:element name="Actions"
type="actionsType"
/>

The Actions element is defined by the taskType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Task taskType Describes the task that is performed


by the Task Scheduler service.

Child elements
EL EM EN T TYPE DESC RIP T IO N

ComHandler comHandlerType Specifies an action that fires a handler.

Exec execType Specifies an action that executes a


command-line operation.

SendEmail sendEmailType Specifies an action that sends an email


message.

ShowMessage showMessageType Specifies an action that shows a


message box.

Attributes
NAME TYPE DESC RIP T IO N

Context Principal identifier of the user who is


the security context for the actions of
the task.

Remarks
The child elements listed previously (maximum 32) are defined by the actionGroup group. These elements can
be added in any order.
For C++ development, the actions of a task are defined in the IActionCollection interface.
For script development, the actions of a task are defined in the ActionCollection object.
Examples
For more information and a complete example of the XML for a task that contains a single execution action, see
Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
taskType
actionGroup
Task Scheduler Schema Elements
Task Scheduler
AllowHardTerminate (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task may be terminated using TerminateProcess.

<xs:element name="AllowHardTerminate"
type="boolean"
default="true"
minOccurs="0"
/>

The AllowHardTerminate element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings taskType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, see the AllowHardTerminate proper ty of ITaskSettings .
For script development, see TaskSettings.AllowHardTerminate .

Examples
For a complete example of the XML for a task that allows hard termination, see Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
AllowStartOnDemand (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task can be started using either the Run command or the Context menu.

<xs:element name="AllowStartOnDemand"
type="boolean"
minOccurs="0"
default="true"
/>

The AllowStar tOnDemand element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
When this element is set to True, the task can be started independently of when any triggers start the task.
For C++ development, see the AllowDemandStar t proper ty of ITaskSettings .
For script development, see TaskSettings.AllowDemandStar t .

Examples
For a complete example of the XML for a task that allows demand start, see Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
April (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in April.

<xs:element name="April">
<xs:complexType />
</xs:element>

The April element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly day-of-week schedule.

Examples
The following XML defines a months calendar that runs the task in April.

<Months>
<April/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Arguments (execType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the arguments associated with the command-line operation.

<xs:element name="Arguments"
type="string"
/>

The Arguments element is defined by the execType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Exec execType Specifies an action that executes a


command-line operation.

Remarks
For C++ development, see the Arguments proper ty of IExecAction .
For script development, see ExecAction.Arguments .

Examples
For a complete example of the XML for a task that uses an executable action, see Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Attachments (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains a list of attachments in the email message.

<xs:element name="Attachments"
type="attachmentsType"
/>

The Attachments element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Child elements
EL EM EN T TYPE DESC RIP T IO N

File nonEmptyString Specifies the path to a file that is sent


as an attachment in an email message.

Remarks
For C++ development, see Attachments Proper ty of IEmailAction .
For script development, see EmailAction.Attachments .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


August (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in August.

<xs:element name="August">
<xs:complexType />
</xs:element>

The August element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in August.

<Months>
<August/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Author (registrationInfoType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the author of the task.

<xs:element name="Author"
type="string"
minOccurs="0"
/>

The Author element is defined by the registrationInfoType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Remarks
For scripting development, the author of the task is specified using the RegistrationInfo.Author property.
For C++ development, the author of the task is specified using the IRegistrationInfo::Author property.

Examples
The following XML defines the author of a task.

<RegistrationInfo>
<Author></Author>
</RegistrationInfo>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Body (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the text in the body of the email message.

<xs:element name="Body"
type="string"
/>

The Body element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Remarks
For C++ development, see Body Proper ty of IEmailAction .
For script development, see EmailAction.Body .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Body (showMessageType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the text to display in the body of the message box.

<xs:element name="Body"
type="nonEmptyString"
/>

The Body element is defined by the showMessageType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ShowMessage (actionGroup) showMessageType Represents an action that shows a


message box.

Remarks
For C++ development, see MessageBody Proper ty of IShowMessageAction .
For script development, see ShowMessageAction.MessageBody .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


BootTrigger (triggerGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a trigger that starts a task when the system is booted.

<xs:element name="BootTrigger"
type="bootTriggerType"
/>

The BootTrigger element is defined by the bootTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Triggers triggersType Specifies the triggers that start the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay (bootTriggerType) duration Specifies the amount of time between


when the system is booted and when
the task is started.

Enabled (triggerBaseType) boolean Specifies that the trigger is enabled.

EndBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit duration Specifies the maximum amount of time


(triggerBaseType) in which the task can be started by the
trigger.

Repetition (triggerBaseType) repetitionType Specifies how often the task is run and
how long the repetition pattern is
repeated after the task is started.

Star tBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is activated.

Attributes
NAME TYPE DESC RIP T IO N

Id string The identifier of the trigger.


Remarks
For script development, a boot trigger is defined by the BootTrigger object.
For C++ development, a boot trigger is defined by the IBootTrigger object.

Examples
For a complete example of the XML for a task that specifies a boot trigger, see Boot Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Bcc (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the email addresses used on the Bcc line of an email message.

<xs:element name="Bcc"
type="string"
/>

The Bcc element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Remarks
For C++ development, see Bcc Proper ty of IEmailAction .
For script development, see EmailAction.Bcc .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


CalendarTrigger (triggerGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a daily, weekly, monthly, or a monthly day-of-the-week (DOW) trigger.

<xs:element name="CalendarTrigger"
type="calendarTriggerType"
/>

The CalendarTrigger element is defined by the calendarTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Triggers triggersType Specifies the triggers that start the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Enabled (triggerBaseType) boolean Specifies that the trigger is enabled.

EndBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit duration Specifies the maximum amount of time


(triggerBaseType) in which the task can be started by the
trigger.

Repetition (triggerBaseType) repetitionType Specifies how often the task is run and
how long the repetition pattern is
repeated after the task is started.

ScheduleByDay dailyScheduleType Specifies a daily schedule.


(calendarTriggerType)

ScheduleByMonth monthlyScheduleType Specifies a monthly schedule.


(calendarTriggerType)

ScheduleByMonthDayOfWeek monthlyDayOfWeekScheduleType Specifies a trigger that starts a job on


(calendarTriggerType) a monthly day-of-week schedule.

ScheduleByWeek weeklyScheduleType Specifies a weekly schedule.


(calendarTriggerType)
EL EM EN T TYPE DESC RIP T IO N

Star tBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is activated. This element is
required.

Attributes
NAME TYPE DESC RIP T IO N

Id ID The identifier of the trigger.

Remarks
The Star tBoundar y element is a required element for time and calendar triggers (TimeTrigger and
CalendarTrigger ).
The child elements listed above are defined by the triggerBaseType and calendarTriggerType complex
element types.
For script development, calendar triggers are specified using one of the following objects.
DailyTrigger
WeeklyTrigger
MonthlyTrigger
MonthlyDOWTrigger
For C++ development, calendar triggers are specified using one of the following interfaces.
IDailyTrigger
IWeeklyTrigger
IMonthlyTrigger
IMonthlyDOWTrigger

Examples
For a complete example of the XML for a task that specifies a calendar trigger, see Daily Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Cc (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the email addresses used on the Cc line of an email message.

<xs:element name="Cc"
type="string"
/>

The Cc element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Remarks
For C++ development, see Cc Proper ty of IEmailAction .
For script development, see EmailAction.Cc .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


ClassId (comHandlerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the identifier of the handler class.

<xs:element name="ClassId"
type="guidType"
/>

The ClassId element is defined by the comHandlerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ComHandler comHandlerType Specifies an action that fires a handler.

Remarks
Applications define the class identifier using the ClassId property of the IComHandlerAction interface.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
ComHandler (actionGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies an action that fires a handler.

<xs:element name="ComHandler"
type="comHandlerType"
/>

The ComHandler element is defined by the actionGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Actions actionsType Contains the actions performed by the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

ClassId guidType Specifies the identifier of the handler


class.

Data dataType Specifies additional data associated


with the handler.

Remarks
Applications define a COM handler action using the IComHandlerAction interface.
Attributes
The following attribute is defined by the actionBaseType complex type.
ID: Identifier of the action performed by the task.

Examples
The following XML defines a COM handler action.

<Actions>
<ComHandler>
<ClassId></ClassId>
<Data></Data>
</ComHandler>
</Actions>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Command (execType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the executable file or document to be run.

<xs:element name="Command"
type="pathType"
/>

The Command element is defined by the execType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Exec execType Specifies an action that executes a


command-line operation.

Remarks
For C++ development, see the Arguments proper ty of IExecAction .
For script development, see ExecAction.Arguments .

Examples
For a complete example of the XML for a task that uses an executable action, see Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Count (restartType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the number of times that the Task Scheduler will attempt to restart the task.

<xs:element name="Count">
<xs:simpleType>
<xs:restriction
base="unsignedByte"
>
<xs:minInclusive
value="1"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The element is defined by the restar tType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Restar tOnFailure restar tType Specifies that the Task Scheduler will
attempt to restart the task if the task
fails for any reason.

Remarks
If this element is specified, the Inter val element must also be specified to tell the Task Scheduler how long to
attempt to restart the task.
For C++ development, see Restar tCount Proper ty of ITaskSettings .
For script development, see TaskSettings.Restar tCount .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Data (comHandlerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies additional data associated with the handler.

<xs:element name="Data"
type="dataType"
/>

The Data element is defined by the comHandlerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ComHandler comHandlerType Specifies an action that fires a handler.

Remarks
Applications define the handler data using the Data property of the IComHandlerAction interface.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Data (taskType) Element
8/8/2022 • 2 minutes to read • Edit Online

Defines addition data that is associated with the task, but is otherwise unused by the Task Scheduler service.

<xs:element name="Data"
type="dataType"
/>

The Data element is defined by the taskType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Task taskType Defines the task that is performed by


the Task Scheduler service.

Remarks
As an example of this type of data, the Performance Logs and Alerts service uses this property as a storage
container for the perf counter query associated with a task.
For C++ development, the data of a task is specified using the Data proper ty of ITaskDefinition .
In scripting development, the data of a task is specified using the TaskDefinition.Data property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Date (registrationInfoType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the date and time when the task is registered.

<xs:element name="Date"
type="dateTime"
minOccurs="0"
/>

The Date element is defined by the registrationInfoType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Remarks
For scripting development, the registration date of a task is specified using the RegistrationInfo.Date
property.
For C++ development, the registration date of a task is specified using the IRegistrationInfo::Date property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Day (daysOfMonthType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a day of the month during which the task runs.

<xs:element name="Day"
type="dayOfMonthType"
/>

The Day element is defined by the daysOfMonthType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

DaysOfMonth daysOfMonthType Specifies the days of the month during


which the task runs.

Examples
The following XML defines the days portion of a monthly calendar that runs the task on the 1st and 15th day of
the month.

<DaysOfMonth>
<Day>1</Day>
<Day>15</Day>
</DaysOfMonth>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
DaysInterval (dailyScheduleType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the interval between the days in the schedule.

<xs:element name="DaysInterval"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="unsignedInt"
>
<xs:minInclusive
value="1"
/>
<xs:maxInclusive
value="365"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The element is defined by the dailyScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ScheduleByDay dailyScheduleType Specifies a daily schedule.

Remarks
For script development, the days interval for a daily trigger is specified by the DailyTrigger.DaysInter val
property.
For C++ development, the days interval for a daily trigger is specified by the IDailyTrigger ::DaysInter val
property.

Examples
The following XML defines a daily calendar trigger that starts the task every day.

<CalendarTrigger>
<StartBoundary>2005-01-01T00:00:00</StartBoundary>
<EndBounadry>2007-01-01T00:00:00</EndBoundary>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>

For a complete example of the XML for a task that specifies a daily schedule, see Daily Trigger Example (XML).
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
DaysOfMonth (monthlyScheduleType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the days of the month during which the task runs.

<xs:element name="DaysOfMonth"
type="daysOfMonthType"
/>

The DaysOfMonth element is defined by the monthlyScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ScheduleByMonth monthlyDayOfWeekScheduleType Specifies a trigger that starts a job for


a monthly day-of-week schedule.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Day dayOfMonthType Specifies a day of the month during


which the task runs.

Remarks
For script development, the days of the month for the schedule are specified using the
MonthlyTrigger.DaysOfMonth property.
For C++ development, the days of the month for the schedule are specified using the
IMonthlyTrigger ::DaysOfMonth property.
The child element must be repeated for each day of the month the task is to run.

Examples
The following XML defines a monthly calendar trigger that starts a task (at 8 AM) on the 1st day of every month.
<CalendarTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBoundary>2007-01-01T00:00:00</EndBoundary>
<ScheduleByMonth>
<DaysOfMonth>
<Day>1</Day>
</DaysOfMonth>
<Months>
<January/>
<February/>
<March/>
<April/>
<May/>
<June/>
<July/>
<August/>
<September/>
<October/>
<November/>
<December/>
</Months>
</ScheduleByMonth>
</CalendarTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
DaysOfWeek (monthlyDayOfWeekScheduleType)
Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the days of the week in which the task runs.

<xs:element name="DaysOfWeek"
type="daysOfWeekType"
/>

The DaysOfWeek element is defined by the monthlyDayOfWeekScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ScheduleByMonthDayOfWeek monthlyDayOfWeekScheduleType Specifies a trigger that starts a job for


a monthly day-of-week schedule.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Friday Specifies that the task runs on Friday.

Monday Specifies that the task runs on


Monday.

Saturday Specifies that the task runs on


Saturday.

Sunday Specifies that the task runs on Sunday.

Thursday Specifies that the task runs on


Thursday.

Tuesday Specifies that the task runs on Tuesday.

Wednesday Specifies that the task runs on


Wednesday.

Remarks
For scripting development, the days of the week for a monthly day-of-week calendar are specified using the
MonthlyDOWTrigger.DaysOfWeek property.
For C++ development, the days of the week for a monthly day-of-week calendar are specified using the
IMonthlyDOWTrigger ::DaysOfWeek property.
The child elements above are defined by the daysOfWeekType complex type.

Examples
The following XML defines a monthly day-of-week calendar that starts the task on Monday of the first week for
each month of the year.

<ScheduleByMonthDayOfWeek>
<Weeks>
<Week>1</Week>
</Weeks>
<DaysOfWeek>
<Monday/>
</DaysOfWeek>
<Months>
<January/>
<February/>
<March/>
<April/>
<May/>
<June/>
<July/>
<August/>
<September/>
<October/>
<November/>
<December/>
<Months>
</ScheduleByMonthDayOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
DaysOfWeek (weeklyScheduleType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the days of the week in which the task runs.

<xs:element name="DaysOfWeek"
type="daysOfWeekType"
/>

The DaysOfWeek element is defined by the weeklyScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ScheduleByWeek weeklyScheduleType Specifies a weekly schedule.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Friday Specifies that the task runs on Friday.

Monday Specifies that the task runs on


Monday.

Saturday Specifies that the task runs on


Saturday.

Sunday Specifies that the task runs on Sunday.

Thursday Specifies that the task runs on


Thursday.

Tuesday Specifies that the task runs on Tuesday.

Wednesday Specifies that the task runs on


Wednesday.

Remarks
The previous child elements are defined by the daysOfWeekType complex type.
For scripting development, the weekly interval is specified using the WeeklyTrigger.WeeksInter val property.
For C++ development, the weekly interval is specified using the IWeeklyTrigger ::WeeksInter val property.

Examples
The following XML defines a daily calendar trigger that starts a task Monday through Friday ( at 8:00 AM) every
week.

<CalendarTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T00:00:00</EndBoundary>
<ScheduleByWeek>
<WeeksInterval>1</WeeksInterval>
<DaysOfWeek>
<Monday/>
<Tuesday/>
<Wednesday/>
<Thurday/>
<Friday/>
</DaysOfWeek>
</ScheduleByWeek>
</CalendarTrigger>

For a complete example of the XML for a task that uses a weekly trigger, see Weekly Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Deadline Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies when the Task scheduler must to start the task during emergency Automatic maintenance, if it failed to
complete during regular Automatic maintenance.
The format for this string is PnYnMnDTnHnMnS , where nY is the number of years, nM is the number of months,
nD is the number of days, T is the date/time separator, nH is the number of hours, nM is the number of minutes,
and nS is the number of seconds (for example, "PT5M" specifies 5 minutes and "P1M4DT2H5M" specifies one
month, four days, two hours, and five minutes). The minimum value is one minute. For more information about
the duration type, see XML Schema Part 2: Datatypes Second Edition. Minimum Deadline a task can use is 1 day.
The value of the Deadline element should be greater than the value of the Period element. If the deadline is
not specified the task will not be started during emergency Automatic maintenance.

<xs:element name="Deadline"
maxOccurs="1"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="P1D"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The Deadline element is defined by the maintenanceSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

MaintenanceSettings maintenanceSettingsType Specifies the task settings the Task


(maintenanceSettingsType) scheduler will use to start task during
Automatic maintenance.

Remarks
For C++ programming, this idle setting is specified using the IMaintenanceSettings::Deadline property.

Examples
The following XML defines a months calendar that runs the task in March.

<MaintenanceSettings>
<Period>P5D</Period>
<Deadline>P15D</Deadline>
</MaintenanceSettings>
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 8 [desktop apps only]

Minimum supported server Windows Server 2012 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
December (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in December.

<xs:element name="December">
<xs:complexType />
</xs:element>

The December element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in December.

<Months>
<December/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Delay (bootTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the amount of time between when the system is booted and when the task is started. The format for
this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the
number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS
is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four
days, two hours, and five minutes). For more information about the duration type, see
https://go.microsoft.com/fwlink/p/?linkid=106886.

<xs:element name="Delay"
type="duration"
/>

The Delay element is defined by the bootTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

BootTrigger bootTriggerType Specifies a trigger that starts a task


when the system is booted.

Remarks
For script development, the event trigger delay is specified by the BootTrigger.Delay property.
For C++ development, the event trigger delay is specified by the IBootTrigger ::Delay property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Delay (eventTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the amount of time between when the event occurs and when the task is started. The format for this
string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of
days, 'T' is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the
number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days,
two hours, and five minutes). For more information about the duration type, see
https://go.microsoft.com/fwlink/p/?linkid=106886.

<xs:element name="Delay"
type="duration"
/>

The Delay element is defined by the eventTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

EventTrigger eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

Remarks
For script development, the event trigger delay is specified by the EventTrigger.Delay property.
For C++ development, the event trigger delay is specified by the IEventTrigger ::Delay property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Delay (logonTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Amount of time between when the user logs on and when the task is started. The format for this string is
PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days, 'T'
is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of
seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours,
and five minutes). For more information about the duration type, see https://go.microsoft.com/fwlink/p/?
linkid=106886.

<xs:element name="Delay"
type="duration"
/>

The Delay element is defined by the logonTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

LogonTrigger logonTriggerType Specifies a trigger that starts a task


when a user logs on.

Remarks
For scripting development, the logon trigger delay is specified using the LogonTrigger.Delay property.
For C++ development, the user identifier for the logon trigger is specified using the ILogonTrigger ::Delay
property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Delay (registrationTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the amount of time between when the task is registered and when the task is started. The format for
this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the
number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS
is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four
days, two hours, and five minutes). For more information about the duration type, see
https://go.microsoft.com/fwlink/p/?linkid=106886.

<xs:element name="Delay"
type="duration"
/>

The Delay element is defined by the registrationTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationTrigger registrationTriggerType Specifies a trigger that starts a task


when the task is registered.

Remarks
For scripting development, the registration trigger delay is specified using the RegistrationTrigger.Delay
property.
For C++ development, the registration trigger delay is specified using the IRegistrationTrigger ::Delay
property.

Examples
The following XML defines a registration trigger delay that allows a 5 minute delay between when the task is
registered and when the task is started.

<BootTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T08:00:00</EndBoundary>
<Enabled></Enabled>
<Repetition></Repetition>
<ExecutionTimeLimit></ExecutionTimeLimit>
<Delay>PT5M<Delay>
</BootTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Delay (sessionStateChangeTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains a value that indicates the delay length for a task start time, when a Terminal Server session state
change is detected. The format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the
number of months, nD is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the
number of minutes, and nS is the number of seconds (for example, PT5M specifies 5 minutes and
P1M4DT2H5M specifies one month, four days, two hours, and five minutes). For more information about the
duration type, see https://go.microsoft.com/fwlink/p/?linkid=106886.

<xs:element name="Delay"
type="duration"
/>

The Delay element is defined by the sessionStateChangeTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SessionStateChangeTrigger sessionStateChangeTriggerType Specifies a trigger that starts a task


when a Terminal Server session
changes state.

Remarks
For scripting development, the session state change trigger delay is specified using the
SessionStateChangeTrigger.Delay property.
For C++ development, the session state change trigger delay is specified using the Delay proper ty of
ISessionStateChangeTrigger .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


DeleteExpiredTaskAfter (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the amount of time that the Task Scheduler will wait before deleting the task after it expires. If no value
is specified for this element, then the Task Scheduler service will not delete the task. The format for this string is
PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days, 'T'
is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of
seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours,
and five minutes). For more information about the duration type, see https://go.microsoft.com/fwlink/p/?
linkid=106886.

<xs:element name="DeleteExpiredTaskAfter"
type="duration"
minOccurs="0"
default="PT0S"
/>

The DeleteExpiredTaskAfter element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, see DeleteExpiredTaskAfter Proper ty of ITaskSettings .
For script development, see TaskSettings.DeleteExpiredTaskAfter .

Examples
The following XML defines a settings element that deletes an expired task after one week.

<Settings>
<DeleteExpiredTaskAfter>PT7D</DeleteExpiredTaskAfter>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


See also
Task Scheduler Schema Elements
Description (registrationInfoType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the description of the task.

<xs:element name="Description"
type="string"
minOccurs="0"
/>

The Description element is defined by the registrationInfoType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Remarks
For scripting development, the description of a task is specified using the RegistrationInfo.Description
property.
For C++ development, the description of a task is specified using the IRegistrationInfo::Description property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
DisallowStartIfOnBatteries (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task will not be started if the computer is running on batteries.

<xs:element name="DisallowStartIfOnBatteries"
type="boolean"
/>

The DisallowStar tIfOnBatteries element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
The default setting for this element is True.
For scripting development, this information is accessed through the
TaskSettings.DisallowStar tIfOnBatteries property.
For C++ development, this information is accessed through the ITaskSettings::DisallowStar tIfOnBatteries
property.

Examples
The following XML defines a settings element that does not allow the task to run if the computer is running on
batteries.

<Settings>
<DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
DisallowStartOnRemoteAppSession (settingsType)
Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task will not be started if triggered to run in a Remote Applications Integrated Locally (RAIL)
session.

<xs:element name="DisallowStartOnRemoteAppSession"
type="boolean"
default="false"
minOccurs="0"
/>

The DisallowStar tOnRemoteAppSession element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
The default setting for this element is False.
For C++ development, this information is accessed through the
ITaskSettings2::DisallowStar tOnRemoteAppSession property.

Examples
The following XML defines a settings element that does not allow the task to start if the task is triggered to run
in a RAIL session.

<Settings>
<DisallowStartOnRemoteAppSession>true</DisallowStartOnRemoteAppSession>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]

See also
Task Scheduler Schema Elements
DisplayName (principalType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the name of the principal that is displayed in the Task Scheduler UI.

<xs:element name="DisplayName"
type="string"
/>

The DisplayName element is defined by the principalType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Principal principalType Specifies the security credentials for a


principal.

Remarks
For scripting development, the display name of the principal is specified using the Principal.DisplayName
property.
For C++ development, the display name of the principal is specified using the IPrincipal::DisplayName
property.

Examples
The following XML defines a using a group identifier and a display name.

<Principal>
<GroupId></GroupId>
<DisplayName></DisplayName>
</Principal>

The following XML defines a principal using a user identifier and a display name.

<Principal>
<UserId></UserId>
<LogonType></LogonType>
<DisplayName></DisplayName>
</Principal>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]


REQ UIREM EN T VA L UE

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
Documentation (registrationInfoType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies any additional documentation for the task.

<xs:element name="Documentation"
type="string"
minOccurs="0"
/>

The Documentation element is defined by the registrationInfoType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Remarks
For scripting applications, additional task documentation is specified using the using the
RegistrationInfo.Documentation property.
For C++ applications, additional task documentation is specified using the using the
IRegistrationInfo::Documentation property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Duration (idleSettingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies how long the computer must be in an idle state before the task is run. The format for this string is
PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days, 'T'
is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of
seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours,
and five minutes). The minimum value is one minute. For more information about the duration type, see
https://go.microsoft.com/fwlink/p/?linkid=106886.

<xs:element name="Duration"
default="PT10M"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The element is defined by the idleSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

IdleSettings idleSettingsType Specifies how the Task Scheduler


performs tasks when the computer is
in an idle state.

Remarks
For script programming, this idle setting is specified using the IdleSettings.IdleDuration property.
For C++ programming, this idle setting is specified using the IIdleSettings::IdleDuration property.

Examples
The following XML defines an idle setting that allows 5 minutes for the task to start.

<IdleSettings>
<Duration>PT5M</Duration>
</IdleSettings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Duration (repetitionType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies how long the pattern is repeated. The format for this string is PnYnMnDTnHnMnS, where nY is the
number of years, nM is the number of months, nD is the number of days, 'T' is the date/time separator, nH is the
number of hours, nM is the number of minutes, and nS is the number of seconds (for example, PT5M specifies 5
minutes and P1M4DT2H5M specifies one month, four days, two hours, and five minutes). For more information
about the duration type, see https://go.microsoft.com/fwlink/p/?linkid=106886. If no value is specified for the
duration, then the pattern is repeated indefinitely. The minimum value is one minute.

<xs:element name="Duration"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The element is defined by the repetitionType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Repetition repetitionType Specifies how often the task is run and


how long the repetition pattern is
repeated after the task is started.

Remarks
For scripting applications, the duration of the pattern is specified using the RepetitionPattern.Duration
property.
For C++ applications, the duration of the pattern is specified using the IRepetitionPattern::Duration property.

Examples
The following XML defines a repetition pattern for a trigger.

<Repetition>
<Interval></Interval>
<Duration></Duration>
<StopAtDurationEnd>true</StopAtDirationEnd>
</Repetition>
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Enabled (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task is enabled. The task can be performed only when this setting is True.

<xs:element name="Enabled"
type="boolean"
default="true"
minOccurs="1"
/>

The Enabled element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, see Enabled Proper ty of ITaskSettings .
For script development, see TaskSettings.Enabled .

Examples
For a complete example of the XML for a task that is enabled, see Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Enabled (triggerBaseType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the trigger is enabled.

<xs:element name="Enabled"
type="boolean"
/>

The Enabled element is defined by the triggerBaseType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

BootTrigger bootTriggerType Specifies a trigger that starts a task


when the system is booted.

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

EventTrigger eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

IdleTrigger idleTriggerType Specifies a trigger that starts a task


when the computer goes into an idle
state.

LogonTrigger logonTriggerType Specifies a trigger that starts a task


when a user logs on.

RegistrationTrigger registrationTriggerType Specifies a trigger that starts a task


when the task is registered.

TimeTrigger timeTriggerType Specifies a trigger that starts a task


when the trigger is activated.

Remarks
For scripting development, this information is accessed through the Trigger.Enabled property that is inherited
by the all trigger objects.
For C++ development, this information is accessed through the ITrigger ::Enabled property that is inherited by
the all trigger interfaces.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
EndBoundary (triggerBaseType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the date and time when the trigger is deactivated. The trigger cannot start the task after it is
deactivated.

<xs:element name="EndBoundary"
type="dateTime"
/>

The EndBoundar y element is defined by the triggerBaseType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

BootTrigger bootTriggerType Specifies a trigger that starts a task


when the system is booted.

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

EventTrigger eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

IdleTrigger idleTriggerType Specifies a trigger that starts a task


when the computer goes into an idle
state.

LogonTrigger logonTriggerType Specifies a trigger that starts a task


when a user logs on.

RegistrationTrigger registrationTriggerType Specifies a trigger that starts a task


when the task is registered.

TimeTrigger timeTriggerType Specifies a trigger that starts a task


when the trigger is activated.

Remarks
For scripting development, the end boundary is specified using the Trigger.EndBoundar y property that is
inherited by the all trigger objects.
For C++ development, the end boundary is specified using the ITrigger ::EndBoundar y property that is
inherited by the all trigger interfaces.

Examples
The following XML defines a boot trigger element that defines an end boundary of January 1, 2007: 8:00 AM.
<BootTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T08:00:00</EndBoundary>
<Enabled>true</Enabled>
<Repetition></Repetition>
<ExecutionTimeLimit></ExecutionTimeLimit>
<Delay><Delay>
</BootTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
EventTrigger (triggerGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a trigger that starts a task when a system event occurs.

<xs:element name="EventTrigger"
type="eventTriggerType"
/>

The EventTrigger element is defined by the triggerGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Triggers triggersType Specifies the triggers that start the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay (eventTriggerType) duration Specifies the amount of time between


when the event occurs and when the
task is started.

Enabled (triggerBaseType) boolean Specifies that the trigger is enabled.

EndBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

Repetition (triggerBaseType) repetitionType Specifies how often the task is run and
how long the repetition pattern is
repeated after the task is started.

Star tBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is activated.

Subscription (eventTriggerType) string Specifies the XPath query that


identifies the event that fires the
trigger.

Attributes
NAME TYPE DESC RIP T IO N

Id ID Identifier of the trigger.


Remarks
A maximum of 500 tasks with event subscriptions can be created. An event subscription that queries for a
variety of events can be used to trigger a task that uses the same action in response to the events being logged.
For script development, an event trigger is defined by the EventTrigger object.
For C++ development, an event trigger is defined by the IEventTrigger interface.

Examples
For a complete example of the XML for a task that uses an event trigger, see Event Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
Exclusive Element
8/8/2022 • 2 minutes to read • Edit Online

Indicates whether the Task scheduler must start the task during the Automatic maintenance in exclusive mode.
The exclusivity is guaranteed only between other maintenance tasks and doesn't grant any ordering priority of
the task. If exclusivity is not specified, the task is started in parallel with other maintenance tasks.

<xs:element name="Exclusive"
type="xsd:boolean"
maxOccurs="1"
minOccurs="0"
/>

The Exclusive element is defined by the maintenanceSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

MaintenanceSettings maintenanceSettingsType Specifies the task settings the Task


(maintenanceSettingsType) scheduler will use to start task during
Automatic maintenance.

Remarks
For C++ programming, this idle setting is specified using the IMaintenanceSettings::Exclusive property.

Examples
The following XML defines maintenance task with deadline requirement set to 15 days.

<MaintenanceSettings>
<Period>P5D</Period>
<Deadline>P15D</Deadline>
<Exclusive>true</Exclusive>
</MaintenanceSettings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 8 [desktop apps only]

Minimum supported server Windows Server 2012 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Exec (actionGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies an action that executes a command-line operation.

<xs:element name="Exec"
type="execType"
/>

The Exec element is defined by the actionGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Actions actionsType Contains the actions performed by the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Arguments string Specifies the arguments associated


with the command-line operation.

Command string Specifies the executable file or


document to be run.

WorkingDirector y string Specifies the directory where either the


executable or those files used by the
executable exists.

Attributes
NAME TYPE DESC RIP T IO N

id string The identifier of the action performed


by the task.

Remarks
The child elements listed above are defined by the execType complex type.
For script development, an execution action is defined by the ExecAction object.
For C++ development, an execution action is defined by the IExecAction interface.
If environment variables are used in the Command , Arguments , or WorkingDirector y elements, then the
values of the environment variables are cached and used when the Taskeng.exe (the task engine) is launched.
Changes to the environment variables that occur after the task engine is launched will not be used by the task
engine.

Examples
For a complete example of the XML for a task that uses an event trigger, see Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
ExecutionTimeLimit (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Amount of time allowed to complete the task.The format for this string is PnYnMnDTnHnMnS, where nY is the
number of years, nM is the number of months, nD is the number of days, 'T' is the date/time separator, nH is the
number of hours, nM is the number of minutes, and nS is the number of seconds (for example, PT5M specifies 5
minutes and P1M4DT2H5M specifies one month, four days, two hours, and five minutes). For more information
about the duration type, see https://go.microsoft.com/fwlink/p/?linkid=106886. A value of PT0S will enable the
task to run indefinitely.

<xs:element name="ExecutionTimeLimit"
type="duration"
minOccurs="0"
/>

The ExecutionTimeLimit element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, see ExecutionTimeLimit Proper ty of ITaskSettings .
For script development, see TaskSettings.ExecutionTimeLimit .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
ExecutionTimeLimit (triggerBaseType) Element
8/8/2022 • 2 minutes to read • Edit Online

The maximum amount of time that the task launched by the trigger is allowed to run. The format for this string
is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days,
'T' is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of
seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours,
and five minutes). For more information about the duration type, see https://go.microsoft.com/fwlink/p/?
linkid=106886.

<xs:element name="ExecutionTimeLimit"
type="duration"
/>

The ExecutionTimeLimit element is defined by the triggerBaseType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

BootTrigger bootTriggerType Specifies a trigger that starts a task


when the system is booted.

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

EventTrigger eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

IdleTrigger idleTriggerType Specifies a trigger that starts a task


when the computer goes into an idle
state.

LogonTrigger logonTriggerType Specifies a trigger that starts a task


when a user logs on.

RegistrationTrigger registrationTriggerType Specifies a trigger that starts a task


when the task is registered.

TimeTrigger timeTriggerType Specifies a trigger that starts a task


when the trigger is activated.

Remarks
For scripting development, the execution time limit is specified using the Trigger.ExecutionTimeLimit
property that is inherited by the all trigger objects.
For C++ development, the execution time limit is specified using the ITrigger ::ExecutionTimeLimit property
that is inherited by the all trigger interfaces.
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
February (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in February.

<xs:element name="February">
<xs:complexType />
</xs:element>

The Februar y element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in February.

<Months>
<February/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
File (attachmentsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the path to a file sent as an attachment in an email message.

<xs:element name="File"
type="nonEmptyString"
/>

The File element is defined by the attachmentsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Attachments (sendEmailType) attachmentsType Contains a list of attachments in the


email message.

Remarks
For C++ development, see Attachments Proper ty of IEmailAction .
For script development, see EmailAction.Attachments .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Friday (daysOfWeekType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs on Friday.

<xs:element name="Friday">
<xs:complexType />
</xs:element>

The Friday element is defined by the daysOfWeekType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(monthlyDayOfWeekScheduleTyp the task runs for a monthly day-of-
e) week schedule.

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(weeklyScheduleType) the task runs for a weekly schedule.

Examples
The following XML defines a day of week calendar that starts a task on Friday.

<DaysOfWeek>
<Friday/>
</DaysOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
From (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the email address of the email sender.

<xs:element name="From"
type="string"
/>

The From element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Remarks
For C++ development, see From Proper ty of IEmailAction .
For script development, see EmailAction.From .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


GroupId (principalType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the identifier of the user group required to run those tasks associated with the principal.

<xs:element name="GroupId"
type="nonEmptyString"
/>

The GroupId element is defined by the principalType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Principal principalType Specifies the security credentials for a


principal.

Remarks
You cannot specify a group identifier and a user identifier at the same time. Specify either the UserId or
GroupId elements, but not both.
For script development, the group identifier of the principal is specified using the Principal.GroupId property.
For C++ development, the group identifier of the principal is specified using the IPrincipal::GroupId property.

Examples
For a complete example of the XML for a task that uses this element, see Logon Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
HeaderFields (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the header fields and their values used in the header of the email message.

<xs:element name="HeaderFields"
type="headerFieldsType"
/>

The HeaderFields element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Child elements
EL EM EN T TYPE DESC RIP T IO N

HeaderField headerFieldType Contains a field for a header in an


email message.

Remarks
For C++ development, see HeaderFields Proper ty of IEmailAction .
For script development, see EmailAction.HeaderFields .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


HeaderField (headerFieldsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains a field for a header in an email message.

<xs:element name="HeaderField"
type="headerFieldType"
/>

The HeaderField element is defined by the headerFieldsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

HeaderFields headerFieldsType Specifies the header fields and their


values used in the header of the email
message.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Name nonEmptyString Specifies the name of the header field


in an email message.

Value string Specifies the value of a header field in


an email message.

Remarks
For C++ development, see HeaderFields Proper ty of IEmailAction .
For script development, see EmailAction.HeaderFields .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Hidden (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task will not be visible in the UI by default. However, administrators can override this setting
through the use of a "master switch" that makes all tasks visible in the UI.

<xs:element name="Hidden"
type="boolean"
default="false"
minOccurs="0"
/>

The Hidden element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that Task


Scheduler uses to perform the task.

Remarks
For C++ development, see Hidden Proper ty of ITaskSettings .
For script development, see TaskSettings.Hidden .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
IdleSettings (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies how the Task Scheduler performs tasks when the computer is in an idle state. For information about
idle conditions, see Task Idle Conditions.

<xs:element name="IdleSettings"
type="idleSettingsType"
minOccurs="0"
/>

The IdleSettings element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Child elements
NOTE
The Duration and WaitTimeout settings are deprecated. They're still present in the Task Scheduler user interface, and their
interface methods may still return valid values, but they're no longer used.

EL EM EN T TYPE DESC RIP T IO N

Restar tOnIdle boolean Specifies whether the task is restarted


when the computer cycles into an idle
condition more than once.

StopOnIdleEnd boolean Specifies that the Task Scheduler will


stop the task if the idle condition ends
before the task is completed.

Deprecated : Duration duration Specifies how long the computer must


be in an idle state before the task is
run.

Deprecated : WaitTimeout duration Specifies the amount of time that the


Task Scheduler will wait for an idle
condition to occur.

Remarks
For script development, idle settings are specified using the TaskSettings.IdleSettings property.
For C++ development, idle settings are specified using the ITaskSettings::IdleSettings property.
Examples
The following XML defines a settings element that allows Task Scheduler to wait 24 hours for an idle condition
and then allows only 10 minutes {IdleDuration) to initiate the task.

<Settings>
<IdleSettings>
<StopOnIdleEnd>false</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
<!-- WaitTimeout and Duration have been deprecated -->
<Duration>PT5M</Duration>
<WaitTimeout>PT24H</WaitTimeout>
</IdleSettings>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
IdleTrigger (triggerGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a trigger that starts a task when the computer goes into an idle state. For information about idle
conditions, see Task Idle Conditions.

<xs:element name="IdleTrigger"
type="idleTriggerType"
/>

The IdleTrigger element is defined by the triggerGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Triggers triggersType Specifies the triggers that start the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Enabled (triggerBaseType) boolean Specifies that the trigger is enabled.

EndBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit duration Specifies the maximum amount of time


(triggerBaseType) in which the task can be started by the
trigger.

Repetition (triggerBaseType) repetitionType Specifies how often the task is run and
how long the repetition pattern is
repeated after the task is started.

Star tBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is activated.

Attributes
NAME TYPE DESC RIP T IO N

Id string The identifier of the trigger.

Remarks
For scripting development, an idle trigger is specified using the IdleTrigger object.
For C++ development, an idle trigger is specified using the IIdleTrigger interface.
The child elements listed above are defined by the triggerBaseType complex element types. These elements
must be added in the sequence shown below.
Star tBoundar y (triggerBaseType)
EndBoundar y (triggerBaseType)
Enabled (triggerBaseType)
Repetition (triggerBaseType)
ExecutionTimeLimit (triggerBaseType)

Examples
The following XML defines an idle trigger.

<IdleTrigger>
<StartBoundary>2005-01-01T00:08:00</StartBoundary>
<EndBounadry>2007-01-01T00:08:00</EndBoundary>
<Enabled></Enabled>
<Repetition></Repetition>
<ExecutionTimeLimit></ExecutionTimeLimit>
</IdleTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Id (networkSettingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains a GUID value that identifies a network profile.

<xs:element name="Id"
type="guidType"
minOccurs="0"
/>

The Id element is defined by the networkSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

NetworkSettings (settingsType) networkSettingsType Contains the settings that the Task


Scheduler service uses to obtain a
network profile. The Task Scheduler
service checks the availability of this
network when the
RunOnlyIfNetworkAvailable
element is set to True .

Remarks
For C++ development, see Id Proper ty of INetworkSettings .
For script development, see NetworkSettings.Id .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Interval (repetitionType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the amount of time between each restart of the task. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S (for example, "PT5M" is 5 minutes, "PT1H" is 1 hour, and "PT20M" is 20
minutes). The maximum time allowed is 31 days, and the minimum time allowed is 1 minute.

<xs:element name="Interval">
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
<xs:maxInclusive
value="P31D"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The element is defined by the repetitionType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Repetition repetitionType Specifies how often the task is run and


how long the repetition pattern is
repeated after the task is started.

Remarks
For scripting development, the interval of the repetition pattern is specified using the
RepetitionPattern.Inter val property.
For C++ development, the interval of the repetition pattern is specified using the IRepetitionPattern::Inter val
property.

Examples
For a complete example of the XML for a task that uses a repetition interval, see Daily Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


See also
Task Scheduler Schema Elements
Task Scheduler
Interval (restartType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies how long the Task Scheduler will attempt to restart the task. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S (for example, "PT5M" is 5 minutes, "PT1H" is 1 hour, and "PT20M" is 20
minutes). The maximum time allowed is 31 days, and the minimum time allowed is 1 minute.

<xs:element name="Interval">
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
<xs:maxInclusive
value="P31D"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The element is defined by the restar tType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Restar tOnFailure restar tType Specifies that the Task Scheduler will
attempt to restart the task if the task
fails for any reason.

Remarks
If this element is specified, the Count element must also be specified to tell the Task Scheduler how many times
it should try to restart the task.
For C++ development, see Restar tInter val Proper ty of ITaskSettings .
For script development, see TaskSettings.Restar tInter val .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
January (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in January.

<xs:element name="January">
<xs:complexType />
</xs:element>

The Januar y element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in January.

<Months>
<January/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
July (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in July.

<xs:element name="July">
<xs:complexType />
</xs:element>

The July element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in July.

<Months>
<July/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
June (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in June.

<xs:element name="June">
<xs:complexType />
</xs:element>

The June element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in June.

<Months>
<June/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
LogonTrigger (triggerGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a trigger that starts a task when a user logs on.

<xs:element name="LogonTrigger"
type="logonTriggerType"
/>

The LogonTrigger element is defined by the triggerGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Triggers triggersType Specifies the triggers that start the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay (logonTriggerType) duration Amount of time between when the


user logs on and when the task is
started.

Enabled (triggerBaseType) boolean Specifies that the trigger is enabled.

EndBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit duration Specifies the maximum amount of time


(triggerBaseType) in which the task can be started by the
trigger.

Repetition (triggerBaseType) repetitionType Specifies how often the task is run and
how long the repetition pattern is
repeated after the task is started.

Star tBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is activated.

UserId (logonTriggerType) string Identifier of the user. The task is


started when this user logs onto the
computer.

Remarks
For scripting development, a logon trigger is specified using the LogonTrigger object.
For C++ development, a logon trigger is specified using the ILogonTrigger interface.
The child elements listed above are defined by the triggerBaseType and logonTriggerType complex element
types. These elements must be added in the sequence shown below.
Star tBoundar y (triggerBaseType)
EndBoundar y (triggerBaseType)
Enabled (triggerBaseType)
Repetition (triggerBaseType)
ExecutionTimeLimit (triggerBaseType)
UserId (logonTriggerType)
Delay (logonTriggerType)
Attributes
The attribute listed below is defined by the triggerBaseType complex element types.
Id: Identifier of the trigger.

Examples
For a complete example of the XML for a task that uses a logon trigger, see Logon Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
LogonType (principalType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the security logon method required to run those tasks associated with the principal.

<xs:element name="LogonType"
type="logonType"
/>

The LogonType element is defined by the principalType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Principal principalType Specifies the security credentials for a


principal.

Remarks
The LogonType element and the UserId element are used together to define the user required to run those
tasks that use this principal.
For scripting development, the logon type for the principal is specified by the Principal.LogonType property.
For C++ development, the logon type for the principal is specified by the IPrincipal::LogonType property.
This element (defined by the logonType simple type) must have one of the following values.
S4U: User must log on using a service for user (S4U) logon. When an S4U logon is used, no password is
stored by the system and there is no access to the network or encrypted files.
Password: User must log on using a password.
InteractiveToken: User must already be logged on. The task will be run only in an existing interactive session.
For a task, that contains a message box action, the message box will be displayed if the task is activated and the
task has an interactive logon type. To set the task logon type to be interactive, specify InteractiveToken in the
<LogonType> element of the task principal.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
MaintenanceSettings (maintenanceSettingsType)
Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies how the Task Scheduler performs tasks during Automatic maintenance.

<xs:element name="MaintenanceSettings"
type="maintenanceSettingsType"
minOccurs="0"
/>

The MaintenanceSettings element is defined by the maintenanceSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Deadline Specifies the amount of time after


which the Task scheduler will attempt
to start task during emergency
Automatic maintenance, if it failed to
complete during regular maintenance.

Exclusive boolean If set to true, the task will be started


exclusively among other maintenance
tasks.

Period Specifies how often the task needs to


be started during Automatic
maintenance.

Remarks
For C++ programming, this idle setting is specified using the ITaskSettings3::MaintenanceSettings property.

Examples
The following XML defines a settings element that instructs Task Scheduler to execute task once in 5 days during
regular Automatic maintenance and if failed for 15 days, start attempting the task during the emergency
Automatic maintenance.
<Settings>
<MaintenanceSettings>
<Period>P5D</Period>
<Deadline>P15D</Deadline>
</MaintenanceSettings>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 8 [desktop apps only]

Minimum supported server Windows Server 2012 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
March (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in March.

<xs:element name="March">
<xs:complexType />
</xs:element>

The March element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in March.

<Months>
<March/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
May (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in May.

<xs:element name="May">
<xs:complexType />
</xs:element>

The May element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in May.

<Months>
<May/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Monday (daysOfWeekType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs on Monday.

<xs:element name="Monday">
<xs:complexType />
</xs:element>

The Monday element is defined by the weeklyScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(monthlyDayOfWeekScheduleTyp the task runs for a monthly day-of-
e) week schedule.

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(weeklyScheduleType) the task runs for a weekly schedule.

Examples
The following XML defines a day of week calendar that starts a task on Monday.

<DaysOfWeek>
<Monday/>
</DaysOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Months (monthlyDayOfWeekScheduleType)
Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the months of the year during which the task runs for a monthly day-of-week schedule.

<xs:element name="Months"
type="monthsType"
/>

The Months element is defined by the monthlyDayOfWeekScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ScheduleByMonthDayOfWeek monthlyDayOfWeekScheduleType Specifies a trigger that starts a job for


(calendarTriggerType) a monthly day-of-week schedule.

Child elements
EL EM EN T TYPE DESC RIP T IO N

April Specifies that the task runs in April.

August Specifies that the task runs in August.

December Specifies that the task runs in


December.

Februar y Specifies that the task runs in


February.

Januar y Specifies that the task runs in January.

July Specifies that the task runs in July.

June Specifies that the task runs in June.

March Specifies that the task runs in March.

May Specifies that the task runs in May.

November Specifies that the task runs in


November.

October Specifies that the task runs in October.


EL EM EN T TYPE DESC RIP T IO N

September Specifies that the task runs in


September.

Remarks
For scripting development, the months of a year for a monthly day-of-week schedule are specified using the
MonthlyDOWTrigger.MonthsOfYear property.
For C++ development, the months of a year for a monthly day-of-week schedule are specified using the
IMonthlyDOWTrigger ::MonthsOfYear property.
The child elements above are defined by the monthsType complex type.

Examples
The following XML defines a monthly day-of-week calendar that starts the task on Monday of the first week for
each month of the year.

<ScheduleByMonthDayOfWeek>
<Weeks>
<Week>1</Week>
</Weeks>
<DaysOfWeek>
<Monday/>
</DaysOfWeek>
<Months>
<January/>
<February/>
<March/>
<April/>
<May/>
<June/>
<July/>
<August/>
<September/>
<October/>
<November/>
<December/>
<Months>
</ScheduleByMonthDayOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Months (monthlyScheduleType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the months of the year during which the task runs for a monthly schedule.

<xs:element name="Months"
type="monthsType"
/>

The Months element is defined by the monthlyScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ScheduleByMonth monthlyScheduleType Specifies a monthly schedule.

Child elements
EL EM EN T TYPE DESC RIP T IO N

April (monthsType) Specifies that the task runs in April.

August (monthsType) Specifies that the task runs in August.

December (monthsType) Specifies that the task runs in


December.

Februar y (monthsType) Specifies that the task runs in


February.

Januar y (monthsType) Specifies that the task runs in January.

July (monthsType) Specifies that the task runs in July.

June (monthsType) Specifies that the task runs in June.

March (monthsType) Specifies that the task runs in March.

May (monthsType) Specifies that the task runs in May.

November (monthsType) Specifies that the task runs in


November.

October (monthsType) Specifies that the task runs in October.

September (monthsType) Specifies that the task runs in


September.
Remarks
For script development, the months of the schedule are specified using the MonthlyTrigger.MonthsOfYear
property.
For C++ development, the months of the schedule are specified using the IMonthlyTrigger ::MonthsOfYear
property.

Examples
The following XML defines a monthly calendar that starts the task on the 1st and 15th day of every month of the
year.

</ScheduleByMonth>
<DaysOfMonth>
<Day>1</Day>
<Day>15</Day>
</DaysOfMonth
<Months>
<January/>
<February/>
<March/>
<April/>
<May/>
<June/>
<July/>
<August/>
<September/>
<October/>
<November/>
<December/>
<Months>
</ScheduleByMonth>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
MultipleInstancesPolicy (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the policy that defines how the Task Scheduler deals with multiple instances of the task.

<xs:element name="MultipleInstancesPolicy"
type="multipleInstancesPolicyType"
/>

The MultipleInstancesPolicy element is defined by the multipleInstancesPolicyType simple type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, see MultipleInstances Proper ty of ITaskSettings .
For script development, see TaskSettings.MultipleInstances .
Restricted Values
This element is restricted to the following values.
Parallel: Starts a new instance while an existing instance is running.
Queue: Starts a new instance of task after all other instances of the task are complete.
IgnoreNew: Default. Does not start a new instance if an existing instance of the task is running.
StopExisting: Stops an existing instance of the task before it starts a new instance.

Examples
The following XML defines a settings element that allows multiple instances of the task to run in parallel.

<Settings>
<MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


See also
Task Scheduler Schema Elements
Name (headerFieldType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the name of a header field in an email message.

<xs:element name="Name"
type="nonEmptyString"
/>

The Name element is defined by the headerFieldType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

HeaderField headerFieldType Contains a field for a header in an


email message.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Name (networkSettingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the name of a network profile. The name is used for display purposes.

<xs:element name="Name"
type="nonEmptyString"
minOccurs="0"
/>

The Name element is defined by the networkSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

NetworkSettings (settingsType) networkSettingsType Contains the settings that the Task


Scheduler service uses to obtain a
network profile. The Task Scheduler
service checks the availability of this
network when the
RunOnlyIfNetworkAvailable
element is set to True .

Remarks
For C++ development, see Name Proper ty of INetworkSettings .
For script development, see NetworkSettings.Name .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


NetworkProfileName (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the name of a network profile. The Task Scheduler service checks the availability of this network when
the RunOnlyIfNetworkAvailable element is set to True . The name is used for display purposes.

<xs:element name="NetworkProfileName"
type="string"
minOccurs="0"
/>

The NetworkProfileName element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings (taskType) settingsType Specifies the settings that the Task


Scheduler uses to perform the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


NetworkSettings (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the settings that the Task Scheduler service uses to obtain a network profile. The Task Scheduler service
checks the availability of this network when the RunOnlyIfNetworkAvailable element is set to True .

<xs:element name="NetworkSettings"
type="networkSettingsType"
minOccurs="0"
/>

The NetworkSettings element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings (taskType) settingsType Specifies the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, see NetworkSettings Proper ty of ITaskSettings .
For script development, see TaskSettings.NetworkSettings .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


November (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in November.

<xs:element name="November">
<xs:complexType />
</xs:element>

The November element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in November.

<Months>
<November/>
</DaysOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
October (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in October.

<xs:element name="October">
<xs:complexType />
</xs:element>

The October element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in October.

<Months>
<October/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Period Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies how often the task needs to be started during Automatic maintenance.
The format for this string is PnYnMnDTnHnMnS , where nY is the number of years, nM is the number of months,
nD is the number of days, T is the date/time separator, nH is the number of hours, nM is the number of minutes,
and nS is the number of seconds (for example, "PT5M" specifies 5 minutes and "P1M4DT2H5M" specifies one
month, four days, two hours, and five minutes). The minimum value is one minute. For more information about
the duration type, see XML Schema Part 2: Datatypes Second Edition.

<xs:element name="Period"
maxOccurs="1"
minOccurs="1"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="P1D"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The Period element is defined by the maintenanceSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

MaintenanceSettings maintenanceSettingsType Specifies the task settings the Task


(maintenanceSettingsType) scheduler will use to start task during
Automatic maintenance.

Remarks
For C++ programming, this idle setting is specified using the IMaintenanceSettings::Period property.

Examples
The following XML defines maintenance task with periodicity requirement set to 5 days.

<MaintenanceSettings>
<Period>P5D</Period>
</MaintenanceSettings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 8 [desktop apps only]

Minimum supported server Windows Server 2012 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Principal (principalType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the security credentials for a principal. These credentials define the security context that a task runs
under.

<xs:element name="Principal"
type="principalType"
/>

The Principal element is defined by the principalType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Principals principalsType Specifies the security principals


associated with the task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

DisplayName string Specifies the name of the principal that


is displayed in the Task Scheduler UI.

GroupId string Specifies the identifier of the user


group required to run tasks associated
with the principal.

LogonType logonType Specifies the security logon method


required to run those tasks associated
with the principal.

UserId string Specifies the user identifier required to


run tasks associated with the principal.

Attributes
NAME TYPE DESC RIP T IO N

Id ID Identifier of the principal definition.

Remarks
For scripting development, the security credentials for a principal are specified using the Principal object.
For C++ development, the security credentials for a principal are specified using the IPrincipal interface.
The child elements listed above are defined by the principalType complex type. For sequencing information for
these child elements, see principalType .

Examples
The following XML defines a principal with a user identifier.

<Principals>
<Principal>
<UserId></UserId>
<LogonType><LogonType>
<DisplayName></DisplayName>
</Principal>
</Principals>

The following XML defines a principal with a group identifier.

<Principals>
<Principal>
<GroupId></GroupId>
<DisplayName></DisplayName>
</Principal>
</Principals>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
Principals (taskType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the security contexts that can be used to run the task.

<xs:element name="Principals"
type="principalsType"
/>

The Principals element is defined by the taskType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Task taskType Defines the task that is performed by


the Task Scheduler service.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Principal principalType Specifies the security credentials for a


principal.

Remarks
You can specify up to 32 principals for a task.
For scripting development, the principals of a task are specified using the TaskDefinition.Principal property.
For C++ development, the principals of a task are specified using the Principal proper ty of ITaskDefinition .

Examples
The following XML defines two principals: a user identifier and group identifier principal for the task.

<Principals>
<Principal>
<UserId></UserId>
<LogonType><LogonType>
<DisplayName></DisplayName>
</Principal>
<Principal>
<GroupId></GroupId>
<DisplayName></DisplayName>
</Principal>
</Principals>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Privilege (requiredPrivilegesType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the right of a task to perform various system-related operations, such as shutting down the system,
loading device drivers, or changing the system time.

<xs:element name="Privilege"
type="privilegeType"
maxOccurs="64"
minOccurs="1"
/>

The Privilege element is defined by the requiredPrivilegesType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RequiredPrivileges requiredPrivilegesType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, this information is accessed through the IPrincipal2::RequiredPrivilege property.

Examples
The following XML defines a settings element that specifies the right of a task to perform various system-related
operations, such as shutting down the system, loading device drivers, or changing the system time.

<Principal>
<RequiredPrivileges>
<Privilege>SeCreateTokenPrivilege</Privilege>
</RequiredPrivileges>
</Principal>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]

See also
Task Scheduler Schema Elements
ProcessTokenSidType (principalType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the process security identify (SID) type of the task.

<xs:element name="ProcessTokenSidType"
type="processTokenSidType"
maxOccurs="1"
minOccurs="0"
/>

The ProcessTokenSidType element is defined by the principalType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Principal principalType Specifies the security credentials for a


principal.

Remarks
For C++ development, the process SID type is specified by using the IPrincipal2::ProcessTokenSidType
property.

Examples
The following XML defines the process SID type of the task.

<Principal>
<GroupId>NT AUTHORITY\LOCAL SERVICE</GroupId>
<ProcessTokenSidType>None</ProcessTokenSidType>
</Principal>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]

See also
Task Scheduler
Priority (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the priority level for the task.

<xs:element name="Priority"
type="priorityType"
default="7"
minOccurs="0"
/>

The Priority element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
Priority level 0 is the highest priority, and priority level 10 is the lowest priority. The default value is 7. The
minimum and maximum values are set by the priorityType simple type. Priority levels 7 and 8 are used for
background tasks, and priority levels 4, 5, and 6 are used for interactive tasks.
The task's action is started in a process with a priority that is based on a Priority Class value. A Priority Level
value (thread priority) is used for COM handler, message box, and email task actions. For more information
about the Priority Class and Priority Level values, see Scheduling Priorities; for more information about I/O
Priority values, see IO_PRIORITY_HINT enumeration; for information about Memory Priority values, see
MEMORY_PRIORITY_INFORMATION structure. The following table lists the possible values for the Priority
element, and the corresponding Priority Class, Priority Level, I/O Priority and Memory Priority values.

TA SK P RIO RIT Y P RIO RIT Y C L A SS P RIO RIT Y L EVEL I/ O P RIO RIT Y M EM O RY P RIO RIT Y

0 REALTIME_PRIORITY_ THREAD_PRIORITY_TI IoPriorityNormal MEMORY_PRIORITY_


CLASS ME_CRITICAL NORMAL

1 HIGH_PRIORITY_CLA THREAD_PRIORITY_H IoPriorityNormal MEMORY_PRIORITY_


SS IGHEST NORMAL

2 ABOVE_NORMAL_PR THREAD_PRIORITY_A IoPriorityNormal MEMORY_PRIORITY_


IORITY_CLASS BOVE_NORMAL NORMAL

3 ABOVE_NORMAL_PR THREAD_PRIORITY_A IoPriorityNormal MEMORY_PRIORITY_


IORITY_CLASS BOVE_NORMAL NORMAL

4 NORMAL_PRIORITY_ THREAD_PRIORITY_N IoPriorityNormal MEMORY_PRIORITY_


CLASS ORMAL NORMAL
TA SK P RIO RIT Y P RIO RIT Y C L A SS P RIO RIT Y L EVEL I/ O P RIO RIT Y M EM O RY P RIO RIT Y

5 NORMAL_PRIORITY_ THREAD_PRIORITY_N IoPriorityNormal MEMORY_PRIORITY_


CLASS ORMAL BELOW_NORMAL

6 NORMAL_PRIORITY_ THREAD_PRIORITY_N IoPriorityNormal MEMORY_PRIORITY_


CLASS ORMAL MEDIUM

7 BELOW_NORMAL_PR THREAD_PRIORITY_B IoPriorityLow MEMORY_PRIORITY_


IORITY_CLASS ELOW_NORMAL LOW

8 BELOW_NORMAL_PR THREAD_PRIORITY_B IoPriorityLow MEMORY_PRIORITY_


IORITY_CLASS ELOW_NORMAL VERY_LOW

9 IDLE_PRIORITY_CLAS THREAD_PRIORITY_L IoPriorityVeryLow MEMORY_PRIORITY_


S OWEST VERY_LOW

10 IDLE_PRIORITY_CLAS THREAD_PRIORITY_I IoPriorityVeryLow MEMORY_PRIORITY_


S DLE VERY_LOW

For C++ development, see Priority Proper ty of ITaskSettings .


For script development, see TaskSettings.Priority .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
RandomDelay (calendarTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the delay time that is randomly added to the start time of the trigger. The format for this string is
PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days, 'T'
is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of
seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours,
and five minutes). For more information about the duration type, see https://go.microsoft.com/fwlink/p/?
linkid=106886.

<xs:element name="RandomDelay"
type="duration"
default="PT0M"
minOccurs="0"
/>

The RandomDelay element is defined by the calendarTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

CalendarTrigger (triggerGroup) calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


RandomDelay (timeTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the delay time that is randomly added to the start time of the trigger. The format for this string is
PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD is the number of days, 'T'
is the date/time separator, nH is the number of hours, nM is the number of minutes, and nS is the number of
seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one month, four days, two hours,
and five minutes). For more information about the duration type, see https://go.microsoft.com/fwlink/p/?
linkid=106886.

<xs:element name="RandomDelay"
type="duration"
default="PT0M"
minOccurs="0"
/>

The element is defined by the timeTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

TimeTrigger (triggerGroup) timeTriggerType Specifies a trigger that starts a task


when the trigger is activated.

Remarks
For C++ development, see RandomDelay Proper ty of ITimeTrigger .
For script development, see TimeTrigger.RandomDelay .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


RegistrationInfo (taskType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies administrative information about the task, such as the author of the task and the date the task is
registered.

<xs:element name="RegistrationInfo"
type="registrationInfoType"
minOccurs="0"
/>

The RegistrationInfo element is defined by the taskType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Task taskType Defines the task that is performed by


the Task Scheduler service.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Author (registrationInfoType) string Specifies the author of the task.

Date (registrationInfoType) dateTime Specifies the date and time when the
task is registered.

Description (registrationInfoType) string Specifies the description of the task.

Documentation string Specifies any additional documentation


(registrationInfoType) for the task.

SecurityDescriptor string Specifies the security descriptor of the


(registrationInfoType) task.

Source (registrationInfoType) string Specifies where the task originated


from. For example, from a component,
a service, an application, or a user.

URI (registrationInfoType) anyURI Specifies the URI of the task.

Version (registrationInfoType) string Specifies the version number of the


task.

Remarks
For scripting development, the registration information of a task is specified using the
TaskDefinition.RegistrationInfo property.
For C++ development, the registration information of a task is specified using the RegistrationInfo proper ty
of ITaskDefinition .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
RegistrationTrigger (triggerGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a trigger that starts a task when the task is registered.

<xs:element name="RegistrationTrigger"
type="registrationTriggerType"
/>

The RegistrationTrigger element is defined by the registrationTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Triggers triggersType Specifies the triggers that start the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay (registrationTriggerType) duration Specifies the amount of time between


when the task is registered and when
the task is started.

Enabled (triggerBaseType) boolean Specifies that the trigger is enabled.

EndBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit duration Specifies the maximum amount of time


(triggerBaseType) in which the task can be started by the
trigger.

Repetition (triggerBaseType) repetitionType Specifies how often the task is run and
how long the repetition pattern is
repeated after the task is started.

Star tBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is activated.

Attributes
NAME TYPE DESC RIP T IO N

Id ID Identifier of the trigger.


Remarks
For scripting development, a registration trigger is specified using the RegistrationTrigger object.
For C++ development, a registration trigger is specified using the IRegistrationTrigger interface.
The child elements listed above are defined by the triggerBaseType and registrationTriggerType complex
element types. These elements must be added in the sequence shown below.
Star tBoundar y (triggerBaseType)
EndBoundar y (triggerBaseType)
Enabled (triggerBaseType)
Repetition (triggerBaseType)
ExecutionTimeLimit (triggerBaseType)
Delay (registrationTriggerType)

Examples
For a complete example of the XML for a task that specifies a boot trigger, see Registration Trigger Example
(XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Repetition (triggerBaseType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies how often the task is run and how long the repetition pattern is repeated after the task is started.

<xs:element name="Repetition"
type="repetitionType"
/>

The Repetition element is defined by the triggerBaseType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

BootTrigger bootTriggerType Specifies a trigger that starts a task


when the system is booted.

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

EventTrigger eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

IdleTrigger idleTriggerType Specifies a trigger that starts a task


when the computer goes into an idle
state.

LogonTrigger logonTriggerType Specifies a trigger that starts a task


when a user logs on.

RegistrationTrigger registrationTriggerType Specifies a trigger that starts a task


when the task is registered.

TimeTrigger timeTriggerType Specifies a trigger that starts a task


when the trigger is activated.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Duration duration Specifies how long the pattern is


repeated.

Inter val duration Specifies the amount of time between


each restart of the task.
EL EM EN T TYPE DESC RIP T IO N

StopAtDurationEnd boolean Specifies that a running instances of


the task is stopped at the end of the
repetition pattern duration.

Remarks
If you specify a repetition duration for a task, you must also specify the repetition interval.
If you register a task that contains a trigger with a repetition interval equal to one minute and a repetition
duration equal to four minutes, the task will be launched five times. The five repetitions can be defined by the
following pattern.
1. A task starts at the beginning of the first minute.
2. The next task starts at the end of the first minute.
3. The next task starts at the end of the second minute.
4. The next task starts at the end of the third minute.
5. The next task starts at the end of the fourth minute.
Windows Ser ver 2003, Windows XP and Windows 2000: If you register a task that contains a trigger with
a repetition interval equal to one minute and a repetition duration equal to four minutes, the task will be
launched four times.
Windows Vista, Windows 7, Windows Ser ver 2008, Windows 8 and Windows Ser ver 2012: Usually,
setting the repetition duration to an exact multiple of the interval yields the numbers described above. However,
under certain heavy load conditions, it is possible for the duration to timeout before TaskScheduler can launch
the final task interval.
For scripting development, the repetition pattern is specified using the Trigger.Repetition property that is
inherited by all the trigger objects.
For C++ development, the repetition pattern is specified using the ITRigger ::Repetition property that is
inherited by all the trigger interfaces.

Examples
The following XML defines a boot trigger element that specifies a repetition pattern for a trigger.

<BootTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T08:00:00</EndBoundary>
<Enabled>true</Enabled>
<Repetition>
<Interval></Interval>
<Duration></Duration>
<StopAtDurationEnd>true</StopAtDirationEnd>
</Repetition>
<ExecutionTimeLimit></ExecutionTimeLimit>
<Delay><Delay>
</BootTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
ReplyTo (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the email addresses that are replied to in the email message.

<xs:element name="ReplyTo"
type="string"
/>

The ReplyTo element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Remarks
For C++ development, see ReplyTo Proper ty of IEmailAction .
For script development, see EmailAction.ReplyTo .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


RequiredPrivileges (requiredPrivilegesType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the privileges that are required by the task.

<xs:element name="RequiredPrivileges"
type="requiredPrivilegesType"
minOccurs="0"
/>

The RequiredPrivileges element is defined by the requiredPrivilegesType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Principal (principalType) principalType Specifies the security credentials for a


principal.

Remarks
For C++ development, this information is accessed through the IPrincipal2::RequiredPrivilege property.

Examples
The following XML defines using a group identifier and the required privileges.

<Principal>
<RequiredPrivileges>
<Privilege>SeCreateTokenPrivilege</Privilege>
</RequiredPrivileges>
</Principal>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]

See also
Task Scheduler
RestartOnFailure (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the Task Scheduler will attempt to restart the task if the task fails for any reason.

<xs:element name="RestartOnFailure"
type="restartType"
minOccurs="0"
/>

The Restar tOnFailure element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Count unsignedByte Specifies the number of times that the


Task Scheduler will attempt to restart
the task.

Inter val duration Specifies how long the Task Scheduler


will attempt to restart the task.

Remarks
When an application specifies task settings, this information is accessed through the Restar tCount and
Restar tInter val properties of the ITaskSettings interface. For scripting, this information is accessed through
the TaskSettings.Restar tCount and TaskSettings.Restar tInter val properties.
Both child elements must be set to specify how the Task Scheduler restarts the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
RestartOnIdle (idleSettingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies whether the task is restarted when the computer cycles into an idle condition more than once.

<xs:element name="RestartOnIdle"
type="boolean"
default="false"
minOccurs="0"
/>

The Restar tOnIdle element is defined by the idleSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

IdleSettings idleSettingsType Specifies how the Task Scheduler


performs tasks when the computer is
in an idle state.

Remarks
This element is used only if the TerminateOnIdleEnd element is set to True.
For script development, this task settings is specified using the IdleSettings.Restar tOnIdle property.
For C++ development, this task settings is specified using the IIdleSettings::Restar tOnIdle property.

Examples
The following XML defines an idle setting that indicates that the task should not be restarted when the idle
condition cycles.

<IdleSettings>
<TerminateOnIdleEnd>true</TerminateOnIdleEnd>
<RestartOnIdle>true</RestartOnIdle>
</IdleSettings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
RunLevel (runLevelType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains a value that specifies the security context level for running the task. You can specify to run a task using
least privileges or elevated privileges. A value of 0 specifies to run the task with lowest privileges, and a value of
1 specifies to run the task with elevated privileges.

<xs:element name="RunLevel"
type="runLevelType"
/>

The RunLevel element is defined by the runLevelType simple type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Principal (principalType) principalType Specifies the security credentials for a


principal. These credentials define the
security context that a task runs under.

Remarks
For C++ development, see RunLevel Proper ty of IPrincipal .
For script development, see Principal.RunLevel .
If a task is registered using the Builtin\Administrator account or the LocalSystem or LocalService accounts,
the RunLevel property is ignored. The attribute value will also be ignored if User Account Control (UAC) is
turned off.
If a task is registered using the Administrators group for the security context of the task, then you must also
set the RunLevel property to "HighestAvailable" to run the task. For more information, see Security Contexts
for Tasks.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


RunOnlyIfIdle (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task is run only when the computer is in an idle state.

<xs:element name="RunOnlyIfIdle"
type="boolean"
/>

The RunOnlyIfIdle element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, see RunOnlyIfIdle Proper ty of ITaskSettings .
For script development, see TaskSettings.RunOnlyIfIdle .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
RunOnlyIfNetworkAvailable (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the Task Scheduler will run the task only when a network is available.

<xs:element name="RunOnlyIfNetworkAvailable"
type="boolean"
default="false"
minOccurs="0"
/>

The RunOnlyIfNetworkAvailable element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ development, see RunOnlyIfNetworkAvailable Proper ty of ITaskSettings .
For script development, see TaskSettings.RunOnlyIfNetworkAvailable .

Examples
The following XML defines a settings element that allows the task to start only if a network is available.

<Settings>
<RunOnlyIfNetworkAvailable>true</RunOnlyIfNetworkAvailable>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Saturday (daysOfWeekType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs on Saturday.

<xs:element name="Saturday">
<xs:complexType />
</xs:element>

The Saturday element is defined by the daysOfWeekType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(monthlyDayOfWeekScheduleTyp the task runs for a monthly day-of-
e) week schedule.

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(weeklyScheduleType) the task runs for a weekly schedule.

Examples
The following XML defines a day of week calendar that starts a task on Saturday.

<DaysOfWeek>
<Saturday/>
</DaysOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
ScheduleByDay (calendarTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a daily schedule. For example, the task starts at 8:00 AM every day, every-other day, every third day,
and so on.

<xs:element name="ScheduleByDay"
type="dailyScheduleType"
/>

The ScheduleByDay element is defined by the calendarTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

Child elements
EL EM EN T TYPE DESC RIP T IO N

DaysInter val unsignedByte Specifies the interval between the days


in the schedule.

Remarks
The child element listed previously is defined by the dailyScheduleType complex element types.
The time of day that the task is started is set by the Star tBoundar y element.
For scripting development, a daily trigger is specified using the DailyTrigger object.
For C++ development, a daily trigger is specified using the IDailyTrigger interface.

Examples
The following XML defines a daily calendar trigger that starts the task every day.

<CalendarTrigger>
<StartBoundary>2005-01-01T00:00:00</StartBoundary>
<EndBounadry>2007-01-01T00:00:00</EndBoundary>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>

For a complete example of the XML for a task that specifies a daily schedule, see Daily Trigger Example (XML).
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
ScheduleByMonthDayOfWeek
(calendarTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a monthly day-of-week schedule. For example, the task starts on specific days of the week, weeks of
the month, and months of the year.

<xs:element name="ScheduleByMonthDayOfWeek"
type="monthlyDayOfWeekScheduleType"
/>

The ScheduleByMonthDayOfWeek element is defined by the monthlyDayOfWeekScheduleType complex


type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

Child elements
EL EM EN T TYPE DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


the task runs.

Months monthsType Specifies the months of the year


during which the task runs.

Weeks unsignedByte Specifies the interval between the


weeks in the schedule.

Remarks
The time of day that the task is started is set by the Star tBoundar y element.
For scripting development, a monthly day-of-week trigger is specified using the MonthlyDOWTrigger object.
For C++ development, a monthly day-of-week trigger is specified using the IMonthlyDOWTrigger interface.
The child elements listed above are defined by the monthlyDayOfWeekScheduleType complex element
types.

Examples
The following XML defines a monthly day of week calendar trigger that starts a task ( at 8:00 AM) on Monday of
the first week for each month of the year.

<CalendarTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T00:00:00</EndBoundary>
<ScheduleByMonthDayOfWeek>
<Weeks>
<Week>1</Week>
</Weeks>
<DaysOfWeek>
<Monday/>
</DaysOfWeek>
<Months>
<January/>
<February/>
<March/>
<April/>
<May/>
<June/>
<July/>
<August/>
<September/>
<October/>
<November/>
<December/>
<Months>
</ScheduleByMonthDayOfWeek>
</CalendarTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
ScheduleByMonth (calendarTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a monthly schedule. For example, the task starts at 8:00 AM on specific days of the month on specific
months.

<xs:element name="ScheduleByMonth"
type="monthlyScheduleType"
/>

The ScheduleByMonth element is defined by the calendarTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

Child elements
EL EM EN T TYPE DESC RIP T IO N

DaysOfMonth daysOfMonthType Specifies the days of the month during


(monthlyScheduleType) which the task runs.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs.

Remarks
The time of day that the task is started is set by the Star tBoundar y element.
For script development, a monthly trigger is specified using the MonthlyTrigger object.
For C++ development, a monthly trigger is specified using the IMonthlyTrigger interface.
The child elements listed below are defined by the monthlyScheduleType complex element types.

Examples
The following XML defines a monthly calendar trigger that starts a task ( at 8:00 AM) on the 1st and 15th day of
every month of the year.
<CalendarTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T00:00:00</EndBoundary>
<ScheduleByMonth>
<DaysOfMonth>
<Day>1</Day>
<Day>15</Day>
</DaysOfMonth>
<Months>
<January/>
<February/>
<March/>
<April/>
<May/>
<June/>
<July/>
<August/>
<September/>
<October/>
<November/>
<December/>
</Months>
</ScheduleByMonth>
</CalendarTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
ScheduleByWeek (calendarTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a weekly schedule. For example, the task starts at 8:00 AM on a specific day of the week every week or
on a specific day of the week every other week.

<xs:element name="ScheduleByWeek"
type="weeklyScheduleType"
/>

The ScheduleByWeek element is defined by the calendarTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

Child elements
EL EM EN T TYPE DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


the task runs.

WeeksInter val unsignedByte Specifies the interval between the


weeks in the schedule.

Remarks
The child elements listed above are defined by the weeklyScheduleType complex element types.
The time of day that the task is started is set by the Star tBoundar y element.
For scripting development, a weekly trigger is specified using the WeeklyTrigger object.
For C++ development, a weekly trigger is specified using the IWeeklyTrigger interface.

Examples
The following XML defines a weekly calendar trigger that starts a task Monday through Friday (at 8:00 AM)
every week.
<CalendarTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T00:00:00</EndBoundary>
<ScheduleByWeek>
<WeeksInterval>1</WeeksInterval>
<DaysOfWeek>
<Monday/>
<Tuesday/>
<Wednesday/>
<Thurday/>
<Friday/>
</DaysOfWeek>
</ScheduleByWeek>
</CalendarTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
SecurityDescriptor (registrationInfoType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the security descriptor of the task.

<xs:element name="SecurityDescriptor"
type="string"
/>

The SecurityDescriptor element is defined by the registrationInfoType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Remarks
For scripting development, the security descriptor of a task is specified using the
RegistrationInfo.SecurityDescriptor property.
For C++ development, the security descriptor of a task is specified using the
IRegistrationInfo::SecurityDescriptor property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
SendEmail (actionGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Represents an action that sends an email message.

<xs:element name="SendEmail"
type="sendEmailType"
/>

The SendEmail element is defined by the actionGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Actions actionsType Contains the actions performed by the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Attachments attachmentsType Specifies a list of attachments in the


email message.

Bcc string Specifies the email addresses used on


the Bcc line of an email message.

Body string Specifies the text in the body of the


email message.

Cc string Specifies the email addresses used on


the Cc line of an email message.

From string Specifies the email address of the


sender.

HeaderFields headerFieldsType Specifies the header fields and their


values used in the header of the email
message.

ReplyTo string Specifies the email addresses that are


replied to in the email message.

Ser ver nonEmptyString Specifies the email server used to send


the email message.

Subject string Specifies the subject of the email


message.
EL EM EN T TYPE DESC RIP T IO N

To string Specifies the email addresses to which


the email will be sent.

Remarks
For C++ development, see the IEmailAction interface.
For script development, see the EmailAction object.
Windows 8 and Windows Ser ver 2012: This element has been removed. Please use IExecAction with the
powershell Send-MailMessage cmdlet as a workaround.

Examples
For a complete example of the XML for a task that specifies an email action, see Event Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7

End of server support Windows Server 2008 R2


September (monthsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs in September.

<xs:element name="September">
<xs:complexType />
</xs:element>

The September element is defined by the monthsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Months monthsType Specifies the months of the year


(monthlyDayOfWeekScheduleTyp during which the task runs for a
e) monthly day-of-week schedule.

Months (monthlyScheduleType) monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Examples
The following XML defines a months calendar that runs the task in September.

<Months>
<September/>
</Months>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Server (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the email server used to send the email message.

<xs:element name="Server"
type="nonEmptyString"
/>

The Ser ver element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Remarks
For C++ development, see Ser ver Proper ty of IEmailAction .
For script development, see EmailAction.Ser ver .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


SessionStateChangeTrigger (triggerGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a trigger that starts a task when a Terminal Server session changes state.

<xs:element name="SessionStateChangeTrigger"
type="sessionStateChangeTriggerType"
/>

The SessionStateChangeTrigger element is defined by the triggerGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Triggers triggersType Specifies the triggers that start the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay duration Specifies a value that indicates the


length of the delay before a task is
started when a Terminal Server session
state change is detected.

StateChange sessionStateChangeType Specifies the kind of Terminal Server


session change that would trigger a
task launch.

UserId nonEmptyString Specifies the user for the Terminal


Server session. When a session state
change is detected for this user, a task
is started.

Remarks
For scripting development, a session state change trigger is specified using the SessionStateChangeTrigger
object.
For C++ development, a session state change trigger is specified using the ISessionStateChangeTrigger
interface.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]


REQ UIREM EN T VA L UE

Minimum supported server Windows Server 2008 [desktop apps only]


Settings (taskType) Element
8/8/2022 • 2 minutes to read • Edit Online

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

<xs:element name="Settings"
type="settingsType"
minOccurs="0"
/>

The Settings element is defined by the taskType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Task taskType Specifies the task that is performed by


the Task Scheduler service.

Child elements
EL EM EN T TYPE DESC RIP T IO N

AllowHardTerminate boolean Specifies that the task may be


terminated using TerminateProcess.

AllowStar tOnDemand boolean Specifies that the task can be started


using either the Run command or the
Context menu.

DeleteExpiredTaskAfter duration Specifies the amount of time that the


Task Scheduler will wait before deleting
the task after it expires.

DisallowStar tIfOnBatteries boolean Specifies that the task will not be


started if the computer is running on
batteries.

Enabled boolean Specifies that the task is enabled. The


task can be performed only when this
setting is True.

ExecutionTimeLimit duration Amount of time allowed to complete


the task.

Hidden boolean Specifies that the task will not be


visible in the UI by default.

IdleSettings idleSettingsType Specifies how the Task Scheduler


performs tasks when the computer is
in an idle state.
EL EM EN T TYPE DESC RIP T IO N

MaintenanceSettings maintenanceSettingsType Specifies how the Task Scheduler


performs tasks during Automatic
maintenance.

MultipleInstancesPolicy multipleInstancesPolicyType Specifies the policy that defines how


the Task Scheduler deals with multiple
instances of the task.

Priority priorityType Specifies the priority level for the task.

Restar tOnFailure restar tType Specifies that the Task Scheduler will
attempt to restart the task if the task
fails for any reason.

RunOnlyIfIdle boolean Specifies that the task is run only when


the computer is in an idle state.

RunOnlyIfNetworkAvailable boolean Specifies that the Task Scheduler will


run the task only when a network is
available.

Star tWhenAvailable boolean Specifies that the Task Scheduler can


start the task at any time after its
scheduled time has passed.

StopIfGoingOnBatteries boolean Specifies that the task will be stopped


(settingsType) if the computer is going onto batteries.

Volatile boolean Specifies if the task is automatically


disabled by Task Scheduler at Windows
startup.

WakeToRun (settingsType) boolean Specifies that Task Scheduler will wake


the computer when it is time to run
the task.

Remarks
You can select one or more of the child elements referenced above.
For C++ development, the registration information of a task is specified using the Settings proper ty of
ITaskDefinition .
For scripting development, the registration information of a task is specified using the TaskDefinition.Settings
property.

Examples
The following XML code example defines a settings element that allows a hard termination of the task.
<task>
<Settings>
<AllowHardTerminate>true</AllowHardTerminate>
<AllowStartOnDemand>true</AllowStartOnDemand>
</Settings>
</task>

For more information and a complete example of the XML for setting task settings, see Time Trigger Example
(XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
ShowMessage (actionGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Represents an action that shows a message box.

<xs:element name="ShowMessage"
type="showMessageType"
/>

The ShowMessage element is defined by the actionGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Actions (taskType) actionsType Contains the actions performed by the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Body nonEmptyString Specifies the text to display in the body


of the message box.

Title nonEmptyString Specifies the title of the message box.

Remarks
For scripting development, a message box action is specified using the ShowMessageAction object.
For C++ development, a message box action is specified using the IShowMessageAction interface.
Windows 8 and Windows Ser ver 2012: This element has been removed. You can use IExecAction with the
Windows scripting MsgBox function to show a message in the user session.

Examples
For a complete example of the XML for a task that uses a message box action, see Message Box Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

End of client support Windows 7


REQ UIREM EN T VA L UE

End of server support Windows Server 2008 R2


Source (registrationInfoType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies where the task originated from. For example, from a component, a service, an application, or a user.

<xs:element name="Source"
type="string"
minOccurs="0"
/>

The Source element is defined by the registrationInfoType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Remarks
For scripting development, the source of a task is specified using the RegistrationInfo.Source property.
For C++ development, the source of a task is specified using the IRegistrationInfo::Source property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
StartBoundary (triggerBaseType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the date and time when the trigger is activated.

<xs:element name="StartBoundary"
type="dateTime"
/>

The Star tBoundar y element is defined by the triggerBaseType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

BootTrigger bootTriggerType Specifies a trigger that starts a task


when the system is booted.

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

EventTrigger eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

IdleTrigger idleTriggerType Specifies a trigger that starts a task


when the computer goes into an idle
state.

LogonTrigger logonTriggerType Specifies a trigger that starts a task


when a user logs on.

RegistrationTrigger registrationTriggerType Specifies a trigger that starts a task


when the task is registered.

TimeTrigger timeTriggerType Specifies a trigger that starts a task


when the trigger is activated.

Remarks
The <Star tBoundar y> element is a required element for time and calendar triggers (<TimeTrigger> and
<CalendarTrigger> ).
For scripting development, the end boundary is specified using the Trigger.Star tBoundar y property that is
inherited by the all trigger objects.
For C++ development, the end boundary is specified using the ITrigger ::Star tBoundar y property that is
inherited by the all trigger interfaces.

Examples
The following XML defines a boot trigger element that defines a start boundary of January 1, 2005: 8:00 AM.

<BootTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T08:00:00</EndBoundary>
<Enabled>true</Enabled>
<Repetition></Repetition>
<ExecutionTimeLimit></ExecutionTimeLimit>
<Delay><Delay>
</BootTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
StartWhenAvailable (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the Task Scheduler can start the task at any time after its scheduled time has passed.

<xs:element name="StartWhenAvailable"
type="boolean"
default="false"
minOccurs="0"
/>

The Star tWhenAvailable element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
This property applies only to timed tasks.
For C++ development, see Star tWhenAvailable Proper ty of ITaskSettings .
For script development, see TaskSettings.Star tWhenAvailable .

Examples
The following XML defines a settings element that allows the Task Scheduler to start the task when it is available.

<Settings>
<StartWhenAvailable>true</StartWhenAvailable>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
StateChange (sessionStateChangeTriggerType)
Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the kind of Terminal Server session change that would trigger a task launch.

<xs:element name="StateChange"
type="sessionStateChangeType"
/>

The StateChange element is defined by the sessionStateChangeTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SessionStateChangeTrigger sessionStateChangeTriggerType Specifies a trigger that starts a task


when a Terminal Server session
changes state.

Remarks
For C++ development, see StateChange Proper ty of ISessionStateChangeTrigger .
For script development, see SessionStateChangeTrigger.StateChange .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


StopAtDurationEnd (repetitionType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that a running instance of the task is stopped at the end of the repetition pattern duration. This is
applicable only if repetitions are set.

<xs:element name="StopAtDurationEnd"
type="boolean"
/>

The StopAtDurationEnd element is defined by the repetitionType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Repetition repetitionType Specifies how often the task is run and


how long the repetition pattern is
repeated after the task is started.

Remarks
For scripting development, this setting is specified using the RepetitionPattern.StopAtDurationEnd property.
For C++ development, this setting is specified using the IRepetitionPattern::StopAtDurationEnd property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
StopIfGoingOnBatteries (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task will be stopped if the computer is going onto batteries.

<xs:element name="StopIfGoingOnBatteries"
type="boolean"
default="true"
minOccurs="0"
/>

The StopIfGoingOnBatteries element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
The default setting for this element is False. Note that the default value has changed from previous versions of
Task Scheduler.
For scripting development, this setting is specified using the TaskSettings.StopIfGoingOnBatteries property.
For C++ development, this setting is specified using the ITaskSettings::StopIfGoingOnBatteries property.

Examples
The following XML defines a settings element that allows a hard termination of the task.

<Settings>
<StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
StopOnIdleEnd (idleSettingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the Task Scheduler will stop the task if the idle condition ends before the task is completed.

<xs:element name="StopOnIdleEnd"
type="boolean"
minOccurs="0"
default="true"
/>

The StopOnIdleEnd element is defined by the idleSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

IdleSettings idleSettingsType Specifies how the Task Scheduler


performs tasks when the computer is
in an idle state.

Remarks
For C++ development, see StopOnIdleEnd Proper ty of IIdleSettings .
For script development, see IdleSettings.StopOnIdleEnd .

Examples
The following XML defines an idle setting that indicates the task should not be performed when the idle
condition ends.

<IdleSettings>
<StopOnIdleEnd>false</StopOnIdleEnd>
</IdleSettings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Subject (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the subject of the email message.

<xs:element name="Subject"
type="string"
/>

The Subject element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Remarks
For C++ development, see Subject Proper ty of IEmailAction .
For script development, see EmailAction.Subject .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Subscription (eventTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the XPath query that identifies the event that fires the trigger.

<xs:element name="Subscription"
type="nonEmptyString"
/>

The Subscription element is defined by the eventTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

EventTrigger eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

Remarks
For script development, the event subscription is specified by the EventTrigger.Subscription property.
For C++ development, the event subscription is specified by the IEventTrigger ::Subscription property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Sunday (daysOfWeekType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs on Sunday.

<xs:element name="Sunday">
<xs:complexType />
</xs:element>

The Sunday element is defined by the daysOfWeekType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(monthlyDayOfWeekScheduleTyp the task runs for a monthly day-of-
e) week schedule.

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(weeklyScheduleType) the task runs for a weekly schedule.

Examples
The following XML defines a day of week calendar that starts a task on Sunday.

<DaysOfWeek>
<Sunday/>
</DaysOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Task Element
8/8/2022 • 2 minutes to read • Edit Online

Defines the task that is performed by the Task Scheduler service.

<xs:element name="Task"
type="taskType"
>
<xs:key name="PrincipalKey">
<xs:selector
xpath="td:Principals/td:Principal"
/>
<xs:field
xpath="@id"
/>
</xs:key>
<xs:keyref name="ContextKeyRef">
<xs:selector
xpath="td:Actions"
/>
<xs:field
xpath="@Context"
/>
</xs:keyref>
<xs:unique name="UniqueId">
<xs:selector

xpath="td:Principals/td:Principal|td:Triggers/td:BootTrigger|td:Triggers/td:RegistrationTrigger|td:Triggers/
td:IdleTrigger|td:Triggers/td:TimeTrigger|td:Triggers/td:EventTrigger|td:Triggers/td:LogonTrigger|td:Trigger
s/td:SessionStateChangeTrigger|td:Triggers/td:CalendarTrigger|td:Actions/td:Exec|td:Actions/td:ComHandler|td
:Actions/td:SendEmail"
/>
<xs:field
xpath="@id"
/>
</xs:unique>
</xs:element>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Actions actionsType Specifies the actions performed by the


task.

Data dataType Specifies addition data that is


associated with the task, but is
otherwise unused by the Task
Scheduler service.

Principals principalsType Specifies the security contexts that can


be used to run the task.
EL EM EN T TYPE DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Settings settingsType Specifies the settings that the Task


Scheduler uses to perform the task.

Triggers triggersType Specifies the triggers that start the


task.

Remarks
For C++ development, see ITaskDefinition .
For script development, see TaskDefinition .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Thursday (daysOfWeekType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs on Thursday.

<xs:element name="Thursday">
<xs:complexType />
</xs:element>

The Thursday element is defined by the daysOfWeekType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(monthlyDayOfWeekScheduleTyp the task runs for a monthly day-of-
e) week schedule.

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(weeklyScheduleType) the task runs for a weekly schedule.

Examples
The following XML defines a day of week calendar that starts a task on Thursday.

<DaysOfWeek>
<Thursday/>
</DaysOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
TimeTrigger (triggerGroup) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a trigger that starts a task when the trigger is activated.

<xs:element name="TimeTrigger"
type="timeTriggerType"
/>

The TimeTrigger element is defined by the triggerGroup .

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Triggers triggersType Specifies the triggers that start the


task.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Enabled (triggerBaseType) boolean Specifies that the trigger is enabled.

EndBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is deactivated. The trigger
cannot start the task after it is
deactivated.

ExecutionTimeLimit duration Specifies the maximum amount of time


(triggerBaseType) in which the task can be started by the
trigger.

Repetition (triggerBaseType) repetitionType Specifies how often the task is run and
how long the repetition pattern is
repeated after the task is started.

Star tBoundar y (triggerBaseType) dateTime Specifies the date and time when the
trigger is activated. This element is
required.

Attributes
NAME TYPE DESC RIP T IO N

Id string The identifier of the trigger.

Remarks
The Star tBoundar y element is a required element for time and calendar triggers (TimeTrigger and
CalendarTrigger ).
For scripting development, a time trigger is specified using the TimeTrigger object.
For C++ development, a time trigger is specified using the ITimeTrigger interface.
The child elements listed above are defined by the triggerBaseType complex element types. These elements
must be added in the sequence shown below.
Star tBoundar y (triggerBaseType)
EndBoundar y (triggerBaseType)
Enabled (triggerBaseType)
Repetition (triggerBaseType)
ExecutionTimeLimit (triggerBaseType)

Examples
For a complete example of the XML for a task that specifies a time trigger, see Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
Title (showMessageType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the title of the message box.

<xs:element name="Title"
type="nonEmptyString"
/>

The Title element is defined by the showMessageType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ShowMessage (actionGroup) showMessageType Represents an action that shows a


message box.

Remarks
For C++ development, see Title Proper ty of IShowMessageAction .
For script development, see ShowMessageAction.Title .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


To (sendEmailType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the email addresses to which the email will be sent.

<xs:element name="To"
type="string"
/>

The To element is defined by the sendEmailType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SendEmail (actionGroup) sendEMailType Represents an action that sends an


email message.

Remarks
For C++ development, see To Proper ty of IEmailAction .
For script development, see EmailAction.To .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Triggers (taskType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the triggers that start the task.

<xs:element name="Triggers"
type="triggersType"
/>

The Triggers element is defined by the triggersType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Task taskType Defines the task that is performed by


the Task Scheduler service.

Child elements
EL EM EN T TYPE DESC RIP T IO N

BootTrigger bootTriggerType Specifies a trigger that starts a task


when the system is booted.

CalendarTrigger calendarTriggerType Specifies a daily, weekly, monthly, or a


monthly day-of-the-week (DOW)
trigger.

EventTrigger eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

IdleTrigger idleTriggerType Specifies a trigger that starts a task


when the computer goes into an idle
state.

LogonTrigger logonTriggerType Specifies a trigger that starts a task


when a user logs on.

RegistrationTrigger registrationTriggerType Specifies a trigger that starts a task


when the task is registered.

TimeTrigger timeTriggerType Specifies a trigger that starts a task


when the trigger is activated.

Remarks
The child elements listed above can be added in any order.
For C++ development, the triggers of a task are specified using the Triggers proper ty of ITaskDefinition .
For scripting development, the triggers of a task are specified using the TaskDefinition.Triggers property.

Examples
For a complete example of the XML for a task that specifies a trigger, see Time Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Tuesday (daysOfWeekType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs on Tuesday.

<xs:element name="Tuesday">
<xs:complexType />
</xs:element>

The Tuesday element is defined by the daysOfWeekType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(monthlyDayOfWeekScheduleTyp the task runs for a monthly day-of-
e) week schedule.

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(weeklyScheduleType) the task runs for a weekly schedule.

Examples
The following XML defines a day of week calendar that starts a task on Tuesday.

<DaysOfWeek>
<Tuesday/>
</DaysOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
URI (registrationInfoType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the URI of the task. This element is used to specify where the registered task is placed in the task folder
hierarchy.

<xs:element name="URI"
type="anyURI"
minOccurs="0"
/>

The URI element is defined by the registrationInfoType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Remarks
For scripting development, the URI of the task is specified using the RegistrationInfo.URI property.
For C++ development, the URI of the task is specified using the IRegistrationInfo::URI property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
UserId (logonTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Identifier of the user. The task is started when this user logs on to the computer.

<xs:element name="UserId"
type="nonEmptyString"
maxOccurs="1"
minOccurs="0"
/>

The UserId element is defined by the logonTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

LogonTrigger logonTriggerType Specifies a trigger that starts a task


when a user logs on.

Remarks
For scripting development, the user identifier for the logon trigger is specified using the LogonTrigger.UserId
property.
For C++ development, the user identifier for the logon trigger is specified using the ILogonTrigger ::UserId
property.

Examples
For a complete example of the XML for a task that specifies a logon trigger, see Logon Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
UserId (principalType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the user identifier required to run those tasks associated with the principal.

<xs:element name="UserId"
type="nonEmptyString"
/>

The UserId element is defined by the principalType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Principal principalType Specifies the security credentials for a


principal.

Remarks
The UserId element and the LogonType element are used together to define the user required to run those
tasks that use this principal.
You cannot specify a user identifier and a group identifier at the same time. Specify either the UserId or the
GroupId element, but not both.
For scripting development, the user identifier is specified using the Principal.UserId property.
For C++ development, the user identifier is specified using the IPrincipal::UserId property.

Examples
The following XML defines a principle using a user identifier.

<Principal>
<UserId></UserId>
<LogonType><LogonType>
<DisplayName></DisplayName>
</Principal>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
UserId (sessionStateChangeTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the user for the Terminal Server session. When a session state change is detected for this user, a task is
started.

<xs:element name="UserId"
type="nonEmptyString"
maxOccurs="1"
minOccurs="0"
/>

The UserId element is defined by the sessionStateChangeTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

SessionStateChangeTrigger sessionStateChangeTriggerType Specifies a trigger that starts a task


when a Terminal Server session
changes state.

Remarks
For C++ development, see UserId Proper ty of ISessionStateChangeTrigger .
For script development, see SessionStateChangeTrigger.UserId .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


UseUnifiedSchedulingEngine (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the Unified Scheduling Engine will be used to run this task.

<xs:element name="UseUnifiedSchedulingEngine"
type="boolean"
default="false"
minOccurs="0"
/>

The UseUnifiedSchedulingEngine element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
The default setting for this element is False.
For C++ development, this information is accessed through the
ITaskSettings2::UseUnifiedSchedulingEngine property.

Examples
The following XML defines a settings element that specifies that the Unified Scheduling Engine will be used to
run this task.

<Settings>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
</Settings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]

See also
Task Scheduler Schema Elements
ValueQueries (eventTriggerType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains a sequence of elements that each contain a name and an XPath query value. The queries are applied to
an event returned from the event subscription specified in the Subscription element. The name for the XPath
query value can be used as a variable in the action section of a task.

<xs:element name="ValueQueries"
type="namedValues"
minOccurs="0"
/>

The ValueQueries element is defined by the eventTriggerType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

EventTrigger (triggerGroup) eventTriggerType Specifies a trigger that starts a task


when a system event occurs.

Remarks
For C++ development, see ValueQueries Proper ty of IEventTrigger .
For script development, see EventTrigger.ValueQueries .

Examples
For a complete example of the XML for a task that specifies a an event trigger using this element, see Event
Trigger Example (XML).

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Value (headerFieldType) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the value of a header field in an email message.

<xs:element name="Value"
type="string"
/>

The Value element is defined by the headerFieldType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

HeaderField headerFieldType Contains a field for a header in an


email message.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Value (namedValues) Element
8/8/2022 • 2 minutes to read • Edit Online

Contains the value that is associated with a name in a name-value pair.

<xs:element name="Value"
type="namedValue"
minOccurs="1"
maxOccurs="32"
/>

The Value element is defined by the namedValues complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ValueQueries (eventTriggerType) namedValues Specifies a collection of named XPath


queries. Each query in the collection is
applied to the last matching event
XML that is returned from the
subscription query specified in the
Subscription element. The name of
the query can be used as a variable in
the message of a ShowMessage action.

Remarks
For C++ development, see Value Proper ty of ITaskNamedValuePair .
For script development, see TaskNamedValuePair.Value .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


Version (registrationInfoType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the version number of the task.

<xs:element name="Version"
type="string"
minOccurs="0"
/>

The Version element is defined by the registrationInfoType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Remarks
For scripting development, the version of a task is specified using RegistrationInfo.Version property.
For C++ development, the version of a task is specified using IRegistrationInfo::Version property.

Examples
The following XML defines the version of a task.

<RegistrationInfo>
<Version></Version>
</RegistrationInfo>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Volatile Element
8/8/2022 • 2 minutes to read • Edit Online

Indicates whether the task is automatically disabled every time Windows starts.

<xs:element name="Volatile"
type="xsd:boolean"
maxOccurs="1"
minOccurs="0"
default="false"
/>

The Volatile element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
For C++ programming, this idle setting is specified using the ITaskSettings3::Volatile property.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 8 [desktop apps only]

Minimum supported server Windows Server 2012 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
WaitTimeout (idleSettingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the amount of time that the Task Scheduler will wait for an idle condition to occur. If no value is
specified for this element, then the Task Scheduler service will wait indefinitely for an idle condition to occur. The
format for this string is PnYnMnDTnHnMnS, where nY is the number of years, nM is the number of months, nD
is the number of days, 'T' is the date/time separator, nH is the number of hours, nM is the number of minutes,
and nS is the number of seconds (for example, PT5M specifies 5 minutes and P1M4DT2H5M specifies one
month, four days, two hours, and five minutes). For more information about the duration type, see
https://go.microsoft.com/fwlink/p/?linkid=106886. The minimum time allowed is 1 minute.

<xs:element name="WaitTimeout"
default="PT1H"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The element is defined by the idleSettingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

IdleSettings idleSettingsType Specifies how the Task Scheduler


performs tasks when the computer is
in an idle state.

Remarks
For script development, this idle setting is specified using the IdleSettings.WaitTimeout property.
For C++ development, this idle setting is specified using the IIdleSettings::WaitTimeout property.

Examples
The following XML defines an idle setting that waits 24 hours for an idle condition to occur.

<IdleSettings>
<WaitTimeout>PT24H</WaitTimeout>
</IdleSettings>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
WakeToRun (settingsType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that Task Scheduler will wake the computer when it is time to run the task.

<xs:element name="WakeToRun"
type="boolean"
/>

The WakeToRun element is defined by the settingsType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Settings settingsType Contains the settings that the Task


Scheduler uses to perform the task.

Remarks
When the Task Scheduler service wakes the computer to run a task, the screen may remain off even though the
computer is no longer in the sleep or hibernate mode. The screen will turn on when Windows Vista detects that
a user has returned to use the computer.
For C++ development, see WakeToRun Proper ty of ITaskSettings .
For script development, see TaskSettings.WakeToRun .

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Wednesday (daysOfWeekType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies that the task runs on Wednesday.

<xs:element name="Wednesday">
<xs:complexType />
</xs:element>

The Wednesday element is defined by the daysOfWeekType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(monthlyDayOfWeekScheduleTyp the task runs for a monthly day-of-
e) week schedule.

DaysOfWeek daysOfWeekType Specifies the days of the week in which


(weeklyScheduleType) the task runs for a weekly schedule.

Examples
The following XML defines a day of week calendar that starts a task on Wednesday.

<DaysOfWeek>
<Wednesday/>
</DaysOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Week (weeksType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies a specific week of the month.

<xs:element name="Week"
type="weekType"
/>

The Week element is defined by the weeksType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Weeks weeksType Specifies the weeks of the month in


(monthlyDayOfWeekScheduleTyp which the task is run.
e)

Remarks
When specifying the weeks of the month, use the numbers 1-4 for the first four weeks of the month or use the
string "Last" to indicate that last week of the month.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
WeeksInterval (weeklyScheduleType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the interval between the weeks in the schedule.

<xs:element name="WeeksInterval"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="unsignedByte"
>
<xs:minInclusive
value="1"
/>
<xs:maxInclusive
value="52"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>

The element is defined by the weeklyScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ScheduleByWeek weeklyScheduleType Specifies a weekly schedule.

Remarks
For scripting development, the weekly interval is specified using the WeeklyTrigger.WeeksInter val property.
For C++ development, the weekly interval is specified using the IWeeklyTrigger ::WeeksInter val property.

Examples
The following XML defines a weekly calendar trigger that starts a task Monday through Friday ( at 8:00 AM)
every week.
<CalendarTrigger>
<StartBoundary>2005-01-01T08:00:00</StartBoundary>
<EndBounadry>2007-01-01T00:00:00</EndBoundary>
<ScheduleByWeek>
<WeeksInterval>1</WeeksInterval>
<DaysOfWeek>
<Monday/>
<Tuesday/>
<Wednesday/>
<Thurday/>
<Friday/>
</DaysOfWeek>
</ScheduleByWeek>
</CalendarTrigger>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Weeks (monthlyDayOfWeekScheduleType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the weeks of the month in which the task is run.

<xs:element name="Weeks"
type="weeksType"
/>

The Weeks element is defined by the monthlyDayOfWeekScheduleType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

ScheduleByMonthDayOfWeek monthlyDayOfWeekScheduleType Specifies a trigger that starts a job on


a monthly day-of-week schedule.

Child elements
EL EM EN T TYPE DESC RIP T IO N

Week weekType Specifies a specific week of the month.

Remarks
For scripting development, the weeks of the month are specified using the
MonthlyDOWTrigger.WeeksOfMonth property.
For C++ development, the weeks of the month are specified using the
IMonthlyDOWTrigger ::WeeksOfMonth property.
When specifying the weeks of the month, use 1-4 to specify the first four weeks of the month or use the string
"Last" to indicate the last week regardless of which week it is.

Examples
The following XML defines a monthly day-of-week calendar that starts the task on Monday of the first week for
each month of the year.
<ScheduleByMonthDayOfWeek>
<Weeks>
<Week>1</Week>
</Weeks>
<DaysOfWeek>
<Monday/>
</DaysOfWeek>
<Months>
<January/>
<February/>
<March/>
<April/>
<May/>
<June/>
<July/>
<August/>
<September/>
<October/>
<November/>
<December/>
<Months>
</ScheduleByMonthDayOfWeek>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
WorkingDirectory (execType) Element
8/8/2022 • 2 minutes to read • Edit Online

Specifies the directory where either the executable or those files used by the executable exists.

<xs:element name="WorkingDirectory"
type="pathType"
/>

The WorkingDirector y element is defined by the execType complex type.

Parent element
EL EM EN T DERIVED F RO M DESC RIP T IO N

Exec execType Specifies an action that executes a


command-line operation.

Remarks
For script development, the working directory is specified by the ExecAction.WorkingDirector y property.
For C++ development, the working directory is specified by the IExecAction::WorkingDirector y property.

Examples
The following XML defines a execution action.

<Exec>
<Command></Command>
<Arguments></Arguments>
<WorkingDirectory></WorkingDirectory>
</ServiceResume>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Elements
Task Scheduler
Task Scheduler Schema Simple Types
8/8/2022 • 2 minutes to read • Edit Online

This section contains the simple types used to define the child elements and attributes that are used by other
elements. This information is provided for those who want to extend the Task Scheduler schema.
The topics in this section include a description of what the simple type provides to those elements defined by
the type; how the simple type is defined in the XSD, the child elements or attributes it defines; and remarks that
cover special circumstances.
dayOfMonthType
guidType
logonType
multipleInstancesPolicyType
nonEmptyStringType
pathType
priorityType
privilegeType
processTokenSidType
runLevelType
sessionStateChangeType
versionType
weekType
dayOfMonthType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the possible values for specifying a day of the month.

<xs:simpleType name="dayOfMonthType">
<xs:restriction
base="string"
>
<xs:pattern
value="[1-9]|[1-2][0-9]|3[0-1]|Last"
/>
</xs:restriction>
</xs:simpleType>

Patterns
The dayOfMonthType simple type is a string that is restricted by the following pattern:
[1-9]|[1-2][0-9]|3[0-1]|Last

Specifies the 1st through the 31st day of the month, or always the last day of the month.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Simple Types
Task Scheduler
guidType simple type (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

Defines the pattern for valid GUIDs.

<xs:simpleType name="guidType">
<xs:restriction
base="string"
>
<xs:pattern
value="\{([0-9a-fA-F]){8}(\-[0-9a-fA-F]{4}){3}\-[0-9a-fA-F]{12}\}"
/>
</xs:restriction>
</xs:simpleType>

Patterns
The guidType simple type is a string that is restricted by the following pattern:
\{([0-9a-fA-F]){8}(\-[0-9a-fA-F]{4}){3}\-[0-9a-fA-F]{12}\}

A unique 128-bit number.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Simple Types
Task Scheduler
logonType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the possible values of the LogonType element.

<xs:simpleType name="logonType">
<xs:restriction
base="string"
>
<xs:enumeration
value="S4U"
/>
<xs:enumeration
value="Password"
/>
<xs:enumeration
value="InteractiveToken"
/>
<xs:enumeration
value="InteractiveTokenOrPassword"
/>
</xs:restriction>
</xs:simpleType>

Enumeration values
The logonType simple type defines the following values.

VA L UE DESC RIP T IO N

S4U User must log on using a service for user (S4U) logon. When
an S4U logon is used, no password is stored by the system
and there is no access to either the network or encrypted
files.

Password User must log on using a password.

InteractiveToken User must already be logged on. The task will be run only in
an existing interactive session.

InteractiveTokenOrPassword No longer in use; currently identical to Password.


Windows 10, version 1511, Windows 10, version
1507, Windows 8.1, Windows Ser ver 2012 R2,
Windows 8, Windows Ser ver 2012, Windows Vista
and Windows Ser ver 2008: The task will be run in an
existing interactive session or the user must log on using a
password.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Simple Types
Task Scheduler
multipleInstancesPolicyType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the instance policy constants for the MultipleInstancesPolicy (settingsType) element.

<xs:simpleType name="multipleInstancesPolicyType">
<xs:restriction
base="string"
>
<xs:enumeration
value="Parallel"
/>
<xs:enumeration
value="Queue"
/>
<xs:enumeration
value="IgnoreNew"
/>
<xs:enumeration
value="StopExisting"
/>
</xs:restriction>
</xs:simpleType>

Enumeration values
The multipleInstancesPolicyType simple type defines the following values.

VA L UE DESC RIP T IO N

Parallel Starts new instance while an existing instance is running.

Queue Starts new instance of task after all other instances of the
task are complete.

IgnoreNew Default. Does not start new instance if an existing instance


of the task is running.

StopExisting Stops an existing instance of the task before it starts new


instance.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Simple Types
Task Scheduler
nonEmptyStringType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the values used for a non-empty string of text.

<xs:simpleType name="nonEmptyString">
<xs:restriction
base="string"
>
<xs:enumeration
value="1"
/>
</xs:restriction>
</xs:simpleType>

Enumeration values
The nonEmptyString simple type defines the following value.

VA L UE DESC RIP T IO N

1 The string contains at least one character.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


pathType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the minimum and maximum number of characters for a string that defines a file path. The path cannot
be an empty string, and must be less than 260 characters.

<xs:simpleType name="pathType">
<xs:restriction
base="nonEmptyString"
>
<xs:maxLength
value="260"
/>
</xs:restriction>
</xs:simpleType>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


priorityType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the minimum and maximum values for the Priority (settingsType) element.

<xs:simpleType name="priorityType">
<xs:restriction
base="byte"
>
<xs:enumeration
value="0"
/>
<xs:enumeration
value="10"
/>
</xs:restriction>
</xs:simpleType>

Enumeration values
The priorityType simple type defines the following values.

VA L UE DESC RIP T IO N

0 Minimum integer allowed.

10 Maximum integer allowed.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Simple Types
Task Scheduler
privilegeType Simple Type
8/8/2022 • 5 minutes to read • Edit Online

Privileges determine the type of system operations that a user account can perform. An administrator assigns
privileges to user and group accounts. Each user's privileges include those granted to the user and to the groups
to which the user belongs.

<xs:simpleType name="privilegeType">
<xs:restriction
base="string"
>
<xs:enumeration
value="SeCreateTokenPrivilege"
/>
<xs:enumeration
value="SeAssignPrimaryTokenPrivilege"
/>
<xs:enumeration
value="SeLockMemoryPrivilege"
/>
<xs:enumeration
value="SeIncreaseQuotaPrivilege"
/>
<xs:enumeration
value="SeUnsolicitedInputPrivilege"
/>
<xs:enumeration
value="SeMachineAccountPrivilege"
/>
<xs:enumeration
value="SeTcbPrivilege"
/>
<xs:enumeration
value="SeSecurityPrivilege"
/>
<xs:enumeration
value="SeTakeOwnershipPrivilege"
/>
<xs:enumeration
value="SeLoadDriverPrivilege"
/>
<xs:enumeration
value="SeSystemProfilePrivilege"
/>
<xs:enumeration
value="SeSystemtimePrivilege"
/>
<xs:enumeration
value="SeProfileSingleProcessPrivilege"
/>
<xs:enumeration
value="SeIncreaseBasePriorityPrivilege"
/>
<xs:enumeration
value="SeCreatePagefilePrivilege"
/>
<xs:enumeration
value="SeCreatePermanentPrivilege"
/>
<xs:enumeration
value="SeBackupPrivilege"
/>
/>
<xs:enumeration
value="SeRestorePrivilege"
/>
<xs:enumeration
value="SeShutdownPrivilege"
/>
<xs:enumeration
value="SeDebugPrivilege"
/>
<xs:enumeration
value="SeAuditPrivilege"
/>
<xs:enumeration
value="SeSystemEnvironmentPrivilege"
/>
<xs:enumeration
value="SeChangeNotifyPrivilege"
/>
<xs:enumeration
value="SeRemoteShutdownPrivilege"
/>
<xs:enumeration
value="SeUndockPrivilege"
/>
<xs:enumeration
value="SeSyncAgentPrivilege"
/>
<xs:enumeration
value="SeEnableDelegationPrivilege"
/>
<xs:enumeration
value="SeManageVolumePrivilege"
/>
<xs:enumeration
value="SeImpersonatePrivilege"
/>
<xs:enumeration
value="SeCreateGlobalPrivilege"
/>
<xs:enumeration
value="SeTrustedCredManAccessPrivilege"
/>
<xs:enumeration
value="SeRelabelPrivilege"
/>
<xs:enumeration
value="SeIncreaseWorkingSetPrivilege"
/>
<xs:enumeration
value="SeTimeZonePrivilege"
/>
<xs:enumeration
value="SeCreateSymbolicLinkPrivilege"
/>
</xs:restriction>
</xs:simpleType>

Enumeration values
The privilegeType simple type defines the following values.

VA L UE DESC RIP T IO N
VA L UE DESC RIP T IO N

SeCreateTokenPrivilege Required to create a primary token. User Right: Create a


token object.

SeAssignPrimaryTokenPrivilege Required to assign the primary token of a process. User


Right: Replace a process-level token.

SeLockMemoryPrivilege Required to lock physical pages in memory. User Right: Lock


pages in memory.

SeIncreaseQuotaPrivilege Required to increase the quota assigned to a process. User


Right: Adjust memory quotas for a process.

SeUnsolicitedInputPrivilege Required to read unsolicited input from a terminal device.


User Right: Not applicable.

SeMachineAccountPrivilege Required to create a computer account. User Right: Add


workstations to domain.

SeTcbPrivilege This privilege identifies its holder as part of the trusted


computer base. Some trusted protected subsystems are
granted this privilege. User Right: Act as part of the
operating system.

SeSecurityPrivilege Required to perform a number of security-related functions,


such as controlling and viewing audit messages. This
privilege identifies its holder as a security operator. User
Right: Manage auditing and the security log.

SeTakeOwnershipPrivilege Required to take ownership of an object without being


granted discretionary access. This privilege allows the owner
value to be set only to those values that the holder may
legitimately assign as the owner of an object. User Right:
Take ownership of files or other objects.

SeLoadDriverPrivilege Required to load or unload a device driver. User Right: Load


and unload device drivers.

SeSystemProfilePrivilege Required to gather profiling information for the entire


system. User Right: Profile system performance.

SeSystemtimePrivilege Required to modify the system time. User Right: Change the
system time.

SeProfileSingleProcessPrivilege Required to gather profiling information for a single process.


User Right: Profile single process.

SeIncreaseBasePriorityPrivilege Required to increase the base priority of a process. User


Right: Increase scheduling priority.

SeCreatePagefilePrivilege Required to create a paging file. User Right: Create a pagefile.

SeCreatePermanentPrivilege Required to create a permanent object. User Right: Create


permanent shared objects.
VA L UE DESC RIP T IO N

SeBackupPrivilege Required to perform backup operations. This privilege causes


the system to grant all read access control to any file,
regardless of the access control list (ACL) specified for the
file. Any access request other than read is still evaluated with
the ACL. This privilege is required by the RegSaveKey and
RegSaveKeyExfunctions. The following access rights are
granted if this privilege is held: READ_CONTROL,
ACCESS_SYSTEM_SECURITY, FILE_GENERIC_READ,
FILE_TRAVERSE. User Right: Back up files and directories.

SeRestorePrivilege Required to perform restore operations. This privilege causes


the system to grant all write access control to any file,
regardless of the ACL specified for the file. Any access
request other than write is still evaluated with the ACL.
Additionally, this privilege enables you to set any valid user
or group security identifier (SID) as the owner of a file. This
privilege is required by the RegLoadKey function. The
following access rights are granted if this privilege is held:
WRITE_DAC, WRITE_OWNER, ACCESS_SYSTEM_SECURITY,
FILE_GENERIC_WRITE, FILE_ADD_FILE,
FILE_ADD_SUBDIRECTORY, DELETE. User Right: Restore files
and directories.

SeShutdownPrivilege Required to shut down a local system. User Right: Shut down
the system.

SeDebugPrivilege Required to debug and adjust the memory of a process


owned by another account. User Right: Debug programs.

SeAuditPrivilege Required to generate audit-log entries. Give this privilege to


secure servers. User Right: Generate security audits.

SeSystemEnvironmentPrivilege Required to modify the nonvolatile RAM of systems that use


this type of memory to store configuration information. User
Right: Modify firmware environment values.

SeChangeNotifyPrivilege Required to receive notifications of changes to files or


directories. This privilege also causes the system to skip all
traversal access checks. It is enabled by default for all users.
User Right: Bypass traverse checking.

SeRemoteShutdownPrivilege Required to shut down a system by using a network request.


User Right: Force shutdown from a remote system.

SeUndockPrivilege Required to undock a laptop. User Right: Remove computer


from docking station.

SeSyncAgentPrivilege Required for a domain controller to use the LDAP directory


synchronization services. This privilege allows the holder to
read all objects and properties in the directory, regardless of
the protection on the objects and properties. By default, it is
assigned to the Administrator and LocalSystem accounts on
domain controllers. User Right: Synchronize directory service
data.
VA L UE DESC RIP T IO N

SeEnableDelegationPrivilege Required to mark user and computer accounts as trusted for


delegation. User Right: Enable computer and user accounts
to be trusted for delegation.

SeManageVolumePrivilege Required to enable volume management privileges. User


Right: Manage the files on a volume.

SeImpersonatePrivilege Required to impersonate. User Right: Impersonate a client


after authentication. Windows XP/2000: This privilege is not
supported.
Note that this value is supported starting with Windows
Server 2003, Windows XP with SP2, and Windows 2000 with
SP4.

SeCreateGlobalPrivilege Required to create named file mapping objects in the global


namespace during Terminal Services sessions. This privilege is
enabled by default for administrators, services, and the local
system account. User Right: Create global objects. Windows
XP/2000: This privilege is not supported.
Note that this value is supported starting with Windows
Server 2003, Windows XP with SP2, and Windows 2000 with
SP4.

SeTrustedCredManAccessPrivilege Required to access Credential Manager as a trusted caller.


User Right: Access Credential Manager as a trusted caller.

SeRelabelPrivilege Required to modify the mandatory integrity level of an


object. User Right: Modify an object label.

SeIncreaseWorkingSetPrivilege Required to allocate more memory for applications that run


in the context of users. User Right: Increase a process
working set.

SeTimeZonePrivilege Required to adjust the time zone associated with the


computer's internal clock. User Right: Change the time zone.

SeCreateSymbolicLinkPrivilege Required to create a symbolic link. User Right: Create


symbolic links.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]


processTokenSidType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the possible values for the ProcessTokenSidType (principalType) element.

<xs:simpleType name="processTokenSidType">
<xs:restriction
base="string"
>
<xs:enumeration
value="None"
/>
<xs:enumeration
value="Unrestricted"
/>
</xs:restriction>
</xs:simpleType>

Enumeration values
The processTokenSidType simple type defines the following values.

VA L UE DESC RIP T IO N

None Tasks are run in a process that does not contain a process
token SID (no changes will be made to the process token
groups list).

Unrestricted A task SID will be derived from the full task path and will be
added to the process token groups list.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]


runLevelType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the possible values for the RunLevel (principalType) element.

<xs:simpleType name="runLevelType">
<xs:restriction
base="string"
>
<xs:enumeration
value="LeastPrivilege"
/>
<xs:enumeration
value="HighestAvailable"
/>
</xs:restriction>
</xs:simpleType>

Enumeration values
The runLevelType simple type defines the following values.

VA L UE DESC RIP T IO N

LeastPrivilege Tasks are run with the least privileges (LUA).

HighestAvailable Tasks are run with the highest privileges.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


sessionStateChangeType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines values for the kind of Terminal Server session state change you can use to trigger a task to start.

<xs:simpleType name="sessionStateChangeType">
<xs:restriction
base="string"
>
<xs:enumeration
value="ConsoleConnect"
/>
<xs:enumeration
value="ConsoleDisconnect"
/>
<xs:enumeration
value="RemoteConnect"
/>
<xs:enumeration
value="RemoteDisconnect"
/>
<xs:enumeration
value="SessionLock"
/>
<xs:enumeration
value="SessionUnlock"
/>
</xs:restriction>
</xs:simpleType>

Enumeration values
The sessionStateChangeType simple type defines the following values.

VA L UE DESC RIP T IO N

ConsoleConnect Terminal Server console connection state change. For


example, when you connect to a user session on the local
computer by switching users on the computer.

ConsoleDisconnect Terminal Server console disconnection state change. For


example, when you disconnect to a user session on the local
computer by switching users on the computer.

RemoteConnect Terminal Server remote connection state change. For


example, when a user connects to a user session by using
the Remote Desktop Connection program from a remote
computer.

RemoteDisconnect Terminal Server remote disconnection state change. For


example, when a user disconnects from a user session while
using the Remote Desktop Connection program from a
remote computer.
VA L UE DESC RIP T IO N

SessionLock Terminal Server session locked state change. For example,


this state change causes the task to run when the computer
is locked.

SessionUnlock Terminal Server session unlocked state change. For example,


this state change causes the task to run when the computer
is unlocked.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


versionType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines a pattern that specifies a version of a task.

<xs:simpleType name="versionType">
<xs:restriction
base="string"
>
<xs:pattern
value="\d+(\.\d+){1,3}"
/>
</xs:restriction>
</xs:simpleType>

Patterns
The versionType simple type is a string that is restricted by the following pattern:
\d+(\.\d+){1,3}

A double followed by one, two, or three doubles. For example, 1.2, or 1.2.3.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


weekType Simple Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the values that can be used in the Week element.

<xs:simpleType name="weekType">
<xs:restriction
base="string"
>
<xs:pattern
value="[1-4]|Last"
/>
</xs:restriction>
</xs:simpleType>

Patterns
The weekType simple type is a string that is restricted by the following pattern:
[1-4]|Last

Specifies the first through the fourth week of the month (1-4) or always the last week of the month.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Simple Types
Task Scheduler
Task Scheduler Schema Complex Types
8/8/2022 • 2 minutes to read • Edit Online

This section contains the complex types used to define the child elements and attributes used by other elements.
This information is provided for those who want to extend the Task Scheduler schema.
The topics in this section include a description of what the complex type provides to those elements defined by
the type; how the complex type is defined in the XSD; the child elements or attributes it defines; and remarks
that cover special circumstances.
actionBaseType
actionsType
attachmentsType
bootTriggerType
calendarTriggerType
comHandlerType
dailyScheduleType
dataType
daysOfMonthType
daysOfWeekType
eventTriggerType
execType
headerFieldsType
headerFieldType
idleSettingsType
idleTriggerType
logonTriggerType
monthlyDayOfWeekScheduleType
monthlyScheduleType
monthsType
namedValues
networkSettingsType
namedValue
principalsType
principalType
registrationInfoType
registrationTriggerType
repetitionType
requiredPrivilegesType
restar tType
sendMailType
sessionStateChangeTriggerType
settingsType
showMessageType
taskType
timeTriggerType
triggerBaseType
triggersType
weeklyScheduleType
weeksType

Related topics
Task Scheduler Reference
Task Scheduler
actionBaseType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the Id attribute for all elements of this type.

<xs:complexType name="actionBaseType"
abstract="true"
>
<xs:attribute name="id"
type="ID"
use="optional"
/>
</xs:complexType>

Attributes
NAME TYPE DESC RIP T IO N

id ID Id of the action performed by the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
actionsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and attribute for the Actions element.

<xs:complexType name="actionsType">
<xs:sequence>
<xs:group
maxOccurs="32"
ref="actionGroup"
/>
</xs:sequence>
<xs:attribute name="Context"
type="IDREF"
use="optional"
/>
</xs:complexType>

Attributes
NAME TYPE DESC RIP T IO N

Context IDREF Principal identifier of the used who is


the security context for the actions of
the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
attachmentsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the elements used to specify an attachment sent with an email message.

<xs:complexType name="attachmentsType">
<xs:sequence>
<xs:element name="File"
type="nonEmptyString"
minOccurs="0"
maxOccurs="8"
/>
</xs:sequence>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

File nonEmptyString Specifies the path to a file that is sent


as an attachment in an email message.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


bootTriggerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child element and sequencing information for the BootTrigger element.

<xs:complexType name="bootTriggerType">
<xs:complexContent>
<xs:extension
base="triggerBaseType"
>
<xs:sequence>
<xs:element name="Delay"
type="duration"
default="PT0M"
minOccurs="0"
/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay duration Amount of time between when the


system is booted and when the trigger
is fired.

Remarks
In addition to the child element defined here, the BootTrigger element also uses child elements defined by the
triggerBaseType complex type.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
calendarTriggerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for calendar elements.

<xs:complexType name="calendarTriggerType">
<xs:complexContent>
<xs:extension
base="triggerBaseType"
>
<xs:sequence>
<xs:element name="RandomDelay"
type="duration"
default="PT0M"
minOccurs="0"
/>
<xs:choice>
<xs:element name="ScheduleByDay"
type="dailyScheduleType"
/>
<xs:element name="ScheduleByWeek"
type="weeklyScheduleType"
/>
<xs:element name="ScheduleByMonth"
type="monthlyScheduleType"
/>
<xs:element name="ScheduleByMonthDayOfWeek"
type="monthlyDayOfWeekScheduleType"
/>
</xs:choice>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

RandomDelay duration Contains the delay time that is


randomly added to the start time of
the trigger. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S
(for example, P2DT5S is a 2 day, 5
second delay).

ScheduleByDay dailyScheduleType Specifies a daily schedule. For example,


the task starts every day, every-other
day, every third day, and so on.

ScheduleByMonth monthlyScheduleType Specifies a monthly schedule. For


example, the task starts at 8:00 AM on
specific days of the month on specific
months.
EL EM EN T TYPE DESC RIP T IO N

ScheduleByMonthDayOfWeek monthlyDayOfWeekScheduleType Specifies a trigger that starts a job on


a monthly day-of-week schedule. For
example, the task starts on specific
days of the week, weeks of the month,
and months of the year.

ScheduleByWeek weeklyScheduleType Specifies a weekly schedule. For


example, the task starts at 8:00 AM on
a specific day of the week every week
or on a specific day of the week every
other week.

Remarks
In addition to the child element defined here, the CalendarTrigger element also uses the child elements
defined by the triggerBaseType complex type.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
comHandlerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the ComHandler element.

<xs:complexType name="comHandlerType">
<xs:complexContent>
<xs:extension
base="actionBaseType"
>
<xs:all>
<xs:element name="ClassId"
type="guidType"
/>
<xs:element name="Data"
type="dataType"
minOccurs="0"
/>
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

ClassId guidType Specifies the identifier of the handler


class.

Data dataType Specifies additional data associated


with the handler.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
dailyScheduleType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the ScheduleByDay element.

<xs:complexType name="dailyScheduleType">
<xs:all>
<xs:element name="DaysInterval"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="unsignedInt"
>
<xs:minInclusive
value="1"
/>
<xs:maxInclusive
value="365"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

DaysInter val Specifies the interval between the days


in the schedule.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
dataType complex type (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

Defines a base type.

<xs:complexType name="dataType">
<xs:sequence>
<xs:any
namespace=""
/>
</xs:sequence>
</xs:complexType>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
daysOfMonthType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child element and sequencing information for the DaysOfMonth (monthlyScheduleType)
element.

<xs:complexType name="daysOfMonthType">
<xs:sequence>
<xs:element name="Day"
type="dayOfMonthType"
minOccurs="0"
maxOccurs="32"
/>
</xs:sequence>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Day dayOfMonthType Specifies a day of the month during


which the task runs.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
daysOfWeekType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the DaysOfWeek (weeklyScheduleType) and
DaysOfWeek (monthlyDayOfWeekScheduleType) elements.

<xs:complexType name="daysOfWeekType">
<xs:all>
<xs:element name="Monday"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="Tuesday"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="Wednesday"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="Thursday"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="Friday"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="Saturday"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="Sunday"
minOccurs="0"
>
<xs:complexType />
</xs:element>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Friday N/A Task runs on Friday.

Monday N/A Task runs on Monday.

Saturday N/A Task runs on Saturday.


EL EM EN T TYPE DESC RIP T IO N

Sunday N/A Task runs on Sunday.

Thursday N/A Task runs on Thursday

Tuesday N/A Task runs on Tuesday.

Wednesday N/A Task runs on Wednesday.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
eventTriggerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the EventTrigger element.

<xs:complexType name="eventTriggerType">
<xs:complexContent>
<xs:extension
base="triggerBaseType"
>
<xs:sequence>
<xs:element name="Subscription"
type="nonEmptyString"
/>
<xs:element name="Delay"
type="duration"
default="PT0M"
minOccurs="0"
/>
<xs:element name="ValueQueries"
type="namedValues"
minOccurs="0"
/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay duration Specifies the amount of time between


when the event occurs and when the
task is started.

Subscription nonEmptyString Specifies the XPath query that


identifies the event that fires the
trigger.

ValueQueries namedValues Specifies a sequence of elements that


each contain a name and an XPath
query value. The queries are applied to
an event returned from the event
subscription specified in the
Subscription element. The name for
the XPath query value can be used as
a variable in the Body element in the
ShowMessage action section of a
task.

Remarks
In addition to the child element defined here, the EventTrigger element also uses child elements defined by the
triggerBaseType complex type.
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
execType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information of the Exec (actionGroup) element.

<xs:complexType name="execType">
<xs:complexContent>
<xs:extension
base="actionBaseType"
>
<xs:all>
<xs:element name="Command"
type="pathType"
/>
<xs:element name="Arguments"
type="string"
minOccurs="0"
/>
<xs:element name="WorkingDirectory"
type="pathType"
minOccurs="0"
/>
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Arguments string Specifies the arguments associated


with the command-line operation.

Command pathType Specifies the executable file or


document to be run.

WorkingDirector y pathType Specifies the directory where either the


executable or those files used by the
executable exists.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
headerFieldsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the elements that specify the fields for an email header.

<xs:complexType name="headerFieldsType">
<xs:sequence>
<xs:element name="HeaderField"
type="headerFieldType"
minOccurs="0"
maxOccurs="32"
/>
</xs:sequence>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

HeaderField headerFieldType Specifies a field in an email header.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


headerFieldType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the elements that are used to create a header field in an email message.

<xs:complexType name="headerFieldType">
<xs:all>
<xs:element name="Name"
type="nonEmptyString"
/>
<xs:element name="Value"
type="string"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Name nonEmptyString Specifies the name of the header field


in an email message.

Value string Specifies the value of a header field in


an email message.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


idleSettingsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the IdleSettings (settingsType) element.

<xs:complexType name="idleSettingsType">
<xs:all>
<xs:element name="Duration"
default="PT10M"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="WaitTimeout"
default="PT1H"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="StopOnIdleEnd"
type="boolean"
default="true"
minOccurs="0"
/>
<xs:element name="RestartOnIdle"
type="boolean"
default="false"
minOccurs="0"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Duration Specifies the amount of time allowed


to start the task while in an idle
condition.
EL EM EN T TYPE DESC RIP T IO N

Restar tOnIdle boolean The task is restarted as soon as an idle


condition starts.

StopOnIdleEnd boolean Specifies that the task is terminated if


the idle condition ends before the idle
duration is exceeded.

WaitTimeout Specifies the amount of time to wait


for an idle condition to start. If no
value is specified for this element, then
the Task Scheduler service will wait
indefinitely for an idle condition to
occur.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
idleTriggerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the base type for the IdleTrigger element.

<xs:complexType name="idleTriggerType">
<xs:complexContent>
<xs:extension
base="triggerBaseType"
/>
</xs:complexContent>
</xs:complexType>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
logonTriggerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the LogonTrigger element.

<xs:complexType name="logonTriggerType">
<xs:complexContent>
<xs:extension
base="triggerBaseType"
>
<xs:sequence>
<xs:element name="UserId"
type="nonEmptyString"
minOccurs="0"
/>
<xs:element name="Delay"
type="duration"
default="PT0M"
minOccurs="0"
/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay duration Amount of time between when the


user logs on and when the task is
started.

UserId nonEmptyString Identifier of the user. The task is


started when this user logs onto the
computer.

Remarks
In addition to the child elements defined here, the LogonTrigger element also uses child elements defined by
the triggerBaseType complex type.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
maintenanceSettingsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the MaintenanceSettings element.

<xs:complexType name="maintenanceSettingsType">
<xs:all>
<xs:element name="Period"
minOccurs="1"
maxOccurs="1"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="P1D"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Deadline"
minOccurs="1"
maxOccurs="1"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="P1D"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Exclusive"
type="boolean"
maxOccurs="1"
minOccurs="1"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Deadline Specifies the amount of time after


which the Task scheduler will attempt
to start task during emergency
Automatic maintenance, if it failed to
complete during regular maintenance.

Exclusive boolean If set to true, the task will be started


exclusively among other maintenance
tasks.
EL EM EN T TYPE DESC RIP T IO N

Period Specifies how often the task needs to


be started during Automatic
maintenance.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 8 [desktop apps only]

Minimum supported server Windows Server 2012 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
monthlyDayOfWeekScheduleType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the ScheduleByMonthDayOfWeek element.

<xs:complexType name="monthlyDayOfWeekScheduleType">
<xs:all>
<xs:element name="Weeks"
type="weeksType"
minOccurs="0"
/>
<xs:element name="DaysOfWeek"
type="daysOfWeekType"
/>
<xs:element name="Months"
type="monthsType"
minOccurs="0"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week during


which the task runs.

Months monthsType Specifies the months of the year


during which the task runs.

Weeks weeksType Specifies the weeks of the month


during which the task runs.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
monthlyScheduleType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the ScheduleByMonth (calendarTriggerType)
element.

<xs:complexType name="monthlyScheduleType">
<xs:all>
<xs:element name="DaysOfMonth"
type="daysOfMonthType"
minOccurs="0"
/>
<xs:element name="Months"
type="monthsType"
minOccurs="0"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

DaysOfMonth daysOfMonthType Specifies the days of the month during


which the task runs.

Months monthsType Specifies the months of the year


during which the task runs for a
monthly schedule.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
monthsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the Months (monthlyDayOfWeekScheduleType)
and Months (monthlyScheduleType) elements.
<xs:complexType name="monthsType">
<xs:all>
<xs:element name="January"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="February"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="March"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="April"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="May"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="June"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="July"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="August"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="September"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="October"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="November"
minOccurs="0"
>
<xs:complexType />
</xs:element>
<xs:element name="December"
minOccurs="0"
>
<xs:complexType />
</xs:element>
</xs:all>
</xs:complexType>
Child elements
EL EM EN T TYPE DESC RIP T IO N

April N/A Specifies that the task runs in April.

August N/A Specifies that the task runs in August.

December N/A Specifies that the task runs in


December.

Februar y N/A Specifies that the task runs in


February.

Januar y N/A Specifies that the task runs in January.

July N/A Specifies that the task runs in July.

June N/A Specifies that the task runs in June.

March N/A Specifies that the task runs in March.

May N/A Specifies that the task runs in May.

November N/A Specifies that the task runs in


November.

October N/A Specifies that the task runs in October.

September N/A Specifies that the task runs in


September.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
namedValues Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines a name-value pair in which the name is associated with the value.

<xs:complexType name="namedValues">
<xs:sequence>
<xs:element name="Value"
type="namedValue"
minOccurs="1"
maxOccurs="32"
/>
</xs:sequence>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Value namedValue Specifies the value that is associated


with a name in a name-value pair.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


namedValue Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines a name that is associated with a value in a name-value pair.

<xs:complexType name="namedValue">
<xs:simpleContent>
<xs:extension
base="nonEmptyString"
>
<xs:attribute name="name"
type="nonEmptyString"
use="required"
/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>

Attributes
NAME TYPE DESC RIP T IO N

name nonEmptyString Specifies the name that is associated


with a value in a name-value pair.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


networkSettingsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the elements that provide the settings that the Task Scheduler service uses to obtain a network profile.

<xs:complexType name="networkSettingsType">
<xs:all>
<xs:element name="Name"
type="nonEmptyString"
minOccurs="0"
/>
<xs:element name="Id"
type="guidType"
minOccurs="0"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Id guidType Specifies a GUID value that identifies a


network profile.

Name nonEmptyString Specifies the name of a network profile.


The name is used for display purposes.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


principalsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child element for the Principals element.

<xs:complexType name="principalsType">
<xs:sequence>
<xs:element name="Principal"
type="principalType"
maxOccurs="1"
/>
</xs:sequence>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Principal principalType Specifies the security credentials for a


principal.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


principalType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the attribute, child elements, and sequencing information for the Principal element.

<xs:complexType name="principalType">
<xs:all>
<xs:element name="UserId"
type="nonEmptyString"
minOccurs="0"
/>
<xs:element name="LogonType"
type="logonType"
minOccurs="0"
maxOccurs="1"
/>
<xs:element name="GroupId"
type="nonEmptyString"
minOccurs="0"
/>
<xs:element name="DisplayName"
type="string"
minOccurs="0"
/>
<xs:element name="RunLevel"
type="runLevelType"
minOccurs="0"
/>
<xs:element name="ProcessTokenSidType"
type="processTokenSidType"
minOccurs="0"
maxOccurs="1"
/>
<xs:element name="RequiredPrivileges"
type="requiredPrivilegesType"
minOccurs="0"
/>
</xs:all>
<xs:attribute name="id"
type="ID"
use="optional"
/>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

DisplayName string Specifies the name of the principal that


is displayed in the Task Scheduler user
interface (UI).

GroupId nonEmptyString Specifies the identifier of the user


group that is required to run tasks
that are associated with the principal.
EL EM EN T TYPE DESC RIP T IO N

LogonType logonType Specifies the security logon method


that is required to run tasks that are
associated with the principal.

ProcessTokenSidType processTokenSidType Specifies the types of process security


identifier (SID) that can be used by
tasks.

RequiredPrivileges requiredPrivilegesType Specifies the required privileges to run


the task.

RunLevel runLevelType Specifies the permission level that the


task will be run at.

UserId nonEmptyString Specifies the user identifier that is


required to run tasks that are
associated with the principal.

Attributes
NAME TYPE DESC RIP T IO N

id ID Specifies the identifier of the principal.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
registrationInfoType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the RegistrationInfo element.

<xs:complexType name="registrationInfoType">
<xs:all>
<xs:element name="URI"
type="anyURI"
minOccurs="0"
/>
<xs:element name="SecurityDescriptor"
type="string"
minOccurs="0"
/>
<xs:element name="Source"
type="string"
minOccurs="0"
/>
<xs:element name="Date"
type="dateTime"
minOccurs="0"
/>
<xs:element name="Author"
type="string"
minOccurs="0"
/>
<xs:element name="Version"
type="string"
minOccurs="0"
/>
<xs:element name="Description"
type="string"
minOccurs="0"
/>
<xs:element name="Documentation"
type="string"
minOccurs="0"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Author string Specifies the author of the task.

Date dateTime Specifies the date and time when the


task is registered.

Description string Specifies the description of the task.

Documentation string Specifies any additional documentation


for the task.
EL EM EN T TYPE DESC RIP T IO N

SecurityDescriptor string Specifies the security descriptor of the


task.

Source string Specifies where the task originated


from. For example, from a component,
service, application, or user.

URI anyURI Specifies the URI of the task.

Version string Specifies the version number of the


task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
registrationTriggerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines child elements and sequencing information for the RegistrationTrigger element.

<xs:complexType name="registrationTriggerType">
<xs:complexContent>
<xs:extension
base="triggerBaseType"
>
<xs:sequence>
<xs:element name="Delay"
type="duration"
default="PT0M"
minOccurs="0"
/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay duration Specifies the amount of time between


when the task is registered and when
the task is started.

Remarks
In addition to the child elements defined here, the RegistrationTrigger element also uses child elements
defined by the triggerBaseType complex type.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
repetitionType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequence information for the Repetition (triggerBaseType) element.

<xs:complexType name="repetitionType">
<xs:all>
<xs:element name="Interval">
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
<xs:maxInclusive
value="P31D"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Duration"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="StopAtDurationEnd"
type="boolean"
default="false"
minOccurs="0"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Duration Specifies how long the pattern is


repeated. If no value is specified, the
pattern is repeated indefinitely.

Inter val Specifies the amount of time between


each restart of the task.

StopAtDurationEnd boolean Specifies that a running instance of the


task is stopped at the end of the
repetition pattern duration.
Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
requiredPrivilegesType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the RequiredPrivileges
(requiredPrivilegesType) element.

<xs:complexType name="requiredPrivilegesType">
<xs:all>
<xs:element name="Privilege"
type="privilegeType"
minOccurs="1"
maxOccurs="64"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Privilege privilegeType Specifies the required privileges of the


task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows 7 [desktop apps only]

Minimum supported server Windows Server 2008 R2 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
restartType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequence information for the RestartOnFailure element.

<xs:complexType name="restartType">
<xs:all>
<xs:element name="Interval">
<xs:simpleType>
<xs:restriction
base="duration"
>
<xs:minInclusive
value="PT1M"
/>
<xs:maxInclusive
value="P31D"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Count">
<xs:simpleType>
<xs:restriction
base="unsignedByte"
>
<xs:minInclusive
value="1"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Count Number of attempts to restart the


task.

Inter val How long to try to start the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
sendEmailType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the action type used to specify that an email will be sent when a task executes. This type defines all the
elements used to model the email message.

<xs:complexType name="sendEmailType">
<xs:complexContent>
<xs:extension
base="actionBaseType"
>
<xs:all>
<xs:element name="Server"
type="nonEmptyString"
/>
<xs:element name="Subject"
type="string"
minOccurs="0"
/>
<xs:element name="To"
type="string"
minOccurs="0"
/>
<xs:element name="Cc"
type="string"
minOccurs="0"
/>
<xs:element name="Bcc"
type="string"
minOccurs="0"
/>
<xs:element name="ReplyTo"
type="string"
minOccurs="0"
/>
<xs:element name="From"
type="string"
minOccurs="0"
/>
<xs:element name="HeaderFields"
type="headerFieldsType"
minOccurs="0"
/>
<xs:element name="Body"
type="string"
minOccurs="0"
/>
<xs:element name="Attachments"
type="attachmentsType"
minOccurs="0"
/>
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Attachments attachmentsType Specifies a list of attachments in the


email message.

Bcc string Specifies the email addresses used on


the Bcc line of an email message.

Body string Specifies the text in the body of the


email message.

Cc string Specifies the email addresses used on


the Cc line of an email message.

From string Specifies the email address of the


sender.

HeaderFields headerFieldsType Specifies the header fields and their


values used in the header of the email
message.

ReplyTo string Specifies the email addresses that are


replied to in the email message.

Ser ver nonEmptyString Specifies the email server used to send


the email message.

Subject string Specifies the subject of the email


message.

To string Specifies the email addresses to which


the email will be sent.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


sessionStateChangeTriggerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the elements used to create a task trigger for console connect or disconnect, remote connect or
disconnect, or workstation lock or unlock notifications.

<xs:complexType name="sessionStateChangeTriggerType">
<xs:complexContent>
<xs:extension
base="triggerBaseType"
>
<xs:sequence>
<xs:element name="UserId"
type="nonEmptyString"
minOccurs="0"
/>
<xs:element name="Delay"
type="duration"
default="PT0M"
minOccurs="0"
/>
<xs:element name="StateChange"
type="sessionStateChangeType"
minOccurs="1"
maxOccurs="1"
/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Delay duration Specifies a value that indicates the


length of the delay before a task is
started when a Terminal Server session
state change is detected.

StateChange sessionStateChangeType Specifies the kind of Terminal Server


session change that would trigger a
task launch.

UserId nonEmptyString Specifies the user for the Terminal


Server session. When a session state
change is detected for this user, a task
is started.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]


REQ UIREM EN T VA L UE

Minimum supported server Windows Server 2008 [desktop apps only]


settingsType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the Settings (taskType) element.

<xs:complexType name="settingsType">
<xs:all>
<xs:element name="AllowStartOnDemand"
type="boolean"
default="true"
minOccurs="0"
/>
<xs:element name="RestartOnFailure"
type="restartType"
minOccurs="0"
/>
<xs:element name="MultipleInstancesPolicy"
type="multipleInstancesPolicyType"
default="IgnoreNew"
minOccurs="0"
/>
<xs:element name="DisallowStartIfOnBatteries"
type="boolean"
default="true"
minOccurs="0"
/>
<xs:element name="StopIfGoingOnBatteries"
type="boolean"
default="true"
minOccurs="0"
/>
<xs:element name="AllowHardTerminate"
type="boolean"
default="true"
minOccurs="0"
/>
<xs:element name="StartWhenAvailable"
type="boolean"
default="false"
minOccurs="0"
/>
<xs:element name="NetworkProfileName"
type="string"
minOccurs="0"
/>
<xs:element name="RunOnlyIfNetworkAvailable"
type="boolean"
default="false"
minOccurs="0"
/>
<xs:element name="WakeToRun"
type="boolean"
default="false"
minOccurs="0"
/>
<xs:element name="Enabled"
type="boolean"
default="true"
minOccurs="0"
/>
<xs:element name="Hidden"
type="boolean"
default="false"
default="false"
minOccurs="0"
/>
<xs:element name="DeleteExpiredTaskAfter"
type="duration"
default="PT0S"
minOccurs="0"
/>
<xs:element name="IdleSettings"
type="idleSettingsType"
minOccurs="0"
/>
<xs:element name="NetworkSettings"
type="networkSettingsType"
minOccurs="0"
/>
<xs:element name="ExecutionTimeLimit"
type="duration"
minOccurs="0"
/>
<xs:element name="Priority"
type="priorityType"
default="7"
minOccurs="0"
/>
<xs:element name="RunOnlyIfIdle"
type="boolean"
default="false"
minOccurs="0"
/>
<xs:element name="UseUnifiedSchedulingEngine"
type="boolean"
default="false"
minOccurs="0"
/>
<xs:element name="DisallowStartOnRemoteAppSession"
type="boolean"
default="false"
minOccurs="0"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

AllowHardTerminate boolean Specifies if the Task Scheduler service


allows hard termination of the task.

AllowStar tOnDemand boolean Specifies that the task can be started


by using either the Run command or
the Context menu.

DeleteExpiredTaskAfter duration Specifies the amount of time that the


Task Scheduler will wait before deleting
the task after it expires. If no value is
specified for this element, then the
Task Scheduler service will not delete
the task.
EL EM EN T TYPE DESC RIP T IO N

DisallowStar tIfOnBatteries boolean Specifies that the task will not be


started if the computer is running on
battery power.

DisallowStar tOnRemoteAppSessio boolean Specifies that the task should not start
n if the task is triggered to run in a
Remote Applications Integrated Locally
(RAIL) session.

Enabled boolean Specifies that the task is enabled. The


task can be performed only when this
setting is True .

ExecutionTimeLimit duration Specifies the amount of time allowed


to complete the task.

Hidden boolean Specifies, by default, that the task will


not be visible in the user interface (UI).

IdleSettings idleSettingsType Specifies how the Task Scheduler


performs tasks when the computer is
in an idle state.

MultipleInstancesPolicy multipleInstancesPolicyType Specifies the policy that defines how


the Task Scheduler deals with multiple
instances of the task.

NetworkProfileName string Specifies the name of a network profile.


The Task Scheduler service verifies the
availability of this network when the
RunOnlyIfNetworkAvailable
element is set to True . The name is
used for display purposes.

NetworkSettings networkSettingsType Specifies the settings that the Task


Scheduler service uses to obtain a
network profile. The Task Scheduler
service checks the availability of this
network when the
RunOnlyIfNetworkAvailable
element is set to True .

Priority priorityType Specifies the priority level for the task.

Restar tOnFailure restar tType Specifies that the Task Scheduler will
attempt to restart the task if it fails for
any reason.

RunOnlyIfIdle boolean Specifies that the task is run only when


the computer is in an idle state.

RunOnlyIfNetworkAvailable boolean Specifies that the Task Scheduler will


run the task only when a network is
available.
EL EM EN T TYPE DESC RIP T IO N

Star tWhenAvailable boolean Specifies that the Task Scheduler can


start the task at any time after its
scheduled time has passed.

StopIfGoingOnBatteries boolean Specifies that the task will be stopped


if the computer switches to battery
power.

UseUnifiedSchedulingEngine boolean Specifies that the task is run by using


the Unified Scheduling Engine.

WakeToRun boolean Specifies that Task Scheduler will wake


the computer before it runs the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
showMessageType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the elements that represent an action that shows a message box.

<xs:complexType name="showMessageType">
<xs:complexContent>
<xs:extension
base="actionBaseType"
>
<xs:all>
<xs:element name="Title"
type="nonEmptyString"
/>
<xs:element name="Body"
type="nonEmptyString"
/>
</xs:all>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Body nonEmptyString Specifies the text to display in the body


of the message box.

Title nonEmptyString Specifies the title of the message box.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


taskType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the Task element.

<xs:complexType name="taskType">
<xs:all>
<xs:element name="RegistrationInfo"
type="registrationInfoType"
minOccurs="0"
/>
<xs:element name="Triggers"
type="triggersType"
minOccurs="0"
/>
<xs:element name="Settings"
type="settingsType"
minOccurs="0"
/>
<xs:element name="Data"
type="dataType"
minOccurs="0"
/>
<xs:element name="Principals"
type="principalsType"
minOccurs="0"
/>
<xs:element name="Actions"
type="actionsType"
/>
</xs:all>
<xs:attribute name="version"
type="versionType"
use="optional"
fixed="1.3"
/>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Actions actionsType Specifies the actions performed by the


task.

Data dataType Specifies addition data that is


associated with the task, but is
otherwise unused by the Task
Scheduler service.

Principals principalsType Specifies the security contexts that can


be used to run the task.
EL EM EN T TYPE DESC RIP T IO N

RegistrationInfo registrationInfoType Specifies administrative information


about the task, such as the author of
the task and the date the task is
registered.

Settings settingsType Specifies the settings that the Task


Scheduler uses to perform the task.

Triggers triggersType Specifies the triggers that start the


task.

Attributes
NAME TYPE DESC RIP T IO N

version versionType Specifies the version of the task.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
timeTriggerType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the base type for the TimeTrigger element.

<xs:complexType name="timeTriggerType">
<xs:complexContent>
<xs:extension
base="triggerBaseType"
>
<xs:sequence>
<xs:element name="RandomDelay"
type="duration"
default="PT0M"
/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

RandomDelay duration Specifies the delay time that is


randomly added to the start time of
the trigger. The format for this string is
P<days>DT<hours>H<minutes>M<seconds>S
(for example, P2DT5S is a 2 day, 5
second delay).

Remarks
Note that this element does not add any child elements to those defined by the triggerBaseType complex type.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
triggerBaseType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the attribute, base child elements, and sequencing information for all trigger complex types.

<xs:complexType name="triggerBaseType"
abstract="true"
>
<xs:sequence>
<xs:element name="Enabled"
type="boolean"
default="true"
minOccurs="0"
/>
<xs:element name="StartBoundary"
type="dateTime"
minOccurs="0"
/>
<xs:element name="EndBoundary"
type="dateTime"
minOccurs="0"
/>
<xs:element name="Repetition"
type="repetitionType"
minOccurs="0"
/>
<xs:element name="ExecutionTimeLimit"
type="duration"
minOccurs="0"
/>
</xs:sequence>
<xs:attribute name="id"
type="ID"
use="optional"
/>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Enabled boolean Specifies that the trigger is enabled.

EndBoundar y dateTime The date and time when the trigger is


deactivated.

ExecutionTimeLimit duration Specifies the interval when the trigger


can start the task.

Repetition repetitionType Specifies how often the task is run and


how long the repetition pattern is
repeated once the trigger fires.

Star tBoundar y dateTime The date and time when the trigger is
activated.
Attributes
NAME TYPE DESC RIP T IO N

id ID Identifier of the trigger.

Remarks
Trigger complex types include the following.
bootTriggerType
calendarTriggerType
eventTriggerType
idleTriggerType
logonTriggerType
registrationTriggerType
timeTriggerType

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler Schema Complex Types
Task Scheduler
triggersType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the group (triggerGroup ) for all trigger elements. The triggerGroup group contains the list of
triggers that can be used in a task.

<xs:complexType name="triggersType">
<xs:group
minOccurs="0"
maxOccurs="48"
ref="triggerGroup"
/>
</xs:complexType>

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
weeklyScheduleType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child elements and sequencing information for the ScheduleByWeek element.

<xs:complexType name="weeklyScheduleType">
<xs:all>
<xs:element name="WeeksInterval"
minOccurs="0"
>
<xs:simpleType>
<xs:restriction
base="unsignedByte"
>
<xs:minInclusive
value="1"
/>
<xs:maxInclusive
value="52"
/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="DaysOfWeek"
type="daysOfWeekType"
minOccurs="0"
/>
</xs:all>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

DaysOfWeek daysOfWeekType Specifies the days of the week in which


the task runs.

WeeksInter val Specifies the interval between the


weeks in the schedule.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
weeksType Complex Type
8/8/2022 • 2 minutes to read • Edit Online

Defines the child element and sequencing information for the Week element.

<xs:complexType name="weeksType">
<xs:sequence>
<xs:element name="Week"
type="weekType"
minOccurs="0"
maxOccurs="5"
/>
</xs:sequence>
</xs:complexType>

Child elements
EL EM EN T TYPE DESC RIP T IO N

Week weekType Specifies the week in which the task is


run.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
Task Scheduler Schema Groups
8/8/2022 • 2 minutes to read • Edit Online

This section contains the groups that are defined by the Task Scheduler schema.
actionGroup
triggerGroup
actionGroup Group
8/8/2022 • 2 minutes to read • Edit Online

Defines the group of actions that a task can perform.

<xs:group name="actionGroup">
<xs:choice>
<xs:element name="Exec"
type="execType"
/>
<xs:element name="ComHandler"
type="comHandlerType"
/>
<xs:element name="SendEmail"
type="sendEmailType"
/>
<xs:element name="ShowMessage"
type="showMessageType"
/>
</xs:choice>
</xs:group>

Child elements
EL EM EN T TYPE DESC RIP T IO N

ComHandler comHandlerType Represents an action that fires a


handler.

Exec execType Represents an action that executes a


command-line operation.

SendEmail sendEmailType Represents an action that sends an


email message.

ShowMessage showMessageType Represents an action that shows a


message box.

Remarks
When reading or writing XML, the elements that are defined by this group are the child elements of the Actions
element.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]


See also
Task Scheduler
triggerGroup Group
8/8/2022 • 2 minutes to read • Edit Online

Defines the trigger group.

<xs:group name="triggerGroup">
<xs:choice>
<xs:element name="BootTrigger"
type="bootTriggerType"
minOccurs="0"
/>
<xs:element name="RegistrationTrigger"
type="registrationTriggerType"
minOccurs="0"
/>
<xs:element name="IdleTrigger"
type="idleTriggerType"
minOccurs="0"
/>
<xs:element name="TimeTrigger"
type="timeTriggerType"
minOccurs="0"
/>
<xs:element name="EventTrigger"
type="eventTriggerType"
minOccurs="0"
/>
<xs:element name="LogonTrigger"
type="logonTriggerType"
minOccurs="0"
/>
<xs:element name="SessionStateChangeTrigger"
type="sessionStateChangeTriggerType"
minOccurs="0"
/>
<xs:element name="CalendarTrigger"
type="calendarTriggerType"
minOccurs="0"
/>
</xs:choice>
</xs:group>

Child elements
EL EM EN T TYPE DESC RIP T IO N

BootTrigger bootTriggerType A trigger that starts a task when the


system is booted.

CalendarTrigger calendarTriggerType A trigger that starts a task based on a


daily, weekly, monthly, or monthly day-
of-week (DOW) schedule.

EventTrigger eventTriggerType A trigger that starts a task when a


system event occurs.
EL EM EN T TYPE DESC RIP T IO N

IdleTrigger idleTriggerType A trigger that starts a task when the


computer goes into an idle state.

LogonTrigger logonTriggerType A trigger that starts a task when a


user logs on.

RegistrationTrigger registrationTriggerType A trigger that starts a task when the


task is registered.

SessionStateChangeTrigger sessionStateChangeTriggerType A trigger that starts a task when a


Terminal Server session changes state.

TimeTrigger timeTriggerType A trigger that starts a task when the


trigger is activated.

Remarks
When reading or writing XML, the elements that are defined by this group are the child elements of the
Triggers element.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

See also
Task Scheduler
Task Scheduler Error and Success Constants
8/8/2022 • 3 minutes to read • Edit Online

If an error occurs, the Task Scheduler APIs can return one of the following error codes as an HRESULT value.
The constants that begin with SCHED_S_ are success constants, and the constants that begin with SCHED_E_ are
error constants.

HRESULT phrStatus;
hr = pITask->GetStatus(&phrStatus);

// Release the ITask interface.


pITask->Release();

switch(phrStatus)
{
case SCHED_S_TASK_READY:
wprintf(L" SCHED_S_TASK_READY\n");
break;
case SCHED_S_TASK_RUNNING:
wprintf(L" SCHED_S_TASK_RUNNING\n");
break;

//...
}

Example from C/C++ Code Example: Retrieving Task Status.

NOTE
Some Task Scheduler APIs can return system and network error codes (64 for example). You can check the definition of
these types of error codes by using the net helpmsg command in the command prompt window. For example, the
command net helpmsg 64 returns the message: The specified network name is no longer available.

For more information about events and error messages, see Events and Errors Message Center.
SCHED_S_TASK_READY
0x00041300
The task is ready to run at its next scheduled time.
SCHED_S_TASK_RUNNING
0x00041301
The task is currently running.
SCHED_S_TASK_DISABLED
0x00041302
The task will not run at the scheduled times because it has been disabled.
SCHED_S_TASK_HAS_NOT_RUN
0x00041303
0x00041303
The task has not yet run.
SCHED_S_TASK_NO_MORE_RUNS
0x00041304
There are no more runs scheduled for this task.
SCHED_S_TASK_NOT_SCHEDULED
0x00041305
One or more of the properties that are needed to run this task on a schedule have not been set.
SCHED_S_TASK_TERMINATED
0x00041306
The last run of the task was terminated by the user.
SCHED_S_TASK_NO_VALID_TRIGGERS
0x00041307
Either the task has no triggers or the existing triggers are disabled or not set.
SCHED_S_EVENT_TRIGGER
0x00041308
Event triggers do not have set run times.
SCHED_E_TRIGGER_NOT_FOUND
0x80041309
A task's trigger is not found.
SCHED_E_TASK_NOT_READY
0x8004130A
One or more of the properties required to run this task have not been set.
SCHED_E_TASK_NOT_RUNNING
0x8004130B
There is no running instance of the task.
SCHED_E_SERVICE_NOT_INSTALLED
0x8004130C
The Task Scheduler service is not installed on this computer.
SCHED_E_CANNOT_OPEN_TASK
0x8004130D
The task object could not be opened.
SCHED_E_INVALID_TASK
0x8004130E
The object is either an invalid task object or is not a task object.
SCHED_E_ACCOUNT_INFORMATION_NOT_SET
0x8004130F
No account information could be found in the Task Scheduler security database for the task indicated.
SCHED_E_ACCOUNT_NAME_NOT_FOUND
0x80041310
Unable to establish existence of the account specified.
SCHED_E_ACCOUNT_DBASE_CORRUPT
0x80041311
Corruption was detected in the Task Scheduler security database; the database has been reset.
SCHED_E_NO_SECURITY_SERVICES
0x80041312
Task Scheduler security services are available only on Windows NT.
SCHED_E_UNKNOWN_OBJECT_VERSION
0x80041313
The task object version is either unsupported or invalid.
SCHED_E_UNSUPPORTED_ACCOUNT_OPTION
0x80041314
The task has been configured with an unsupported combination of account settings and run time options.
SCHED_E_SERVICE_NOT_RUNNING
0x80041315
The Task Scheduler Service is not running.
SCHED_E_UNEXPECTEDNODE
0x80041316
The task XML contains an unexpected node.
SCHED_E_NAMESPACE
0x80041317
The task XML contains an element or attribute from an unexpected namespace.
SCHED_E_INVALIDVALUE
0x80041318
The task XML contains a value which is incorrectly formatted or out of range.
SCHED_E_MISSINGNODE
0x80041319
The task XML is missing a required element or attribute.
SCHED_E_MALFORMEDXML
0x8004131A
The task XML is malformed.
SCHED_S_SOME_TRIGGERS_FAILED
0x0004131B
The task is registered, but not all specified triggers will start the task.
SCHED_S_BATCH_LOGON_PROBLEM
0x0004131C
The task is registered, but may fail to start. Batch logon privilege needs to be enabled for the task principal.
SCHED_E_TOO_MANY_NODES
0x8004131D
The task XML contains too many nodes of the same type.
SCHED_E_PAST_END_BOUNDARY
0x8004131E
The task cannot be started after the trigger end boundary.
SCHED_E_ALREADY_RUNNING
0x8004131F
An instance of this task is already running.
SCHED_E_USER_NOT_LOGGED_ON
0x80041320
The task will not run because the user is not logged on.
SCHED_E_INVALID_TASK_HASH
0x80041321
The task image is corrupt or has been tampered with.
SCHED_E_SERVICE_NOT_AVAIL ABLE
0x80041322
The Task Scheduler service is not available.
SCHED_E_SERVICE_TOO_BUSY
0x80041323
The Task Scheduler service is too busy to handle your request. Please try again later.
SCHED_E_TASK_ATTEMPTED
0x80041324
The Task Scheduler service attempted to run the task, but the task did not run due to one of the constraints in
the task definition.
SCHED_S_TASK_QUEUED
0x00041325
The Task Scheduler service has asked the task to run.
SCHED_E_TASK_DISABLED
0x80041326
The task is disabled.
SCHED_E_TASK_NOT_V1_COMPAT
0x80041327
The task has properties that are not compatible with earlier versions of Windows.
SCHED_E_START_ON_DEMAND
0x80041328
The task settings do not allow the task to start on demand.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows Vista [desktop apps only]

Minimum supported server Windows Server 2008 [desktop apps only]

Header
WinError.h
Schtasks.exe
8/8/2022 • 12 minutes to read • Edit Online

Enables an administrator to create, delete, query, change, run, and end scheduled tasks on a local or remote
computer. Running Schtasks.exe without arguments displays the status and next run time for each registered
task.
For more information on Task Scheduler, see this introduction: Task Scheduler for developers.

Creating a Task
The following syntax is used to create a task on the local or remote computer.

schtasks /Create
[/S system [/U username [/P [password]]]]
[/RU username [/RP [password]] /SC schedule [/MO modifier] [/D day]
[/M months] [/I idletime] /TN taskname /TR taskrun [/ST starttime]
[/RI interval] [ {/ET endtime | /DU duration} [/K]
[/XML xmlfile] [/V1]] [/SD startdate] [/ED enddate] [/IT] [/Z] [/F]

Parameters
/S system
A value that specifies the remote computer to connect to. If omitted, the system parameter defaults to the local
computer.
/U username
A value that specifies the user context under which Schtasks.exe should run.
/P [password]
A value that specifies the password for a given user context. If omitted, Schtasks.exe prompts the user for input.
/RU username
A value that specifies the user context under which the task runs. For the system account, valid values are "", "NT
AUTHORITY\SYSTEM", or "SYSTEM". For Task Scheduler 2.0 tasks, "NT AUTHORITY\LOCALSERVICE", and "NT
AUTHORITY\NETWORKSERVICE" are also valid values.
/RP [password]
A value that specifies the password for the user specified with the /RU parameter. To prompt for the password,
the value must be either "*" or no value. This password is ignored for the system account. This parameter must
be combined with either /RU or the /XML switch.
/SC schedule
A value that specifies the schedule frequency. Valid values are: MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY,
ONCE, ONLOGON, ONIDLE, and ONEVENT.
/MO modifier
A value that refines the schedule type to allow for finer control over the schedule recurrence. Valid values are:
MINUTE: 1 - 1439 minutes.
HOURLY: 1 - 23 hours.
DAILY: 1 - 365 days.
WEEKLY: weeks 1 - 52.
ONCE: No modifiers.
ONSTART: No modifiers.
ONLOGON: No modifiers.
ONIDLE: No modifiers.
MONTHLY: 1 - 12, or FIRST, SECOND, THIRD, FOURTH, LAST, and LASTDAY.
ONEVENT: XPath event query string.
/D days
A value that specifies the day of the week to run the task. Valid values are: MON, TUE, WED, THU, FRI, SAT, SUN
and for MONTHLY schedules 1 - 31 (days of the month). The wildcard character (*) specifies all days.
/M months
A value that specifies months of the year. Defaults to the first day of the month. Valid values are: JAN, FEB, MAR,
APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, and DEC. The wildcard character (*) specifies all months.
/I idletime
A value that specifies the amount of idle time to wait before running a scheduled ONIDLE task. The valid range
is 1 - 999 minutes.
/TN taskname
A value that specifies a name which uniquely identifies the scheduled task.
/TR taskrun
A value that specifies the path and file name of the task to be run at the scheduled time. For example:
C:\Windows\System32\calc.exe.
/ST star ttime
A value that specifies the start time to run the task. The time format is HH:mm (24-hour time). For example,
14:30 specifies 2:30PM. The default is the current time is /ST is not specified. This option is required wit the /SC
ONCE argument.
/RI inter val
A value that specifies the repetition interval in minutes. This is not applicable for the following schedule types:
MINUTE, HOURLY, ONSTART, ONLOGON, ONIDLE, and ONEVENT. The valid range is 1 - 599940 minutes. If either
the /ET or /DU parameters are specified, the default is 10 minutes.
Windows XP and Windows Ser ver 2003: This option is not available.
/ET endtime
A value that specifies the end time to run the task. The time format is HH:mm (24-hour time). For example, 14:50
specifies 2:50PM. This is not applicable for the following schedule types: ONSTART, ONLOGON, ONIDLE, and
ONEVENT.
Windows XP and Windows Ser ver 2003: This option is not available.
/DU duration
A value that specifies the duration to run the task. The time format is HH:mm (24-hour time). For example, 14:50
specifies 2:50PM. This is not applicable with /ET and for the following schedule types: ONSTART, ONLOGON,
ONIDLE, and ONEVENT. For /V1 tasks (Task Scheduler 1.0 tasks), if /RI is specified, then the duration default is
one hour.
Windows XP: This option is not available.
/K
A value that terminates the task at the end time or duration time. This is not applicable for the following
schedule types: ONSTART, ONLOGON, ONIDLE, and ONEVENT. Either /ET or /DU must be specified.
Windows XP and Windows Ser ver 2003: This option is not available.
/SD star tdate
A value that specifies the first date on which to run the task. The format is mm/dd/yyyy. This value defaults to
the current date. This is not applicable for the following schedule types: ONCE, ONSTART, ONLOGON, ONIDLE,
and ONEVENT.
/ED enddate
A value that specifies the last date that the task will run. The format is mm/dd/yyyy. This is not applicable for the
following schedule types: ONCE, ONSTART, ONLOGON, ONIDLE, and ONEVENT.
/EC ChannelName
A value that specifies the event channel for ONEVENT triggers.
Windows XP and Windows Ser ver 2003: This option is not available.
/IT
A value that enables the task to run interactively only if the /RU user is currently logged on at the time the task
runs. The task runs only if the user is logged on.
Windows XP and Windows Ser ver 2003: This option is not available.
/NP
A value that indicates that no password is stored. The task does not run interactively as the given user. Only local
resources are available.
Windows XP and Windows Ser ver 2003: This option is not available.
/Z
A value that marks the task to be deleted after its final run.
Windows XP and Windows Ser ver 2003: This option is not available.
/XML xmlfile
A value that creates a task from an XML file. This parameter can be combined with /RU and /RP switches, or with
the /RP switch alone when the task XML already contains the principal.
Windows XP and Windows Ser ver 2003: This option is not available.
/V1
A value that creates a task visible to Windows 2000, Windows Server 2003, and Windows XP platforms.
Windows XP and Windows Ser ver 2003: This option is not available.
/F
A value that forcefully creates the task and suppresses warnings if the specified task already exists.
Windows XP and Windows Ser ver 2003: This option is not available.
/RL level
A value that sets the run level for the task. Valid values are LIMITED and HIGHEST. The default is LIMITED.
Windows XP and Windows Ser ver 2003: This option is not available.
/DEL AY delaytime
A value that specifies the wait time to delay the task after the trigger is fired. The time format is mmmm:ss. This
option is only valid for schedule types ONSTART, ONLOGON, and ONEVENT.
Windows XP and Windows Ser ver 2003: This option is not available.
/?
A value that displays the help message for Schtasks.exe.

Remarks
When creating a task on a remote computer running on the Windows XP, Windows Server 2003, or Windows
2000 operating system, use the /V1 switch.
You cannot create a non-interactive remote Task Scheduler 1.0 task (create a task by not using the /IT switch and
using the /V1 switch) if the remote computer has the File and Printer Sharing firewall exception enabled and the
Remote Scheduled Tasks Management firewall exception disabled.

Deleting a Task
The following syntax is used to delete one or more scheduled tasks.

schtasks /Delete
[/S system [/U username [/P [password]]]]
[/TN taskname] [/F]

Parameters
/S system
A value that specifies the remote computer to connect to. If omitted, the system parameter defaults to the local
computer.
/U username
A value that specifies the user context under which Schtasks.exe should run.
/P [password]
A value that specifies the password for the given user context. If omitted, Schtasks.exe prompts the user for
input.
/TN taskname
A value that specifies the name of the scheduled task to delete. The wildcard character (*) can be used to delete
all tasks.
/F
A value that forcefully deletes the task and suppresses warnings if the specified task is running.
/?
A value that displays Help for Schtasks.exe.

Running a Task
The following syntax is used to immediately run a scheduled task.

schtasks /Run
[/S system [/U username [/P [password]]]]
/TN taskname

Parameters
/S system
A value that specifies the remote computer to connect to. If omitted, the system parameter defaults to the local
computer.
/U username
A value that specifies the user context under which Schtasks.exe should run.
/P [password]
A value that specifies the password for the given user context. If omitted, Schtasks.exe prompts the user for
input.
/TN taskname
A value that specifies the name of the scheduled task to run.
/?
A value that displays Help for Schtasks.exe.

Ending a Running Task


The following syntax is used to stop a running scheduled task.

NOTE
To stop a remote task from running, ensure that the remote computer has the File and Printer Sharing and Remote
Scheduled Tasks Management firewall exceptions enabled.

schtasks /End
[/S system [/U username [/P [password]]]]
/TN taskname

Parameters
/S system
A value that specifies the remote computer to connect to. If omitted, the system parameter defaults to the local
computer.
/U username
A value that specifies the user context under which Schtasks.exe should run.
/P [password]
A value that specifies the password for the given user context. If omitted, Schtasks.exe prompts the user for
input.
/TN taskname
A value that specifies the name of the scheduled task to stop.
/?
A value that displays Help for Schtasks.exe.

Querying for Task Information


The following syntax is used to display the scheduled tasks from the local or remote computer.

schtasks /Query
[/S system [/U username [/P [password]]]]
[/FO format | /XML] [/NH] [/V] [/TN taskname] [/?]

Parameters
/S system
A value that specifies the remote computer to connect to. If omitted, the system parameter defaults to the local
computer.
/U username
A value that specifies the user context under which Schtasks.exe should run.
/P [password]
A value that specifies the password for the given user context. If omitted, Schtasks.exe prompts the user for
input.
/FO format
A value that specifies the output format. The valid values are TABLE, LIST, and CSV.
/NH
A value that specifies that the column header should not be displayed in the output. This is valid only for TABLE
and CSV formats.
/V
A value that displays verbose task output.

NOTE
If a task was scheduled to run only one time, then the displayed schedule information is "Scheduling data is not available
in this format."

/TN taskname
A value that specifies the task name for which to retrieve the information. If no task name is specified, then
information for all the tasks will be displayed.
Windows XP and Windows Ser ver 2003: This option is not available.
/XML
A value that is used to display the task definitions in XML format.
Windows XP and Windows Ser ver 2003: This option is not available.
/?
A value that is used to display the Help for Schtasks.exe.

Changing a Task
The following syntax is used to change how the program runs, or change the user account and password used
by a scheduled task.

schtasks /Change
[/S system [/U username [/P [password]]]] /TN taskname
{ [/RU runasuser] [/RP runaspassword] [/TR taskrun] [/ST starttime]
[/RI interval] [ {/ET endtime | /DU duration} [/K] ]
[/SD startdate] [/ED enddate] [/ENABLE | /DISABLE] [/IT] [/Z] }

Parameters
/S system
A value that specifies the remote computer to connect to. If omitted, the system parameter defaults to the local
computer.
/U username
A value that specifies the user context under which Schtasks.exe should run.
/P [password]
A value that specifies the password for the given user context. If omitted, Schtasks.exe prompts the user for
input.
/TN taskname
A value that specifies which scheduled task to change.
/RU runasuser
A value that changes the user name (user context) under which the scheduled task will run. For the system
account, valid values are "", "NT AUTHORITY\SYSTEM", or "SYSTEM". For Task Scheduler 2.0 tasks, "NT
AUTHORITY\LOCALSERVICE" and "NT AUTHORITY\NETWORKSERVICE" are also valid values.
/RP runaspassword
A value that specifies a new password for the existing user context or the password for a new user account. This
password is ignored for the system account.
/TR taskrun
A value that specifies a new program that the task will run.
/ST star ttime
A value that specifies the start time to run the task. The time format is HH:mm (24-hour time). For example,
14:30 specifies 2:30PM.
Windows XP and Windows Ser ver 2003: This option is not available.
/RI inter val
A value that specifies the repetition interval, in minutes. The valid range is 1 - 599940 minutes.
Windows XP and Windows Ser ver 2003: This option is not available.
/ET endtime
A value that specifies the end time for the task. The time format is HH:mm (24-hour time). For example, 14:50
specifies 2:50PM.
Windows XP and Windows Ser ver 2003: This option is not available.
/DU duration
A value that specifies the duration to run the task. The time format is HH:mm (24-hour time). For example, 14:50
specifies 2:50PM. This is not applicable with the /ET parameter.
Windows XP and Windows Ser ver 2003: This option is not available.
/K
A value that terminates the task at the end time or duration time.
Windows XP and Windows Ser ver 2003: This option is not available.
/SD star tdate
A value that specifies the first date on which to run the task. The format is mm/dd/yyyy.
Windows XP and Windows Ser ver 2003: This option is not available.
/ED enddate
A value that specifies the last date that the task will run. The format is mm/dd/yyyy.
Windows XP and Windows Ser ver 2003: This option is not available.
/IT
A value that enables the task to run interactively only if the /RU user is currently logged on at the time the task
runs. The task runs only if the user is logged on.
Windows XP and Windows Ser ver 2003: This option is not available.
/RL level
A value that sets the run level for the task. Valid values are LIMITED and HIGHEST.
Windows XP and Windows Ser ver 2003: This option is not available.
/ENABLE
A value that enables the scheduled task. An enabled task can run, and a disabled task cannot run.
Windows XP and Windows Ser ver 2003: This option is not available.
/DISABLE
A value that disables the scheduled task from running.
NOTE
If a remote Task Scheduler 1.0 task is disabled by Schtasks.exe and the remote computer has the File and Printer Sharing
firewall exception enabled and the Remote Scheduled Tasks Management firewall exception disabled, then the task will not
be disabled when read from a Task Scheduler 2.0 API.

Windows XP and Windows Ser ver 2003: This option is not available.
/Z
A value that marks the task to be deleted after its final run.
Windows XP and Windows Ser ver 2003: This option is not available.
/DEL AY delaytime
A value that specifies the wait time to delay the running of the task after the trigger is fired. The time format is
mmmm:ss. This option is only valid for tasks with the schedule types ONSTART, ONLOGON, and ONEVENT.
Windows XP and Windows Ser ver 2003: This option is not available.
/?
A value that displays the Help message for Schtasks.exe.

Requirements
REQ UIREM EN T VA L UE

Minimum supported client Windows XP [desktop apps only]

Minimum supported server Windows Server 2003 [desktop apps only]


Task Scheduler Glossary
8/8/2022 • 2 minutes to read • Edit Online

This section provides a glossary of technical terms used in the Task Scheduler documentation.
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Related topics
Task Scheduler
E (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

ABCDEFGHIJKLMNOPQRSTUVWXYZ
enumeration objects
An object that provides methods for enumerating tasks in the Scheduled Tasks folder. This object supports two
interfaces: IUnknown and IEnumWorkItems . Enumeration objects are created by calls to
ITaskScheduler ::Enum .
I (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

ABCDEFGHIJKLMNOPQRSTUVWXYZ
idle conditions
A period of time in which there is no user input on the computer. Idle conditions are associated with the
scheduled start time for the task.
These conditions are set by calling IScheduledWorkItem::SetFlags .
idle triggers
An event-based trigger that is fired when the computer becomes idle for a specific amount of time.
Idle triggers are created by setting the TASK_TRIGGER_TYPE member of the TASK_TRIGGER structure to
TASK_EVENT_TRIGGER_ON_IDLE.
idle wait time
The time interval (in minutes) used by an idle trigger or idle condition. Idle triggers are event-based triggers that
are not associated with a scheduled time. Idle conditions are associated with the scheduled start time for the
task.
The idle time is set by a call to IScheduledWorkItem::SetIdleWait .
P (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

ABCDEFGHIJKLMNOPQRSTUVWXYZ
priority level
A task setting that determines the frequency and length of the time slices for a process. Priority levels apply only
to the Windows Server 2003, Windows XP, and Windows 2000 operating systems.
S (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

ABCDEFGHIJKLMNOPQRSTUVWXYZ
Scheduled Tasks folder
A folder created by the Task Scheduler service that contains all the tasks that are scheduled to run on the
computer.
To view this folder in the Windows Server 2003, Windows XP, or Windows 2000 operating systems, open
Control Panel , and then double-click Scheduled Tasks .
T (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

ABCDEFGHIJKLMNOPQRSTUVWXYZ
task objects
Instances of an object that provides methods for managing tasks. This includes methods for setting and
retrieving properties; running, terminating, and deleting tasks; and creating new triggers and retrieving old
triggers.
The task object is created by calls to IScheduledWorkItem::CreateTrigger and
IScheduledWorkItem::GetTrigger .
task scheduler objects
Instances of an object the represents the Task Scheduler service. This object supports two interfaces: IUnknown
and ITaskScheduler (currently tasks are the only type of work items supported by the Task Scheduler service).
Task scheduler objects are created by calls to CoCreateInstance .
task trigger objects
Instances of an object the provides methods for setting and retrieving task triggers. This object supports two
interfaces: IUnknown and ITaskTrigger .
Task trigger objects are created by calls to IScheduledWorkItem::CreateTrigger and
IScheduledWorkItem::GetTrigger .
See also: triggers.
tasks
Any item that the Task Scheduler can execute. These items may include any of the following (as supported by the
operating system on which the task will execute): Win32® applications, Win16 applications, OS/2 applications,
MS-DOS® applications, batch files (*.bat), command files (*.cmd), or any properly registered file type.
Tasks folder
The folder that lists all task files (currently, tasks are the only work items available). These files contain the
information about the task. The name of these files reflects the name of the task.
You can retrieve the location of the Tasks folder from the registry by getting data for the following value:

HKEY_LOCAL_MACHINE
SOFTWARE
Microsoft
SchedulingAgent
TasksFolder

triggers
A set of criteria that, when met, will cause a task to be executed. Task Scheduler provides time-based and event-
based triggers that can specify task start times, repetition criteria, and other parameters.
trigger strings
A string that describes the trigger. This string is created by the Task Scheduler service, and appears in the Task
Scheduler user interface in a form similar to "At 2PM every day, starting 5/11/97."
trigger structures
The TASK_TRIGGER structure used when setting or retrieving the criteria that defines the trigger. The criteria
includes when the trigger will fire, and the type of the trigger.
W (Task Scheduler)
8/8/2022 • 2 minutes to read • Edit Online

ABCDEFGHIJKLMNOPQRSTUVWXYZ
work items
An item that can be scheduled using the Task Scheduler service. It can be any item that the Task Scheduler
service runs at a time that is specified by the item's trigger(s).
Currently, tasks are the only valid type of work item.
working director y
The directory where Task Scheduler will start to run the task. If no working directory is specified, Task Scheduler
will run the task in the %windir%\system32 directory.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy