Posts

Showing posts from June, 2017

Enable, Disable and Start the task of task scheduler in C#.Net

Below function demonstrates how to enable, disable and run the already created scheduled task. It will first check if the task exists in task scheduler:


publicstaticvoidupdateUserTaskInScheduler(string action) { try { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "cmd.exe"; startInfo.Arguments = "/C schtasks /query /TN <<TaskNameWithQuotes>>; //Check if task exists startInfo.RedirectStandardOutput = true; startInfo.UseShellExecute = false; startInfo.CreateNoWindow = true; startInfo.WindowStyle = ProcessWindowStyle.Hidden; if (System.Environment.OSVersion.Version.Major < 6) { startInfo.Verb = "runas"; } using (Process process = Process.Start(startInfo)) { // Re…