Home

Awesome

Task Scheduler Managed Wrapper

Version Downloads Build status

The original .NET wrapper for the Windows Task Scheduler that aggregates the multiple versions and provides localized controls for editing.

Quick Links

Installation

This project's assemblies are available via NuGet or manually from the .zip files in the Releases section.

LinkPackage NameDescription
NuGetTaskSchedulerMain Library
NuGetTaskSchedulerEditorUI Library

You can also find prerelease NuGet pacakges on the project's AppVeyor NuGet feed.

Once referenced by your project, all classes can be found in the Microsoft.Win32.TaskScheduler namespace.

Project Components

Main Library

Microsoft introduced version 2.0 (internally version 1.2) with a completely new object model with Windows Vista. The managed assembly closely resembles the new object model, but allows the 1.0 (internally version 1.1) COM objects to be manipulated. It will automatically choose the most recent version of the library found on the host system (up through 1.4). Core features include:

The currently supported localizations include: English, Spanish, Italian, French, Chinese (Simplified), German, Polish and Russian. Others localizations can be added upon request, especially if you're willing to help with translations.

The project is based on work the originator started in January 2002 with the 1.0 library that is currently hosted on CodeProject.

UI Library

A second library includes localized and localizable GUI editors and a wizard for tasks which mimic the ones in Vista and later and adds optional pages for new properties. Following is the list of available UI controls:

Sample Code

There is a help file included with the download that provides an overview of the various classes. There are numerous examples under the "Documentation" tab.

You can perform a number of actions in a single line of code:

// Run a program every day on the local machine
TaskService.Instance.AddTask("Test", QuickTriggerType.Daily, "myprogram.exe", "-a arg");

// Run a custom COM handler on the last day of every month
TaskService.Instance.AddTask("Test", new MonthlyTrigger { RunOnLastDayOfMonth = true }, 
    new ComHandlerAction(new Guid("{CE7D4428-8A77-4c5d-8A13-5CAB5D1EC734}")));

For many more options, use the library classes to build a complex task. 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)
   {
      // Get the service on the remote machine
      using (TaskService ts = new TaskService(@"\\RemoteServer", "username", "domain", "password"))
      {
         // Create a new task definition and assign properties
         TaskDefinition td = ts.NewTask();
         td.RegistrationInfo.Description = "Does something";

         // Create a trigger that will fire the task at this time every other day
         td.Triggers.Add(new DailyTrigger { DaysInterval = 2 });

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

         // Register the task in the root folder.
         // (Use the username here to ensure remote registration works.)
         ts.RootFolder.RegisterTaskDefinition(@"Test", td, TaskCreation.CreateOrUpdate, "username");
      }
   }
}

For extended examples on how to the use the library, look in the source code area or look at the Examples Page. The library closely follows the Task Scheduler 2.0 Scripting classes. Microsoft has some examples on Microsoft Docs around it that may further help you understand how to use this library.


This project appreciatively uses:

<img alt="ReSharper from JetBrains" src="docs/icons/resharper-logo.svg" height="5%" width="5%"/> ReSharper from JetBrains

<img alt="Sandcastle Help File Builder" src="https://github.com/EWSoftware/SHFB/blob/master/NuGet/SHFB.png?raw=true"/> Sandcastle Help File Builder