C# API for Task Scheduler 2.0 [closed]
Does anyone have any recommendations for a .NET c# wrapper for the (COM based) Task Scheduler 2.0 API ?
Couldnt find anything using Google.
(I am aware there are .net based schedulers such as Quartz.net, but I need the fully functioned GUI in the windows Scheduler)
Thanks,
Matt
See the following project on GitHub:
https://github.com/dahall/taskscheduler
If you dont want to use any third party wrapper then below is the sample code to schedule task.Code works in Windows 7.
//create task service instance
ITaskService taskService = new TaskSchedulerClass();
taskService.Connect();
ITaskDefinition taskDefinition = taskService.NewTask(0);
taskDefinition.Settings.Enabled = true;
taskDefinition.Settings.Compatibility = _TASK_COMPATIBILITY.TASK_COMPATIBILITY_V2_1;
//create trigger for task creation.
ITriggerCollection _iTriggerCollection = taskDefinition.Triggers;
ITrigger _trigger = _iTriggerCollection.Create(_TASK_TRIGGER_TYPE2.TASK_TRIGGER_TIME);
_trigger.StartBoundary = DateTime.Now.AddSeconds(15).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
_trigger.EndBoundary = DateTime.Now.AddMinutes(1).ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss");
_trigger.Enabled = true;
///get actions.
IActionCollection actions = taskDefinition.Actions;
_TASK_ACTION_TYPE actionType = _TASK_ACTION_TYPE.TASK_ACTION_EXEC;
//create new action
IAction action = actions.Create(actionType);
IExecAction execAction = action as IExecAction;
execAction.Path = @"C:\Windows\System32\notepad.exe";
ITaskFolder rootFolder = taskService.GetFolder(@"\");
//register task.
rootFolder.RegisterTaskDefinition("test", taskDefinition, 6, null, null, _TASK_LOGON_TYPE.TASK_LOGON_NONE, null);
Is the command line good enough?
at 23:39 /every:wednesday defrag c: