views:

327

answers:

2

also how can you tell if it is running, enabled/disabled, etc.?

+3  A: 

There is a Task Scheduler API that you can use to access information about tasks. (It is a com library, but you can call it from C# using pinvokes)

There is an article on codeproject that provides a .net wrapper for the API.

[There is also the schtasks command - more info]

Simon P Stevens
checked out that codeProject wrapper. It works great. I'm really surprised that there are no scheduleTask objects in the .net framework!
KevinDeus
A: 

btw, IRT my accepted solution, here is the CodeProject wrapper code (see http://www.codeproject.com/KB/cs/tsnewlib.aspx ) needed to verify that a scheduledTask exists

I use this in an Integration test so the Assert is NUnit..

public static void VerifyTask(string server, string scheduledTaskToFind)
{
     ScheduledTasks st = new ScheduledTasks(server);

     string[] taskNames = st.GetTaskNames();
     List<string> jobs = new List<string>(taskNames);

     Assert.IsTrue(jobs.Contains(scheduledTaskToFind), "unable to find " + scheduledTaskToFind);

     st.Dispose();
}

to check if it is enabled, you can do the following:

Task task = st.OpenTask(scheduledTaskToFind);
Assert.IsTrue(task.Status != TaskStatus.Disabled);
KevinDeus