I need to create a task in Task Scheduler with high privileges, but the function only takes 3 parameters...
TaskService.Instance.AddTask("Test Task", new BootTrigger() , new ExecAction("C:\\myapp.exe");
how to solve this problem?
Presuming that you are referring to the .NET wrapper for the Windows Task Scheduler , you should first use TaskService.Instance.NewTask()
to create an instance of the task, and then configure it as explained in the examples section.
Something like:
var td = TaskService.Instance.NewTask();
...
td.Settings.Priority = System.Diagnostics.ProcessPriorityClass.Normal;
td.Triggers.Add(new BootTrigger());
td.Actions.Add(new ExecAction("C:\\myapp.exe"));
...
TaskService.Instance.RootFolder.RegisterTaskDefinition("MyTask", td);
Solved:)
TaskDefinition td = TaskService.Instance.NewTask();
td.RegistrationInfo.Description = "Does something";
td.Principal.RunLevel = TaskRunLevel.Highest;
BootTrigger bt = new BootTrigger();
bt.Delay = TimeSpan.FromMinutes(1);
td.Triggers.Add(bt);
td.Actions.Add("C:/Users/myapp.exe");
TaskService.Instance.RootFolder.RegisterTaskDefinition("Test", td);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.