I had to start a scheduled task. Most of the examples on MSDN use C++ for this, because there are no managed APIs to work with the task scheduler. Lucky for me the COM components for the Task Scheduler are pretty easy to use.
- Add a COM reference for the TaskScheduler component.
- Add using TaskScheduler; to your source.
- Use the following code as an example:
TaskScheduler.TaskScheduler ts = new TaskScheduler.TaskSchedulerClass();
ts.Connect("faq-xps", "username", "domain", "password");
ITaskFolder tf = ts.GetFolder(@"\");
IRegisteredTask task = tf.GetTask("Test"); // “Test” is the name of the task in the Scheduler
task.Run(null); // If your task requires parameters, then pass them instead of null
BTW, if you want to do this using a command line utility, you may want to try “schtasks” in a command prompt.
Tags van Technorati: scheduled task,COM,TaskScheduler,schtasks