TaskFolderRegisterTaskDefinition(String, TaskDefinition) Method

Registers (creates) a task in a specified location using a TaskDefinition instance to define a task.

Definition

Namespace: Microsoft.Win32.TaskScheduler
Assembly: Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.11.0
public Task RegisterTaskDefinition(
	string path,
	TaskDefinition definition
)

Parameters

path  String
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.
definition  TaskDefinition
The TaskDefinition of the registered task.

Return Value

Task
A Task instance that represents the new task.

Example

C#
// Create a new task definition for the local machine and assign properties
TaskDefinition td = TaskService.Instance.NewTask();
td.RegistrationInfo.Description = "Does something";

// Add a trigger that, starting tomorrow, will fire every other week on Monday and Saturday
td.Triggers.Add(new WeeklyTrigger(DaysOfTheWeek.Monday | DaysOfTheWeek.Saturday, 2));

// Create an action that will launch Notepad whenever the trigger fires
td.Actions.Add("notepad.exe", "c:\\test.log");

// Register the task in the root folder of the local machine using the current user and the S4U logon type
TaskService.Instance.RootFolder.RegisterTaskDefinition("Test", td);

See Also