Sub topic 16
Task Scheduler: triggers and actions
This chapter assumes you can open an elevated Command Prompt, know how Windows services and processes differ, and understand local user accounts and permissions. Task Scheduler is the Windows tool that runs a program or script automatically, either at a set time or when something happens on the computer. For the A+ Core 2 exam you should know what its parts are, where to open it, and which problems it solves.
What Task Scheduler does
Task Scheduler is a Microsoft Management Console snap-in (a management tool that plugs into MMC). It stores tasks. A task is a saved rule that says "when this happens, do that." Windows itself uses it heavily for maintenance, such as Windows Update checks, disk optimization, and Defender scans. Administrators use it for backups, cleanup scripts, and reminders.
You can open it in three common ways:
- Press Win+R, type
taskschd.msc, and press Enter. - Open Computer Management and expand System Tools, then Task Scheduler.
- Search the Start menu for "Task Scheduler" (it also appears in Windows Tools or Administrative Tools).
The window has a left pane (the Task Scheduler Library and its folders), a center pane (task list and details), and a right pane (the Actions list, such as Create Basic Task and Create Task).
The parts of a task
Every task is built from the same pieces. The exam often asks you to name them.
| Part | Question it answers | Example |
|---|---|---|
| Trigger | When does the task start? | Every day at 2:00 AM |
| Action | What does the task do? | Run a backup script |
| Condition | Should it be held back by system state? | Only if on AC power |
| Settings | How does it behave if something goes wrong? | Retry if it fails |
| General | Who runs it and with what rights? | Run as SYSTEM, highest privileges |
Triggers
A trigger defines when a task starts. A task can have more than one trigger. Common types are:
- On a schedule: one time, daily, weekly, or monthly.
- At log on: when a particular user, or any user, signs in.
- At startup: when the computer boots, before anyone signs in.
- On idle: when the computer has been idle for a set time.
- On an event: when a specific entry appears in an Event Viewer log. This links Task Scheduler to the Event Viewer chapter.
- On workstation lock or unlock, or on connection to a user session.
The difference between "at startup" and "at log on" matters. A startup task runs without any user signed in, so it cannot show a window to the user. A log-on task runs in that user's session.
Triggers also have options such as a start date, an expiration date, a repeat interval (for example every 15 minutes for 1 hour), and a delay. A disabled trigger does nothing, which is a common reason a task "never runs."
Actions
An action defines what the task does. The Basic Task wizard offers three choices:
- Start a program. This is the useful one. You give the path to an executable or script, optional arguments, and an optional "Start in" folder.
- Send an e-mail. Deprecated in current Windows versions.
- Display a message. Also deprecated.
In practice, you almost always use Start a program. To run a batch file, point to the .bat file. To run a PowerShell script, set the program to powershell.exe and put the script in the arguments.
The "Start in" field matters more than learners expect. If a script uses relative paths such as data\file.txt, the task looks for them in the "Start in" folder. If that field is empty, the working folder is usually C:\Windows\System32, and the script fails to find its files.
Conditions and settings
Conditions limit a task based on the machine's state:
- Start only if the computer is idle.
- Start only if on AC power, or stop if it switches to battery.
- Start only if a network connection is available.
- Wake the computer to run the task.
Settings control behavior:
- Allow the task to be run on demand.
- Run as soon as possible after a missed start. This is the setting to use if a laptop was off at 2:00 AM.
- Restart the task if it fails, with an interval and a count.
- Stop the task if it runs longer than a set time (the default is three days).
- If the task is already running, choose to do nothing, queue a new instance, or stop the existing one.
Security context
On the General tab you choose the account the task runs under. Options include your own account, another user, or SYSTEM. Two settings need attention:
- Run only when user is logged on lets the task show windows but does nothing when you are signed out.
- Run whether user is logged on or not runs in the background. Windows asks for the account password, and the task cannot show a window.
- Run with highest privileges gives the task an elevated token, similar to Run as administrator. Without it, a script that needs admin rights fails silently.
If the password of the account changes, tasks stored with the old password fail until you update them. This is a classic cause of "it worked for months, then stopped."
Creating a task from the command line
The graphical tool is the exam focus, but the command schtasks creates and manages the same tasks. It is useful for scripts and remote support.
schtasks /create /tn "NightlyBackup" /tr "robocopy C:\Data D:\Backup /E /R:2 /W:5" /sc daily /st 02:00 /ru SYSTEM
schtasks /query /tn "NightlyBackup" /v /fo list
schtasks /run /tn "NightlyBackup"
schtasks /delete /tn "NightlyBackup" /fThe /create line makes a daily 2:00 AM task that runs as SYSTEM. It needs an elevated prompt. The /query line shows its details, /run starts it immediately for testing, and /delete /f removes it without a confirmation prompt.
Troubleshooting a task that does not run
Work through these checks in order:
- Select the task and read the Last Run Result.
0x0means success. Other codes mean the program returned an error, or that Task Scheduler could not start it. - Open the History tab. If it is blank, history is turned off. Use Enable All Tasks History in the right pane.
- Confirm the trigger is enabled and its start date has not passed without a repeat.
- Check the account, its password, and whether Run with highest privileges is needed.
- Run the task manually with Run to separate a schedule problem from an action problem.
- Test the command by itself in Command Prompt, using full paths.
- Look at Event Viewer under Applications and Services Logs > Microsoft > Windows > TaskScheduler > Operational for details.
Exam-style comparison
| Need | Best tool |
|---|---|
| Run a backup every night at 2 AM | Task Scheduler |
| Run a script when a specific event is logged | Task Scheduler (event trigger) |
| Keep a background program running and restart it after a crash | Services console (recovery tab) |
| See which programs start at sign-in | Task Manager (Startup tab) |
| Read why a task failed | Event Viewer and the task's History tab |
Exercise
A technician created a task that runs a cleanup script at 1:00 AM. The task works when started manually, but it never runs at night, and the user's laptop is often asleep or shut down then. Which two settings should the technician check, and what should each be set to?
Show answer
Check the task's Conditions and Settings. On the Conditions tab, enable "Wake the computer to run this task" (and make sure it is not restricted to AC power if the laptop runs on battery). On the Settings tab, enable "Run task as soon as possible after a scheduled start is missed" so the task runs when the laptop is next on.
Exercise
A task that copies files with a relative path works in Command Prompt but fails under Task Scheduler with a "file not found" error. What field in the action most likely fixes this?
Show answer
The "Start in (optional)" field. Set it to the folder the script expects as its working directory. Using full paths in the script also solves it.