Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# API for Task Scheduler 2.0 [closed]

Tags:

c#

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

like image 545
Matt Randle Avatar asked Oct 20 '10 12:10

Matt Randle


2 Answers

See the following project on GitHub:

https://github.com/dahall/taskscheduler

like image 104
Peter Avatar answered Oct 07 '22 23:10

Peter


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); 
like image 45
Tjcool Avatar answered Oct 08 '22 01:10

Tjcool