Documentation Home Page

There is a help file included with the download that provides an overview of the various classes. The Microsoft MSDN documentation provides an excellent overview of the Task Scheduler along with details around security and permission, idle conditions, and trigger repetition.
Below is a brief example of how to use the library from C#.

using System;
using Microsoft.Win32.TaskScheduler;

class Program
   static void Main(string[] args)
      // Create a new task definition for the local machine and assign properties
      TaskDefinition td = TaskService.Instance.NewTask();
      td.RegistrationInfo.Description = "Does something";

      // Add a trigger that, starting tomorrow, will fire every other week on Monday
      // and Saturday and repeat every 10 minutes for the following 11 hours
      WeeklyTrigger wt = new WeeklyTrigger();
      wt.StartBoundary = DateTime.Today.AddDays(1);
      wt.DaysOfWeek = DaysOfTheWeek.Monday | DaysOfTheWeek.Saturday;
      wt.WeeksInterval = 2;
      wt.Repetition.Duration = TimeSpan.FromHours(11);
      wt.Repetition.Interval = TimeSpan.FromMinutes(10);

      // Create an action that will launch Notepad whenever the trigger fires
      td.Actions.Add("notepad.exe", "c:\\test.log");

      // Register the task in the root folder of the local machine
      TaskService.Instance.RootFolder.RegisterTaskDefinition("Test", td);

Here's the same as above but in VB.NET

Imports Microsoft.Win32.TaskScheduler

Module Module1

    Sub Main()
        Using ts As New TaskService()
            ' Create a new task definition and assign properties
            Dim td As TaskDefinition = ts.NewTask
            td.RegistrationInfo.Description = "Does something"

            ' Add a trigger that will, starting tomorrow, fire every other week on Monday
            ' and Saturday and repeat every 10 minutes for the following 11 hours
            Dim wt As New WeeklyTrigger()
            wt.StartBoundary = DateTime.Today.AddDays(1)
            wt.DaysOfWeek = DaysOfTheWeek.Monday Or DaysOfTheWeek.Saturday
            wt.WeeksInterval = 2
            wt.Repetition.Duration = TimeSpan.FromHours(11)
            wt.Repetition.Interval = TimeSpan.FromMinutes(10)

            ' Add an action (shorthand) that runs Notepad
            td.Actions.Add(New ExecAction("notepad.exe", "c:\test.log"))

            ' Register the task in the root folder
            ts.RootFolder.RegisterTaskDefinition("Test", td)
        End Using
    End Sub

End Module

If you're really into shorthand code, here's almost the same functionality as the C# code above, but much shorter:

using System;
using Microsoft.Win32.TaskScheduler;

class Program
   static void Main(string[] args)
      TaskService.Instance.AddTask("Test", new DailyTrigger { DaysInterval = 2 },
         new ExecAction("notepad.exe", "c:\\test.log", null));

Alternately, you can use the library declaratively or "fluently":

Task t = TaskService.Instance.Execute("notepad.exe").WithArguments(@"c:\test.log").Every(2).Days().AsTask("Test");

Last edited Jul 20 at 6:16 PM by dahall, version 26


Barina Jan 23 at 10:27 PM 
That looks awesome.. I'll try that soon
I have a question
There's a way to pull a specific task information?
I want to check when the next execute will occur and put a countdown timer or something..

dahall Oct 22, 2015 at 2:28 PM 
LudwigP: You have to connect to the TaskService with credentials the same or better than those used to create the task. UAC can also cause problems so either Run as Admin or change your manifest file.

LudwigP Oct 22, 2015 at 12:47 PM 
Create Task works fine, but how do I delete the task again? I tried it this way:

Private Sub btnDeleteTask_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeleteTask.Click

Using ts As New TaskService()


End Using

There was an error message: Access Denied

sathiyajebac Jun 12, 2014 at 12:44 PM 
I have some clarification and code sample for the following.
How to create a task with Administrator account.
How to updated the trigger settings for the existing task.
For example : I have a task which is running daily 12:30 AM, I would like to change the Date running and Time running for this task. I would like to update the date as current date and time as (current time + 5 mins).

How to invoke the task after update the trigger settings?



Deepres Nov 21, 2013 at 11:55 AM 
works win7 is very good!

Deepres Nov 21, 2013 at 11:54 AM 
how to works windows xp?

dahall Aug 14, 2013 at 3:35 PM 
Dangerous: For the SecurityEditor compile problem, I have updated the source code so it will compile. Please note however, that this project is not actually used by the TaskScheduler assemblies. It was a side project that has not been completed.

Dangerous Aug 14, 2013 at 2:01 AM 
I can't get this to work. The download doesn't contain NativeMethods.cs, which is required for SecurityEditor and TestTaskService (and others, but I do have another version/instance of this class which is used elsewhere, albeit, without AccountLibs).

I also do not have the TaskScheduler.Trigger.CreateTriggers() method anywhere.

tmatute Nov 30, 2012 at 6:13 PM 
is there a way to load a XML with a task definition and register the task definition?

dahall Apr 27, 2012 at 4:16 PM 
Don't use the UserId property. Instead call the RegisterTaskDefinition method with "SYSTEM" as the user, null as the password, and TaskLogonType.ServiceAccount for the type.

RickBowden Apr 27, 2012 at 12:05 PM 
I've been trying this and it works great but I'm struggling with something.
I want to create scheduled tasks that run under the system account on both Windows 2008 and 2003.
If I create a task and use ...Principal.UserId = "SYSTEM"; it works for 2008 but not for 2003.
What am I doing wrong?