I have a site running on IIS. I need to run the schtasks.exe from the site. I tried the following
Process proc = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.FileName = @"C:\Windows\System32\schtasks.exe";
proc.StartInfo.Arguments = "/create /tn mylbat /tr MYLExe.exe /s xxx /u xxx\xxx /p xxx /sc daily;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = false;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
proc.Start();
proc.WaitForExit();
The command when executed on cmd works fine but when I tried to execute it on a website running on IIS no task is being added. And also its working on sites that are not hosted on IIS.
Edit I: its working when the site's app pool identity is set to LocalSystem but I need it to be working as a Network Service.
What is missing!!!