Click or drag to resize
Task Scheduler Managed Class Library

TaskServiceAddTask Method (String, Trigger, Action, String, String, TaskLogonType, String)

Creates a new task, registers the task, and returns the instance.

Namespace:  Microsoft.Win32.TaskScheduler
Assembly:  Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.10.1
Syntax
public Task AddTask(
	string path,
	Trigger trigger,
	Action action,
	string userId = null,
	string password = null,
	TaskLogonType logonType = TaskLogonType.InteractiveToken,
	string description = null
)
Request Example View Source

Parameters

path
Type: SystemString
The task name. If this value is NULL, 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.
trigger
Type: Microsoft.Win32.TaskSchedulerTrigger
The Trigger to determine when to run the task.
action
Type: Microsoft.Win32.TaskSchedulerAction
The Action to determine what happens when the task is triggered.
userId (Optional)
Type: SystemString
The user credentials used to register the task.
password (Optional)
Type: SystemString
The password for the userId used to register the task.
logonType (Optional)
Type: Microsoft.Win32.TaskSchedulerTaskLogonType
A TaskLogonType value that defines what logon technique is used to run the registered task.
description (Optional)
Type: SystemString
The task description.

Return Value

Type: Task
A Task instance of the registered task.
Remarks
This method is shorthand for creating a new TaskDescription, adding a trigger and action, and then registering it in the root folder.
Examples
C#
// Display a log file every other day
TaskService.Instance.AddTask("Test", new DailyTrigger { DaysInterval = 2 }, new ExecAction("notepad.exe", "c:\\test.log", null));
See Also