onefootswill
onefootswill

Reputation: 4107

How Can a Scheduled Task be Run from a Console App

Thought this would be a doddle. I have a number of Scheduled Tasks which are managed by the Task Scheduler. They have been configured to run on a schedule, but can also be run "on demand".

We want to funnel everything around these particular jobs through the Task Scheduler. As part of that, we want the ability to run the scheduled task from a Winforms App, a Console app etc. etc.

I can't seem to find a .NET 5 API for interacting with the Task Scehduler. I realize .NET is cross-platform now and this is very Windows-centric, but it would be nice if we could interact with something so fundamental to many systems out there.

Upvotes: 0

Views: 854

Answers (2)

Valentin Vasilev
Valentin Vasilev

Reputation: 111

try

            var processStartInfo = new ProcessStartInfo
            {
                Arguments = Arguments(),
                CreateNoWindow = true,
                FileName = Executable,
                ...
            };
            var process = System.Diagnostics.Process.Start(processStartInfo);

to run

schtasks.exe /run /TN TaskName

Upvotes: 0

feddoh
feddoh

Reputation: 31

For running from commandline / console this should help: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/schtasks

Upvotes: 1

Related Questions