Reputation: 21
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?
Upvotes: 0
Views: 607
Reputation: 21
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);
Upvotes: 0
Reputation: 51204
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);
Upvotes: 1