Hi

run or trigger a Windows Task Scheduler task from a C# application

 using System.Diagnostics;


void RunScheduledTask(string taskName)

{

    var startInfo = new ProcessStartInfo

    {

        FileName = "schtasks",

        Arguments = $"/Run /TN \"{taskName}\"",

        RedirectStandardOutput = true,

        UseShellExecute = false,

        CreateNoWindow = true

    };


    using (var process = Process.Start(startInfo))

    {

        string output = process.StandardOutput.ReadToEnd();

        process.WaitForExit();

        Console.WriteLine(output); // Optional: log output

    }

}


Previous
Next Post »