ITaskFolder::RegisterTaskDefinition method (taskschd.h)
Registers (creates) a task in a specified location using the ITaskDefinition interface to define a task.
Syntax
HRESULT RegisterTaskDefinition(
[in] BSTR path,
[in] ITaskDefinition *pDefinition,
[in] LONG flags,
[in] VARIANT userId,
[in] VARIANT password,
[in] TASK_LOGON_TYPE logonType,
[in, optional] VARIANT sddl,
[out] IRegisteredTask **ppTask
);
Parameters
[in] path
The name of the task. If this value is NULL, the task will be registered in the root task folder and the task name will be a GUID value 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.
[in] pDefinition
The definition of the registered task.
[in] flags
A TASK_CREATION constant.
[in] userId
The user credentials used to register the task. If present, these credentials take priority over the credentials specified in the task definition object pointed to by the pDefinition parameter.
[in] password
The password for the userId 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.
[in] logonType
Defines what logon technique is used to run the registered task.
[in, optional] sddl
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.
[out] ppTask
An IRegisteredTask interface that represents the new task.
Pass in a reference to a NULL IRegisteredTask interface pointer. Referencing a non-NULL pointer can cause a memory leak because the pointer will be overwritten.
Return value
This method can return one of these values.
Return code/value | Description |
---|---|
|
The operation completed successfully. |
|
Access is denied to connect to the Task Scheduler service. |
|
The application does not have enough memory to complete the operation or the user or password has at least one null and one non-null value. |
|
The task is registered, but may fail to start. Batch logon privilege needs to be enabled for the task principal. |
|
The task is registered, but not all specified triggers will start the task. |
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 be interactive, specify TASK_LOGON_INTERACTIVE_TOKEN or TASK_LOGON_GROUP in the LogonType property of the task principal, or in the logonType parameter of ITaskFolder::RegisterTask or ITaskFolder::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 TASK_LOGON_INTERACTIVE_TOKEN specified in the logonType parameter of ITaskFolder::RegisterTask or ITaskFolder::RegisterTaskDefinition, but the task will not run.
Passing the TASK_VALIDATE_ONLY and TASK_IGNORE_REGISTRATION_TRIGGERS values together to the flags parameter is an invalid argument.
The ITaskFolder::RegisterTaskDefinition method returns error 80070534 when called by the System account with the user parameter equal to NULL, the password parameter equal to NULL, and the logonType parameter equal to TASK_LOGON_SERVICE_ACCOUNT.
If a task defines a network that does not exist in the NetworkSettings settings of the task, the ITaskFolder::RegisterTaskDefinition method will return error 0x8000ffff when the task is registered.
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows Vista [desktop apps only] |
Minimum supported server | Windows Server 2008 [desktop apps only] |
Target Platform | Windows |
Header | taskschd.h |
Library | Taskschd.lib |
DLL | Taskschd.dll |