Schedule an Exe in Windows Task Scheduler: Step by Step

You have an exe, maybe a .NET console app, and you want Windows to run it every night without anyone logged in. That is a job for Task Scheduler. You create a task with a trigger (when), an action (which exe, with which arguments and in which folder) and a few security options. This article walks through the Task Scheduler window step by step, then shows the same task as a schtasks command and in PowerShell. It also includes a small console app you can build and schedule to test the setup, because most failures come from the working folder and exit codes, not from the schedule.

Animated table of Task Scheduler settings and what to enter: a recognisable name on the General tab, run whether user is logged on or not under security options, a daily trigger, the full path of the exe in Program/script, and the exe folder in Start in. It is an illustration, not a screenshot.
Where each value goes in the task (illustration, not a screenshot).

Which exe is Task Scheduler?

Task Scheduler is opened with taskschd.msc (press Windows+R, type it, press Enter) or by searching the Start menu for Task Scheduler. Its command-line tool is schtasks.exe, documented by Microsoft as schtasks (Task Scheduler (Microsoft Learn)). If you arrived searching for scheduler.exe, sched.exe or schedule.exe, those are not the names Microsoft documents for Task Scheduler. The exe you want to schedule is your own program, and Task Scheduler is the thing that starts it.

A console app to schedule for testing

Use any exe. If you want something that proves the task ran and shows how exit codes behave, this small .NET 10 console app appends a line to a log file next to the exe and returns a non-zero code when you pass --fail:

var logPath = Path.Combine(AppContext.BaseDirectory, "nightlyjob.log");
var line = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} started, args=[{string.Join(" ", args)}], cwd={Environment.CurrentDirectory}";
File.AppendAllText(logPath, line + Environment.NewLine);
Console.WriteLine(line);

if (args.Contains("--fail"))
{
    File.AppendAllText(logPath, "  failed on purpose" + Environment.NewLine);
    return 2;
}
File.AppendAllText(logPath, "  finished ok" + Environment.NewLine);
return 0;

Two details in that code matter for scheduled tasks. The log path uses AppContext.BaseDirectory (the folder of the exe) instead of a relative path, because the current folder of a scheduled task is not guaranteed to be the exe folder. And the exit code is returned, so Task Scheduler can record success or failure. Build a Windows exe from any machine with the .NET 10 SDK:

dotnet publish -c Release -r win-x64 --self-contained false -o out

That produced NightlyJob.exe (about 160 KB) plus NightlyJob.dll and the runtime config in the out folder. Because it is framework-dependent, the Windows machine needs the .NET 10 runtime installed. Copy the folder to a fixed place such as C:\Jobs\NightlyJob. To publish a single self-contained exe instead, see how to create a single exe file with appsettings.json.

Schedule Exe in Windows Task Scheduler: create the task

Open Task Scheduler: search for Task Scheduler in the Start menu or run taskschd.msc.

Windows Start menu search for Task Scheduler showing the Task Scheduler app with Open, Run as administrator and Open file location options
Screenshot (Windows): searching for Task Scheduler.

In the Actions pane or the Action menu, choose Create Task. Pick Create Task rather than Create Basic Task, because only the full dialog has the security and condition options used below.

Task Scheduler Action menu with Create Task highlighted among Create Basic Task, Import Task and Display All Running Tasks
Screenshot (Windows): the Create Task command.

On the General tab, set:

  • Name: a name you will recognise later, for example NightlyJob.
  • Description: optional, but useful for the next person.
  • Security options: choose Run whether user is logged on or not so the job runs at night. Windows asks for the account password when you save. Tick Do not store password only if the job needs local resources only.
  • Run with highest privileges: only if the program needs administrator rights. Otherwise leave it off. The same setting from the command line is /rl HIGHEST (schtasks create (Microsoft Learn)).
Create Task dialog on the General tab with a name entered and Run whether user is logged on or not selected together with Run with highest privileges
Screenshot (Windows): General tab with name and security options.

Configure the trigger: when the exe runs

Open the Triggers tab and click New. Begin the task offers On a schedule, At log on, At startup, On an event and more. For a nightly run choose On a schedule, then Daily and a start time. Under Advanced settings you can repeat the task every few minutes for a duration. Keep Enabled ticked. The screenshot shows a weekly schedule on Monday to Wednesday.

Task Scheduler New Trigger dialog with Begin the task set to On a schedule, a weekly recurrence with Monday, Tuesday and Wednesday ticked, the Repeat task option and Enabled checked
Screenshot (Windows): a weekly trigger. Choose Daily for a nightly job.

Configure the action: which exe to start

On the Actions tab click New and fill in the three fields:

  • Action: Start a program.
  • Program/script: the full path to the exe, for example C:\Jobs\NightlyJob\NightlyJob.exe.
  • Add arguments (optional): command-line arguments, for example --daily.
  • Start in (optional): the folder that holds the exe, for example C:\Jobs\NightlyJob. Set it whenever your program reads or writes files by relative path.

The screenshots show an example program sql-data-loader.exe in C:\Test\File\data-loader, started with the argument --state true.

File Explorer window in the folder C:\Test\File\data-loader showing a single application named sql-data-loader, 171 KB
Screenshot (Windows): the exe location used in the example.
New Action dialog with Start a program selected, Program/script set to C:\Test\File\data-loader\sql-data-loader.exe, the argument --state true and Start in set to C:\Test\File\data-loader\
Screenshot (Windows): the New Action dialog filled in.

Configure the conditions

The Conditions tab adds requirements on top of the trigger. The task will not run if a condition you enabled is not met. By default Windows ticks Start the task only if the computer is on AC power, which stops a nightly job on a laptop running on battery. Untick it if the job must always run. The Idle and Network options are off by default.

Create Task dialog on the Conditions tab with Idle, Power and Network sections; the options to start only on AC power and to stop if the computer switches to battery power are ticked
Screenshot (Windows): Conditions tab.

Click OK, enter the password if asked, and the task appears in the Task Scheduler Library. Right-click it and choose Run to test it before waiting for the trigger.

Task Scheduler run command: schtasks /create and /run

The command line is faster to repeat on many machines. This creates a daily task at 02:00 that starts the console app with an argument (schtasks create (Microsoft Learn)):

schtasks /create /tn "NightlyJob" /tr "C:\Jobs\NightlyJob\NightlyJob.exe --daily" /sc daily /st 02:00
schtasks /run /tn "NightlyJob"
schtasks /query /tn "NightlyJob" /v /fo list
schtasks /delete /tn "NightlyJob" /f
  • /tn is the task name and /tr is the program to run. Microsoft says to give the fully qualified path of the file.
  • /sc is the schedule type: MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONCE, ONSTART, ONLOGON, ONIDLE or ONEVENT.
  • /ru SYSTEM runs the task as the system account, and /rl HIGHEST asks for the highest privileges.
  • /run, /query and /delete start, inspect and remove the task. /f on delete suppresses the confirmation.

If the exe path contains spaces, wrap the whole /tr value in double quotes and escape the inner quotes, for example /tr "\"C:\Program Files\Jobs\app.exe\" --daily". Note that the schtasks command does not have a field for “Start in”; if your program depends on its working folder, use the GUI, the PowerShell version below, or make the program use AppContext.BaseDirectory as the sample app does.

Create the same task with PowerShell

The ScheduledTasks module can set the working folder too. New-ScheduledTaskAction takes -Execute, -Argument and -WorkingDirectory (New-ScheduledTaskAction (Microsoft Learn)), and Register-ScheduledTask creates the task (Register-ScheduledTask (Microsoft Learn)):

$action  = New-ScheduledTaskAction -Execute "C:\Jobs\NightlyJob\NightlyJob.exe" -Argument "--daily" -WorkingDirectory "C:\Jobs\NightlyJob"
$trigger = New-ScheduledTaskTrigger -Daily -At 2:00AM
Register-ScheduledTask -TaskName "NightlyJob" -Action $action -Trigger $trigger

Run it in a PowerShell window opened as administrator if you get an access denied error. For scheduling PowerShell and Python scripts instead of an exe, see scheduling a PowerShell script with Task Scheduler and scheduling a Python script with Task Scheduler.

Task runs but nothing happens: common problems

  • The program cannot find its files. It was started from a folder other than the exe folder. Fill in Start in, or use absolute paths in your code.
  • Last Run Result is not 0. The program returned a non-zero exit code or could not start. Run the exe by hand in a console first. The meaning of codes such as 0x1 and 0x2 is covered in Task Scheduler 0x1 and 0x2 errors.
  • The task never starts on a laptop. The AC power condition on the Conditions tab is on by default.
  • It works when you are logged on but not otherwise. The account has no access to a mapped drive or user-specific resource. A background task has only the access of its account, so use full UNC paths and grant that account permission.
  • Arguments are ignored. Put them in Add arguments, not in the Program/script box.

What was tested and what was not

  • Run on macOS with .NET SDK 10.0.401: the console app ran with and without --fail and returned exit codes 0 and 2, and wrote its log next to the binary. dotnet publish -r win-x64 --self-contained false produced NightlyJob.exe. Microsoft documentation pages for schtasks, Register-ScheduledTask and New-ScheduledTaskAction were fetched and returned 200, and the parameters above were checked against them.
  • Not tested: every Task Scheduler step, the schtasks commands and the PowerShell script, because there is no Windows machine here, and I did not run the Windows exe. The screenshots come from an earlier Windows session for a different example program (sql-data-loader.exe), and their wording matches the steps above. The Task Scheduler behavior described, such as the default AC power condition, is from those screenshots and Microsoft’s documentation, not from a fresh run.

Summary

  • Task Scheduler is taskschd.msc; the command-line tool is schtasks. You schedule your own exe, not an exe named scheduler.
  • Create Task, then General (name, security), Triggers (when), Actions (full exe path, arguments, Start in) and Conditions (power, idle, network).
  • Return a non-zero exit code on failure, avoid relative paths, and test with Run before waiting for the trigger.

Found this useful?

Bookmark this page and share it with your team. Get new .NET, cloud and database tutorials in your inbox.

Task Scheduler exe FAQ

What is the Task Scheduler exe name: scheduler.exe, schedule.exe or sched.exe?

The console is opened with taskschd.msc, and the command-line tool is schtasks.exe. Neither is the program you schedule; Task Scheduler runs your own exe.

What is the Task Scheduler run command to start an exe with arguments?

In the Action dialog put the exe path in Program/script and the arguments in Add arguments. With schtasks, add the arguments after the exe path inside the /tr value, and quote the exe path if it contains spaces.

How do I run the exe when nobody is logged in?

On the General tab choose Run whether user is logged on or not. Windows asks for the account password. The task then runs without an interactive window and has only the access that account has.

Did your task run on the first try? Tell us in the comments what tripped you up.

Leave a Reply

Your email address will not be published. Required fields are marked *