TaskFolderRegisterTask Method

Registers (creates) a new task in the folder using XML to define the task.

Definition

Namespace: Microsoft.Win32.TaskScheduler
Assembly: Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.11.0
public Task RegisterTask(
	string path,
	string xmlText,
	TaskCreation createType = TaskCreation.CreateOrUpdate,
	string userId = null,
	string password = null,
	TaskLogonType logonType = TaskLogonType.S4U,
	string sddl = null
)

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.
xmlText  String
An XML-formatted definition of the task.
createType  TaskCreation  (Optional)
A union of TaskCreation flags.
userId  String  (Optional)
The user credentials used to register the task.
password  String  (Optional)
The password for the userId used to register the task.
logonType  TaskLogonType  (Optional)
A TaskLogonType value that defines what logon technique is used to run the registered task.
sddl  String  (Optional)
The security descriptor 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.

Return Value

Task
A Task instance that represents the new task.

Example

C#
// Define a basic task in XML
var xml = "<?xml version=\"1.0\" encoding=\"UTF-16\"?>" +
   "<Task version=\"1.2\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">" +
   "  <Principals>" +
   "    <Principal id=\"Author\">" +
   "      <UserId>S-1-5-18</UserId>" +
   "    </Principal>" +
   "  </Principals>" +
   "  <Triggers>" +
   "    <CalendarTrigger>" +
   "      <StartBoundary>2017-09-04T14:04:03</StartBoundary>" +
   "      <ScheduleByDay />" +
   "    </CalendarTrigger>" +
   "  </Triggers>" +
   "  <Actions Context=\"Author\">" +
   "    <Exec>" +
   "      <Command>cmd</Command>" +
   "    </Exec>" +
   "  </Actions>" +
   "</Task>";
// Register the task in the root folder of the local machine using the SYSTEM account defined in XML
TaskService.Instance.RootFolder.RegisterTaskDefinition("Test", xml);

See Also