I need to write a C# program to change the 'Run As' field of scheduled tasks on remote systems.
What are some of the libraries I should be looking at to achieve this?
I need to write a C# program to change the 'Run As' field of scheduled tasks on remote systems.
What are some of the libraries I should be looking at to achieve this?
You can spawn a process to call SCHTASKS.exe
Here is some code that I used to do just that:
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.FileName = "SCHTASKS.exe";
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.Arguments = String.Format(
"/Change /S {0} /TN {1} /RU {2}\\{3} /RP {4}",
MachineName,
ScheduledTaskName,
activeDirectoryDomainName,
userName,
password
);
p.Start();
// Read the error stream first and then wait.
string error = p.StandardError.ReadToEnd();
p.WaitForExit();
if (!String.IsNullOrWhiteSpace(error))
{
throw new Exception(error);
}