Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (var ts = new TaskService())
- {
- ts.RootFolder.DeleteTask("MyTask", false);
- var td = ts.NewTask();
- td.RegistrationInfo.Description = $"MyTask";
- td.Actions.Add(new ExecAction(@"C:\Windows\System32\cmd.exe", $@"start /b /wait cmd /c ""{scriptPath} >{outputPath} 2>&1""", workingDir));
- td.Principal.RunLevel = TaskRunLevel.Highest;
- td.Settings.Priority = ProcessPriorityClass.High;
- var task = ts.RootFolder.RegisterTaskDefinition("MyTask", td, TaskCreation.CreateOrUpdate, user, pass, TaskLogonType.Password);
- task.Run();
- return task;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement