This project has moved and is read-only. For the latest updates, please go here.

Creating a job that runs on a specific week day at a specific time

Jun 18, 2008 at 3:47 PM
I  need to create a job that  runs  on a specific week day (say every tuesday ) at  a specific time (at 4 P.M.) . Moreover, i want  that  job should run with the credentails of  currently logged on user  OR  in other words....i don't want  to ask from the user his/her credentials . I tried doing this but unable to do it . One thing i am not getting is that  how to specify the time(like 4 P.M. mentioned above) in a weekly trigger .  Please help me out .
Jul 18, 2008 at 6:39 PM
Edited Jul 18, 2008 at 6:40 PM


// Get the service on the local machine
TaskService ts = new TaskService();




// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();
td.RegistrationInfo.Description =
"Does something";


 // Set the principle to be the interactive user
td.Principal.LogonType =






// Create a weekly trigger that will run every Tuesday
weeklyTrigger = new WeeklyTrigger();
weeklyTrigger.DaysOfWeek =
weeklyTrigger.WeeksInterval = 1;


 // Start the trigger from today at 4pm onward (DateTime.Today starts at midnight so adding 16 hours makes it 4pm)
weeklyTrigger.StartBoundary = 






// 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 
"Test", td);