Click or drag to resize
Task Scheduler Managed Class Library

TaskServiceAddAutomaticMaintenanceTask Method

Adds or updates an Automatic Maintenance Task on the connected machine.

Namespace:  Microsoft.Win32.TaskScheduler
Assembly:  Microsoft.Win32.TaskScheduler (in Microsoft.Win32.TaskScheduler.dll) Version: 2.10.1
Syntax
public Task AddAutomaticMaintenanceTask(
	string taskPathAndName,
	TimeSpan period,
	TimeSpan deadline,
	string executablePath,
	string arguments = null,
	string workingDirectory = null
)
Request Example View Source

Parameters

taskPathAndName
Type: SystemString
Name of the task with full path.
period
Type: SystemTimeSpan
The amount of time the task needs once executed during regular Automatic maintenance.
deadline
Type: SystemTimeSpan
The amount of time after which the Task Scheduler attempts to run the task during emergency Automatic maintenance, if the task failed to complete during regular Automatic Maintenance.
executablePath
Type: SystemString
The path to an executable file.
arguments (Optional)
Type: SystemString
The arguments associated with the command-line operation.
workingDirectory (Optional)
Type: SystemString
The directory that contains either the executable file or the files that are used by the executable file.

Return Value

Type: Task
A Task instance of the Automatic Maintenance Task.
Exceptions
ExceptionCondition
InvalidOperationException Automatic Maintenance tasks are only supported on Windows 8/Server 2012 and later.
See Also