Task Scheduler Guide
A decent tool since Vista but already existing as early as Win 3.11, Task Scheduler is an ireplaceable tool to manage system scripts.
As the name implies, it is the Windows version of Unix’s Cron. The software manages events that are executed at specified times. It’s essentially a calendar of tasks.
Setting up tasks is more cumbersome compared to Cron due to everything being done through a graphical interface. Instead of quickly writing a one-line rule with a path to a script, we have to navigate through multiple clicks.
On the other hand, Task Scheduler is more user-friendly. Unlike Cron, which requires explanation, a task in Task Scheduler can be created with minimal knowledge and research.
This makes it particularly useful in freelancing, where a client whose knowledge of PCs is limited can be easily guided through the setup process without becoming frustrated.
Another advantage is reliability: in Cron, scripts can sometimes run unpredictably, and troubleshooting may require technical knowledge and can be cumbersome. Task Scheduler is generally more reliable in this regard.
Starting Task Scheduler
The easiest way to start Task Scheduler is by pressing the Start button on your keyboard and then typing ‘task scheduler’. You don’t have to type the whole phrase, as the autofill will suggest it. Just press Enter when it appears.
For those who prefer keyboard shortcuts or want a more direct approach, you can press Win+r and type ‘taskschd.sc’ in the Run dialog that appears.
The initial screen might look like this, or somewhat similar, depending on which menu panels you have enabled or disabled:
Right off the bat, you can see some limitations in the interface. Sorting tasks by column used to work on Windows 10, but it may not function now (at least in my experience). There’s also no search functionality.
This means locating a single task when you have hundreds can be extremely problematic. After focusing on the table, you can type the name of the task you’re looking for and it will keep focusing first direct match, but if there are many tasks with near-identical names, it’s not very helpful.
Adding a new task
There are two procedures for creating tasks:
-
Create Basic Task - A streamlined wizard with limited options that sets sensible defaults. This is designed for inexperienced users to avoid confusion.
-
Create Task - The full version with all options visible, taking slightly longer to set up but offering more control.
In this article, we’ll cover option 2, as it only takes about one to five minutes to fully grasp and some of the extra options are useful.
In the right Actions panel, click Create Task. Alternatively, in the top program menu, click Action and select Create Task from the dropdown menu.
Tab: General
A window similar to the one pictured below will appear. It has 5 tabs, defaulting to the first one, General. Here are explanations for all the options. The one marked with an exclamation mark (!) is required to set up before continuing.
-
Name(!): Name of the task. Choose something concise yet descriptive enough that you’ll immediately know what the task does when you encounter it a year from now. Using unique initial letters makes it easier to find by typing.
-
Description: Self-explanatory. Here you can be as verbose as you like. Taking a moment to write a detailed description is worthwhile, especially if you plan to have many tasks.
-
When running the task, use the following user account: If the account which will be running the script is different from the currently logged-in account, you need to change it here.
-
Run only when user is logged in / Run whether user is logged in or not: Scripts that require user interaction or access to variables created during the log-in process need the first option. The second option hides the task execution and is more suitable for non-interactive background tasks. If unsure, leave it at the default first option.
-
Run with highest privileges: Enable this only if you know you need it. Otherwise, leave it off, as giving highest privileges to a script can cause significant problems if the script misbehaves.
-
Hidden: This option hides the task from the list of tasks. Use with caution and only when necessary for privacy or security reasons.
-
Configure for: Increases compatibility in some edge cases. It’s usually safe to leave this at the default setting.
Tab: Triggers
This is where Task Scheduler really shines and makes Crontab look like child’s toy.
Triggers are conditions which, when met, start the task. In most cases, tasks will have one trigger, but there are instances where multiple triggers are needed. It’s much more convenient to define multiple triggers than multiple tasks, each with a different trigger.
The most commonly used trigger, which is also the default, is On the schedule. We choose a specific date, or a daily/weekly/monthly cycle for the task to be executed.
Often, we want the script to run whenever the computer is on, without concerning ourselves with dates and cycles. We can choose to start the task at logon or startup.
A fantastic feature for power users and unique cases is On an event. For example, when a specific event is logged in the Windows Event Viewer, it could trigger our script to start.
Workstation lock/unlock triggers are very useful in work environments when we want certain scripts to run only when the workstation is in use.
As you can see, the possibilities with Task Scheduler Triggers are vast. Microsoft has made many questionable decisions in the directions its applications are going, but here they’ve done an excellent job.
Let’s discuss some of the Advanced settings:
-
Delay task for up to X: When the trigger registers, instead of starting the task immediately, Task Scheduler waits a specified amount of time before starting.
-
Repeat task every X for the duration of Y: When we want to start a script at system logon and then run every hour, choose Begin a task: On a schedule and select Repeat task every: 1 hour. If you want it to repeat indefinitely, make sure to select For a duration of: Indefinitely.
-
Stop Task if it runs longer than X: Very useful for poorly written scripts which tend to fail and then hang indefinitely, especially if they consume resources while doing so. When dealing with such problematic code, we can limit it with settings like 30 minutes. Note that you’re not limited to options in the drop-down list; you can enter custom values.
-
Expire: Another useful feature. We can have a script collecting data until publication of that data, at which point we want the script to be disabled until we start another data gathering session later in the year. It’s convenient to set up the task expiration date instead of having to remember to disable it manually.
-
Enabled: The most self-explanatory of all the options, but potentially troublesome. It can be clicked not only by clicking on the box or the name, but the clickable area extends to half of the entire container window width. This makes it possible to accidentally click and disable it, potentially causing confusion about why the task isn’t working.
Tab: Actions
After going through various options and scheduling settings for our task, we now create the actual task that will be running.
Here, everything is straightforward. We click on Browse and provide the location of the program to run. If we want to start a program with additional arguments, we specify them in the second field.
The third box, Start in (optional) provides a directory where the program will start. This will be the context directory, useful for example when the program uses relative paths and we want it to have access to files in that particular directory.
Another use is for log file generation. Starting in a specific directory could mean the script generates logs in that directory, which might be desired behavior.
Tab: Conditions
Conditions are an extra set of if statements guarding the task. If any condition is not met, the task is prevented from running.
All of the options are self-explanatory, so there’s no need to expand on any of them.
One particularly useful feature is “Start only if the following network connection is available”. This is especially useful for users in countries where high-speed internet access is not yet common. A PC could be connected to low-speed internet, and for a few hours of the day, high-speed internet could become available.
Task Scheduler could wait for the better option and only then execute the script to enable faster downloading of content. Another use case is waiting for a connection where there is no monthly download limit.
Tab: Settings
-
Allow task to be run on demand: Enables manual execution of the task at any time via the Task Scheduler interface or command line. This is useful for creating extra backup runs of the script or when the script is still in a testing stage and we need to manually execute it to verify what is not working and why.
-
Run task as soon as possible after a scheduled start is missed: A crucial setting for all scripts handling backup. For example, if we schedule a backup at 10 AM but the system is off at that time, ticking this setting ensures that when the PC starts later that day, Task Scheduler recognizes that the backup script did not run and will execute it.
-
If the task fails, restart every [X] minutes, up to [Y] times: Enable this setting for network-related tasks, such as scripts that upload files to a server. If the task fails due to a temporary network issue, it will retry a few times before giving up, increasing the chances of success.
-
Stop the task if it runs longer than [X] hours and [Y] minutes: Enable this setting for scripts that perform resource-intensive calculations or data processing. If the script has a bug causing it to run indefinitely, this setting will prevent it from consuming system resources indefinitely.
-
If the running task does not end when requested, force it to stop: Enable this setting for tasks that interact with external systems, such as automated tests or data transfers. If these tasks hang due to unresponsive external systems, forcing them to stop prevents system resources from being tied up.
-
If the task is already running, then the following rule applies: A very useful set of conditions. When a script is scheduled to run every hour and the old instance hangs and consumes resources, these can stack up. If it doesn’t quit as expected and continues its work, after an hour we could have two scripts doing the same thing which, if they manipulate the same data simultaneously, can have catastrophic results. This setting provides safety nets for these and many other conditions.
Tab: History
Finally, we have the task execution history. It is disabled by default, but enabling it won’t significantly impact system performance. It won’t create logs that consume much disk space, won’t cause excessive disk I/O, and won’t consume much processing power.
The exception is when we have a very large number of tasks that run frequently, but these are very rare cases.
In general, when we are working on a complex system task whose development will take a while and it’s going to be executed many times during each working session, it is useful to enable history for easy execution status tracking.
Last Run Result
One poorly designed aspect of Task Scheduler is the execution codes, visible in the main task table.
Each time a task is executed, there is a code describing the status of that execution. Some of these statuses have both a hexadecimal code (0xnum) and a description, from which we can determine if it worked well and if not, why. However, other times we just receive the code and have to manually search the web to understand what happened with our task.
Below is a list of all the common execution codes and what they mean:
- 0x0: Success - The task completed successfully without errors.
- 0x1: Incorrect function call - This often indicates a generic error with the function call within the script or program.
- 0x2: File not found - The script or program could not find a file it needs to execute.
- 0x41300: Task is ready to run at its next scheduled time - The task is correctly configured and will run at the next scheduled time.
- 0x41301: Task is currently running - The task is actively running.
- 0x41302: Task is disabled - The task needs to be manually enabled to run.
- 0x41303: Task has not yet run - The task has never been executed since it was created or last updated.
- Task is running interactively as a different user - The task is running interactively under a different user account.
- 0x41305: Task is not running - The task is not currently running.
- 0x80070005: Access is denied - The task does not have the necessary permissions to execute.
- 0x8007010B: Directory name is invalid - The task points to a directory that is invalid or does not exist.
- 0xC000013A: The application was terminated by Ctrl+C - The task was terminated by the user manually.
Final word
Task Scheduler is a powerful and versatile tool that can significantly enhance your Windows experience. Whether you’re a casual user looking to automate simple tasks or a power user seeking to orchestrate complex workflows, Task Scheduler offers the flexibility and features to meet your needs. By mastering its various settings and options, you can create sophisticated automated processes that save time, improve system efficiency, and ensure critical tasks are executed reliably.
However, like any powerful tool, Task Scheduler requires careful use and management. It’s important to regularly review and maintain your scheduled tasks, ensuring they’re still necessary and functioning as intended. Pay attention to error codes and execution history to troubleshoot any issues that arise. With proper setup and monitoring, Task Scheduler can be an invaluable asset in your Windows toolkit, helping you streamline your work and make the most of your computer’s capabilities.