This project has moved. For the latest updates, please go here.

Creating a job that runs on everyday at a specific time

Dec 17, 2008 at 12:00 AM
Great post!

I need to create a job that runs on everyday at a specific time (1:00AM everyday) & stop the job if it runs more than 3 hours.
Also, I like the job should run with the domain administrator account if possible.

Thanks in advance for the helps!

JH
Coordinator
Jan 24, 2009 at 1:45 AM
Edited Jul 9, 2009 at 7:50 PM
using (TaskService ts = new TaskService())
{
	TaskDefinition td = ts.NewTask();
	td.RegistrationInfo.Description = "Runs at 10, stops after 3";
	td.Settings.ExecutionTimeLimit = TimeSpan.FromHours(3);
	td.Settings.Enabled = true;
	td.Triggers.Add(new DailyTrigger { StartBoundary = DateTime.Today + TimeSpan.FromHours(10) });
	td.Actions.Add(new ExecAction("notepad.exe", "c:\\test.log", null));
	ts.RootFolder.RegisterTaskDefinition("TaskName", td, TaskCreation.CreateOrUpdate, @"DOMAIN\Admin", "AdminPwd", TaskLogonType.Password, null);
}