The Windows Task Scheduler can run almost any program automatically — at a time and in a way you set.
Task Scheduler is part of Windows’ Administrative Tools, a suite of professional-quality, system-management utilities used to adjust and control many of the operating system’s essential functions and features.
Starting with XP, these tools are either built into Windows or are offered as free add-ons. This guide to using Task Scheduler is the fourth installment in our Windows Administrative Tools series.
Part One of the series explains what the tools are and how to make them easily available from the Windows Start menu.
Part Two discusses Windows’ Performance Monitor, which reports in real time what’s happening within the OS as programs run — or fail to run!
Part Three describes how to use Windows’ Memory Diagnostic tool to thoroughly test your system’s random-access memory.
I’ll focus on the Windows 7 version of Task Scheduler because that’s the OS most Windows Secrets readers are currently running. Windows XP’s and Vista’s Task Schedulers are similar, so many of the instructions given below also apply to those operating systems. I’ll also include links for Vista- and XP-specific information.
The basics of how Task Scheduler works
To understand how Task Scheduler automatically runs defined tasks, you have to understand triggers. In many cases, a trigger is simply a specific time when Task Scheduler should run a task. You set both the time and the task. Time-based triggers can be once-only (such as “at 8 p.m.”) or repeating (“every Tuesday at 8 p.m. for the next 52 weeks”).
There are, however, other kinds of triggers — for example, system events (such as startup, sign-on, sign-off, or shutdown) or just about any kind of error condition.
You can define any number of tasks. For example, you might have Task Scheduler run a cleanup tool at every system shutdown, automatically launch Windows Network Diagnostics when a connection fails, or start a malware scan late at night when your PC is otherwise idle.
Task Scheduler can do much more than merely launch a program. Obviously, once a program is launched, you want it to actually do something — not just idly sit there.
To specify what the program should do once it’s running, you use special commands — technically called command line inputs or arguments — which are really nothing more than plain-text equivalents of the mouse clicks normally used to control a program.
In short, any program that accepts command-line inputs can be controlled via Task Scheduler.
An app’s online support pages will tell you what command-line inputs are allowed — if any — and how to use them. Here are two examples:
Piriform’s CCleaner clean-up tool accepts a few command-line inputs; they’re listed and explained on the app’s advanced usage page. You can, for instance, use Task Scheduler to automatically run CCleaner and then shut down Windows when CCleaner is done.
Searching the Microsoft site, you’ll find that Windows’ Remote Desktop Connection (RDC) accepts command-line inputs. An MS Help & How-to page lists supported command-line options.
Searching a publisher’s support pages will sometimes reveal that there are two versions of an app — one with a normal graphical user interface and another, nongraphical version specifically intended for command-line use. That stripped-down version will work nicely in Task Scheduler. (I’ll give an example below.)
Other ways to discover command-line inputs
Although querying a software publisher’s site is the best and surest way to discover which command-line inputs are allowed, some programs will list the inputs they’ll accept — if you ask them the right way. Here’s how:
From an administrator-level account, open a command window. (Need help? Check out Microsoft’s online Command Prompt FAQ.)
Next, inside quotation marks, type the full path and name of the program you wish to control. After the trailing quotation mark, add a space, forward slash, and question mark.
For example, to see what command line inputs are accepted by Windows’ built-in defragmentation tool, defrag.exe, type:
Press Enter, and defrag will then list all the command-line inputs it can accept.
If the /? option doesn’t work with a given program, try -h (which stands for -help) as an alternative.
For example, to see what command line inputs you can use with the 7-Zip file compression and encryption utility, you type:
“c:\program files\7-zip\7z.exe” -h
Press Enter. 7-Zip will then list all the command-line inputs it can accept.
If a program fails to respond to either the /? or -h options, it’s likely the program does not accept command-line inputs — and thus cannot be controlled via Task Scheduler.
Real-life example: custom antivirus scanning
In the Sept. 20 LangaList Plus item, “A fine-tooth comb process for malware removal,” I mentioned using Task Scheduler “to set up a full, weekly MSE [Microsoft Security Essentials] scan in the middle of the night so … there’s absolutely no impact on my productive use of the PC.”
Many readers wrote, asking for instructions for how to do just that. So I’ll use scheduling automated MSE scans as a simple Task Scheduler example.
If you search the Microsoft site for command-line options for MSE (for example, a Microsoft Community page), you’ll see that MSE is one of those tools that exist in two versions — and both automatically install on your system when you download MSE. The first, msseces.exe, is the version typically seen with the full graphical interface; MpCmdRun.exe is a stripped-down version specifically intended for use with command-line inputs.
The aforementioned Microsoft Community page lists the command-line inputs that MpCmdRun.exe supports, but you also can find them by using the direct-query technique described earlier. In fact, seeing the direct-query syntax can make it easier to set up MSE in Task Scheduler, so let’s take a look.
Assuming you have MSE installed on your system, open an admin-level command window and type:
“C:\Program Files\Microsoft Security Client\MpCmdRun.exe” /?
You’ll see a list of all the command-line inputs that MpCmdRun accepts. Those of immediate interest include the -scan command, which tells MSE to perform a scan; the -scantype option, which defines the type of scan; and the 2 option, which initiates a full scan.
So here’s the complete, plain-text command to tell MSE to launch and perform a full scan:
“C:\Program Files\Microsoft Security Client\MpCmdRun.exe” -scan -scantype 2
With that information in hand, the hard part’s done. Now, all that’s left is to feed that command into Task Scheduler.
It’s easy; here’s how:
- Step 1: Open Task Scheduler. Click Start/Control Panel/System and Security. Under Administrative Tools, click the Schedule tasks link. (Or select it from the Start menu’s Administrative Tools, if you’ve set it up.)
- Step 2: When Task Scheduler opens, click the Create Basic Task option in the right-hand pane, highlighted in Figure 1. (You’ll probably see tasks for other apps in the center Task Scheduler pane, automatically created when the apps were installed.)
- Step 3: In the Create a Basic Task dialog box, give your new task an obvious name and enter an optional, fuller description, as shown in Figure 2. Click Next when you’re done.
- Step 4: In the Task Trigger window, select the instance or frequency with which you want to run the task. In this case, you’re setting up a weekly scan, so you should choose the Weekly trigger, as you’ll see in Figure 3. Click Next when you’re ready to move on.
- Step 5: If you selected a frequency, the next windows lets you further refine the task’s schedule (see Figure 4). Here, I’ve set the scan to run every Sunday at 3 a.m. Click Next when you’re done.
- Step 6: Now select what should happen when the task is triggered. For our example, you want Task Scheduler to Start a Program — that is, to launch MSE. (Figure 5.) Click the “Start a program” button and then click Next.
- Step 7: Fill in the Start a Program specifics window. Use the command-line information you obtained earlier, as shown in Figure 6. Click Next when you’re done.
- Step 8: Double-check the information in the Summary display, as shown in Figure 7, and click Finish to finalize your new task. Checking Open the Properties dialog for this task when I click Finish (before clicking Finish) will let you make additional tweaks to your task.
- Step 9: The new task’s Properties window includes security options, as shown in Figure 8. For an unattended MSE scan, select Run whether user is logged on or not and Run with highest privileges. Click OK when you’re done. (Because you specified Run with highest privileges, you’ll be asked for your admin password when you click OK.)
- Step 10: You’re almost done! But first, take a moment to check your work. In the center pane of Task Scheduler’s main window, scroll through the Active Tasks list (shown in Figure 9) and find the task you just created. Double-click the new task and double-check its settings.
- Step 11: Controls in the Selected Item pane (lower-right of Task Scheduler windows) let you run, end, disable, and delete the task. In this case, click Run (highlighted in Figure 10) to test the new task. If you need to make changes, use the tabbed area of the central pane to edit the task’s triggers, actions, conditions, and settings until things work the way you want them to.
Note: In this example, you’re running the nongraphical, command-line version of MSE, so you won’t see MSE’s usual display window. The only immediate indication that MSE is working will be the heavy disk activity that’s typical of a full scan.
- Step 12: Once your test scan appears finished, launch MSE’s normal graphical interface and check the Last scan text at the bottom of the main dialog window (see Figure 11). It should show that a full scan was just completed.
Advanced: Use system events as triggers
You may have noticed in Figure 3 that you can use specific system events as task triggers. System events include the starting and stopping of all programs and drivers, all errors, most user-initiated actions, and more. Windows assigns each system event an event ID. If you know an event ID, you can specify it as a task trigger.
There are literally thousands — perhaps tens of thousands — of event IDs, and (alas) there’s no single, central database containing them all.
But here are the best sources for event-ID information that I’ve found:
- MS TechNet’s Events and Errors listing
- MS Support’s “Look up an error message” page.
- MS TechNet blog, “How to find all possible event ID’s for a given event source”
- UltimateWindowsSecurity.com’s listing of Windows Security Log Events
- And this simple, but very complete, event ID lookup page from EventID.net
Digging deeper for Win7, Vista, and XP
There’s plenty more information available online for users of all skill levels and for all current versions of Windows.
Here are some great resources:
- MS support article 308569, “How to schedule tasks in Windows XP”
- MS TechNet article, “Windows Vista Task Scheduler”
- MS Help & How-to article, “Schedule a task” (Vista)
- MS Help & How-to article, “Schedule a task” (Windows 7)
- MSDN Task Scheduler page
- MSDN Task Scheduler 2.0 page
Once you get the hang of it, you can use Task Scheduler to have Windows automatically do just about everything — except make the coffee!
Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 10, Windows 8, Windows 7, Firefox, Internet Explorer, Google, etc. Join our 460,000 subscribers!
Subscribe and get our monthly bonuses - free!
The Windows 7 Guide, Volume 3: Advanced maintenance and troubleshooting provides advanced tools for keeping Microsoft's premier operating system up and running smoothly. Get this excerpt and other 4 bonuses if you subscribe FREE now!