34

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

    4 Answers 4

    36

    See the following project on GitHub:

    https://github.com/dahall/taskscheduler

    4
    • Yea thanks. Thats exactly what I was looking for. Somehow missed it when I searched for it.CommentedOct 21, 2010 at 8:13
    • +1 exactly what i needed, i also searched a bit around until i decided to make a search here before posting the same question as Matt
      – Jim Wolff
      CommentedNov 24, 2011 at 12:54
    • Exactly what I was looking for. Task Scheduler is painful and the command line (schtasks) looks even worse. This API is working great so far. Thank you!
      – Robin
      CommentedMar 26, 2013 at 21:43
    • After successfully installing assemblies through Nugget it does not recognize TaskService in code. What can be the problem ?
      – Shai
      CommentedJul 20, 2017 at 11:53
    11

    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); 
    2
    • 1
      From where did you get the ITaskService, TaskSchedulerClass, ITaskDefinition, ITriggerCollection, ITrigger, IActionCollection, IAction, IExecAction, and ITaskFolder? The assembly with those classes and interfaces is not readily visible in Visual Studio 2010.
      – Zarepheth
      CommentedJun 23, 2014 at 22:49
    • 4
      Nevermind - I found the "taskschd.dll" file and after letting Visual Studio generate an Interop wrapped, was able to import it into my project. If only I could do the same with the PowerShell ISE and have it deploy to the destination target machines...
      – Zarepheth
      CommentedJun 23, 2014 at 22:59
    5

    Is the command line good enough?

    at 23:39 /every:wednesday defrag c:

    1
    • 6
      Or better yet its successor, schtasksCommentedJan 21, 2012 at 16:22
    0

    You can get fully functioned GUI through following Nuget command.

    PM> Install-Package TaskSchedulerEditor

    3
    • 1
      why would you install a package with a gui if windows has a gui build especially for this taskschd.msc /s
      – Proxx
      CommentedSep 30, 2015 at 9:49
    • Here TaskSchedulerEditor is name of COM wrapper designed to used in C# code to access windows task scheduler GUI.CommentedSep 30, 2015 at 15:31
    • This is the nuget package for taskscheduler.codeplex.com
      – Chris S
      CommentedDec 6, 2015 at 22:26

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.