Starting a remote scheduled task

♀尐吖头ヾ 提交于 2019-12-17 20:08:27

问题


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:


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();       
}



回答2:


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.



来源:https://stackoverflow.com/questions/19243534/starting-a-remote-scheduled-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!