Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.58 KB | None | 0 0
  1. using (var ts = new TaskService())
  2. {
  3.     ts.RootFolder.DeleteTask("MyTask", false);
  4.  
  5.     var td = ts.NewTask();
  6.     td.RegistrationInfo.Description = $"MyTask";
  7.  
  8.     td.Actions.Add(new ExecAction(@"C:\Windows\System32\cmd.exe", $@"start /b /wait cmd /c ""{scriptPath} >{outputPath} 2>&1""", workingDir));
  9.     td.Principal.RunLevel = TaskRunLevel.Highest;
  10.     td.Settings.Priority = ProcessPriorityClass.High;
  11.  
  12.     var task = ts.RootFolder.RegisterTaskDefinition("MyTask", td, TaskCreation.CreateOrUpdate, user, pass, TaskLogonType.Password);
  13.  
  14.     task.Run();
  15.  
  16.     return task;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement