You want your clients to automatically clean themselves up? You need a program to start at a specific time? You want the PC to automatically send you an e-mail message in case a crash occurs? Windows 7’s built in “Task Scheduler” can automate almost everything you want (except automatically get you coffee). Here’s how it works.
You spend way too much time maintaining and troubleshooting your company’s PCs, that’s for sure! And yes, you keep streamlining and saving time as much as you can. But you really cannot be bothered with every little issue and maintenance task that crops up. That’s why Microsoft built a “Task Scheduler” in Windows 7, which you can use to automate all sorts of maintenance issues and programs.
What can you automate?
- Perform an automatic maintenance task
- Automatically run a specific program
- Get e-mail notifications on any PC crashes, errors, or warnings
Scheduling a Maintenance Task or Specific Programs
First, I show you how to launch a specific Windows feature or a third party program on a regular basis. As an example, I chose Windows 7’s Disk Cleanup tool, a useful utility which performs the following tasks:
- It deletes temporary Windows, programs, and setup files. If you experience problems installing and launching Windows programs, the first step is to rid of all setup log files, temporary setup files and “Temp” files under the “User” and “Windows” folders.
- It cleans up Explorer thumbnails. If PCs have problems displaying thumbnails of photos or documents, cleaning up the thumbnail cache files always helps.
- It gets rid of older debug and backup files. If you upgraded your clients from Vista, the process left tons of backup and log files from the old installations. Disk Cleanup also deletes older error reports and debug files.
To set up Disk Cleanup, you need to start it once and choose which files should be deleted on a regular basis. To do that, click on the Start orb, type
cmd into the search box and hit Enter. At the Command Prompt, type in
Hit Enter. This opens the “Disk Cleanup Settings”, which offer far more options than the regular “Disk Cleanup” you see under the Start Menu. Choose carefully the files you want to automatically delete and click “OK”:
These settings will be saved, so you can now go on and schedule Disk Cleanup to launch automatically at a specific time.
Click on the Start Orb. Type
Task into the search bar and hit Enter.
Next, click on “Create Basic Task,” and type in a name and (optional) description of the new automatic task:
Make it descriptive so you can easily find it and edit it later!
Click on “Next” and select how often you want the Disk Cleanup task to run. In this case, we want like it to clean up the system every Friday at 5:00pm. So select “Weekly,” click on “Next,” and set up the time and date for the first run. Then we check “Friday”:
Click on “Next” and confirm the “Start a program” setting, which is selected by default. Now here comes to the most important step: Selecting the program which will run. Simply type in
cleanmgr.exe (the executable for Disk Cleanup). If you don’t know the exact file name, you can click on “Browse” and select “Disk Cleanup” (or, obviously, choose any program you like). For the more thorough Disk Cleanup to start, enter
/sagerun:1 into “Add arguments”:
That’s it! Click “Next” and “Finish” to set up your new task.
If you want to change the task later, open up Task Scheduler as shown in the first step and click on “Task Scheduler Library.” You should see the “Disk Cleanup” task entry:
Using this guide as an example, you could basically automate anything from your own scripts or a third party application. In the latter case, be sure to check the program’s manual or Help file for a command line switch that makes the software run in silent mode; the last thing you want is to confuse users with prompts and setting dialogs popping up during their work time.
Schedule Tasks During Idle Time
If you don’t want to interrupt users with the scheduled task, you can configure it to run only when the PC is idling. To do that, open “Task Scheduler” and double-click on your task. Under the “Conditions” tab, check “Start the task only if the computer is idle for…” and select after how many minutes (or hours) of idle time the task should be performed:
Schedule Automatic E-Mails in Case of a Disaster
When programs crash, Windows Update fails, or error messages pop up, you (as administrator) need to be informed. You can use Task Scheduler to automatically send you a message in case something goes wrong on one of your PCs. Here’s how.
Set up a Basic Task as described above. After you’ve entered a name, such as “Error notification,” select “When a specific event is logged.”
Task Scheduler shows all the events that occur in Windows 7’s “Event Viewer.” So, for example, if a Windows Update failed to install, you see an event like this in the Event Viewer in the “Windows Logs/Setup” category:
There are literally thousands of events, which is why you need to know exactly which event Task Scheduler should report.
In our little example, we know that the Windows Update error has the Event ID “3” so we tell Task Scheduler to react to only this specific event. To do that, go to “Log” and select “Setup”. Under “Source”, make sure that “WUSA” is selected. Finally, enter the Event ID that occurred, “3” in our example:
As you can see, in this process we exactly mirrored the Event Viewer’s output in the Task Scheduler wizard.
Click on “Next” and select “Send an e-mail.” Enter the e-mail address, the subject, and the company’s SMTP server to use. You can also specify an e-mail attachment! In our case, the Windows Update log (
C:\Windows\Windows Update.log) might be helpful. (If you have trouble setting up the mail notification, this TechNet Community blog post might be helpful.) Finally, click on “Next” and finish the wizard.
You don’t have to limit the notification to a single certain error. You could configure this notification to be sent when a certain event type occurs, such as any “Critical” error. Fire up Task Scheduler and double-click on the event you just created. Go to “Triggers” and open up the trigger properties for “On an event.” Select “Custom” and click on “New Event Filter”:
Here you can choose what kind of events are reported back to you. In our example, we only want critical events and warnings from the categories “System” and “Applications.”
There is no need for us to explain every bit of functionality Task Scheduler has to offer; by creating a Task, playing with Triggers and setting up Actions, you have learned the most important steps. As you surely have noticed, this tool is absolutely powerful and be configured to do so much more.
Want more like this? Sign up for the weekly IT Expert Voice newsletter so you don’t miss a thing!