TaskServiceAddTask(String, QuickTriggerType, String, String, String, String, TaskLogonType, String) Method

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

Definition

Namespace: Microsoft.Win32.TaskScheduler
Assembly: Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.11.0
public Task AddTask(
	string path,
	QuickTriggerType trigger,
	string exePath,
	string arguments = null,
	string userId = null,
	string password = null,
	TaskLogonType logonType = TaskLogonType.InteractiveToken,
	string description = 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.
trigger  QuickTriggerType
The Trigger to determine when to run the task.
exePath  String
The executable path.
arguments  String  (Optional)
The arguments (optional). Value can be NULL.
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.
description  String  (Optional)
The task description.

Return Value

Task
A Task instance of the registered task.

Example

C#
// Display a log file every day
TaskService.Instance.AddTask("Test", QuickTriggerType.Daily, "notepad.exe", "c:\\test.log"));

See Also