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.

jayt.dev
  • 975
  • 6
  • 14
  • 36
  • Probably you could use the [PsExec utility](http://technet.microsoft.com/en-us/sysinternals/bb897553) from PsTools Suite – Steve Oct 08 '13 at 09:13

2 Answers2

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();       
}
C4stor
  • 8,355
  • 6
  • 29
  • 47
  • Microsoft.Win32.TaskScheduler namespace does not exist. Is it in another .Net version perhaps? – jayt.dev Oct 08 '13 at 09:33
  • Oh, my bad, I totally forgot it was not a native library. It comes from here : http://taskscheduler.codeplex.com/ – C4stor Oct 08 '13 at 09:35
  • Great stuff. Note you're missing a closing parenthesis: `using (TaskService tasksrvc = new TaskService(server.Name, login, domain, password))` – Sir Crispalot Jun 21 '16 at 11:59
  • https://stackoverflow.com/a/41861081/1117305 helped me, if you're running the task with a user that is not the owner. – AJ AJ May 04 '20 at 13:01
  • taskscheduler.codeplex.com not found – Kiquenet Mar 17 '22 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.

Tushar
  • 481
  • 6
  • 26