 | TaskFolderRegisterTask Method |
Registers (creates) a new task in the folder using XML to define the task.
Namespace:
Microsoft.Win32.TaskScheduler
Assembly:
Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.10.1
Syntaxpublic Task RegisterTask(
string path,
string xmlText,
TaskCreation createType = TaskCreation.CreateOrUpdate,
string userId = null,
string password = null,
TaskLogonType logonType = TaskLogonType.S4U,
string sddl = null
)
Public Function RegisterTask (
path As String,
xmlText As String,
Optional createType As TaskCreation = TaskCreation.CreateOrUpdate,
Optional userId As String = Nothing,
Optional password As String = Nothing,
Optional logonType As TaskLogonType = TaskLogonType.S4U,
Optional sddl As String = Nothing
) As Task
public:
Task^ RegisterTask(
String^ path,
String^ xmlText,
TaskCreation createType = TaskCreation::CreateOrUpdate,
String^ userId = nullptr,
String^ password = nullptr,
TaskLogonType logonType = TaskLogonType::S4U,
String^ sddl = nullptr
)
Request Example
View SourceParameters
- 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. - xmlText
- Type: SystemString
An XML-formatted definition of the task. - createType (Optional)
- Type: Microsoft.Win32.TaskSchedulerTaskCreation
A union of TaskCreation flags. - 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. - sddl (Optional)
- Type: SystemString
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
Type:
TaskA
Task instance that represents the new task.
Examples
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>";
TaskService.Instance.RootFolder.RegisterTaskDefinition("Test", xml);
See Also