Created
June 14, 2013 11:56
-
-
Save sphingu/5781276 to your computer and use it in GitHub Desktop.
Add Schedular to TaskSchedular in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Win32.TaskScheduler; | |
private void AddTask() | |
{ | |
// Get the service on the local machine | |
using (TaskService ts = new TaskService()) | |
{ | |
// Create a new task definition and assign properties | |
TaskDefinition td = ts.NewTask(); | |
td.RegistrationInfo.Description = "Tesing Schedule"; | |
// Create a trigger that will fire the task at this time every other day | |
td.Triggers.Add(new DailyTrigger { DaysInterval = 1, StartBoundary = DateTime.Now.Subtract(DateTime.Now.TimeOfDay).AddHours(19) }); | |
// Create an action that will launch Notepad whenever the trigger fires | |
td.Actions.Add((new ExecAction("C:\\Mail\\EntryReport.exe", null, null))); | |
// Register the task in the root folder | |
ts.RootFolder.RegisterTaskDefinition(@"EntryReportScheduler", td); | |
// Remove the task we just created | |
ts.RootFolder.DeleteTask("Test"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment