C# start a scheduled task

浪尽此生 提交于 2019-12-01 03:56:22

I suggest using one of the .NET wrappers for the task scheduler.

I have used this one in the past to good effect.

using Microsoft.Win32.TaskScheduler;

using (TaskService tasksrvc = new TaskService(@"\\" + servername, username, domain, password, true))
{       
    Task task = tasksrvc.FindTask(taskSchedulerName);
    task.Run();
}   

I use the following which works fine, may be of help (plugging in your arguments)

var p = new Process
                            {
                                StartInfo =
                                    {
                                        UseShellExecute = false,
                                        FileName = "SCHTASKS.exe",
                                        RedirectStandardError = true,
                                        RedirectStandardOutput = true,
                                        CreateNoWindow = true,
                                        WindowStyle = ProcessWindowStyle.Hidden,
                                        Arguments = arguments
                                    }
                            };
            p.Start();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!