0

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?

  • Does this answer your question? [Elevating process privilege programmatically?](https://stackoverflow.com/questions/133379/elevating-process-privilege-programmatically) – funie200 Jul 15 '20 at 11:59

2 Answers2

1

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);
vgru
  • 49,838
  • 16
  • 120
  • 201
0

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