10

How is it possible to start a scheduled task that is not locally stored but on another computer on your network, using c#?

It seems that i cannot determine the path of the schedule task. Also I just need to start the task. I dont need to wait for it to finish and I do not need any error handling. Just run the task.

1
  • Probably you could use the PsExec utility from PsTools Suite
    – Steve
    Commented Oct 8, 2013 at 9:13

2 Answers 2

16

Install NuGet package: Task Scheduler Managed Wrapper and then you can use:

using Microsoft.Win32.TaskScheduler;

using (TaskService tasksrvc = new TaskService(server.Name, login, domain, password))
{
    Task task = tasksrvc.FindTask(taskName);
    task .Run();       
}
5
  • Microsoft.Win32.TaskScheduler namespace does not exist. Is it in another .Net version perhaps?
    – jayt.dev
    Commented Oct 8, 2013 at 9:33
  • Oh, my bad, I totally forgot it was not a native library. It comes from here : taskscheduler.codeplex.com
    – C4stor
    Commented Oct 8, 2013 at 9:35
  • Great stuff. Note you're missing a closing parenthesis: using (TaskService tasksrvc = new TaskService(server.Name, login, domain, password)) Commented Jun 21, 2016 at 11:59
  • stackoverflow.com/a/41861081/1117305 helped me, if you're running the task with a user that is not the owner.
    – AJ AJ
    Commented May 4, 2020 at 13:01
  • taskscheduler.codeplex.com not found
    – Kiquenet
    Commented Mar 17, 2022 at 22:33
-3

It is not working because you are missing the using closing brackets

using (TaskService tasksrvc = new TaskService("server.Name", "login", 
                                                             "domain", "password"))
{                   
    Task task = tasksrvc.FindTask("taskname");
    task.Run();       
}

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.