In this code, I am creating the batch file and run this file through c#.
While running the batch file, if the task name xxx is there, it will show “are you sure to delete the task” by clicking yes, it will execute the remaining lines in the batch file.
Is it possible to give yes automatically?If so please give your thoughts.
string schCmd = string.Format("SchTasks /Delete /TN xxx \n schtasks /create /tn xxx " +
"/tr {0} /sd {1} /st {2} /sc DAILY /mo {3} \n PAUSE"
, Server.MapPath("SqlScripts/sqlbackup.bat"), startDate, objAutoBackup.StartTime, objAutoBackup.Occurences);
sw.WriteLine(schCmd);
sw.Close();
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.WorkingDirectory = Server.MapPath("SqlScripts");
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "scheduler.bat";
proc.Start();
You can use the
/fswitch forschtasksto delete the task with prompting.http://msdn.microsoft.com/en-gb/library/windows/desktop/bb736357%28v=vs.85%29.aspx