A couple of weeks ago, you have learned the basics of Windows 7s new Task Scheduler. A mighty little tool that helps you automate your PC, which – once set up – safes your time and nerves. Last time we used Task Scheduler to automatically launch a program. In this blog post, you’ll learn how to make Windows automatically react on a certain “event”. This is especially useful for automatically troubleshooting Windows or streamlining its operation. How? Read on!
What is an “event”?
Windows keeps track on basically all operations that occur on your system: When you launch a program, switch between wireless networks or when Windows Update fails to install some patches – these are just three examples. There are literally thousands of possible events that Windows memorizes in the so called Event Log. You can take a look at what events occurred on your PC by performing the following steps: Click on the Start Orb in the lower left corner and enter “Event Viewer”. Press return.
This will fire up the built-in Event Viewer. Go have a look around. Under “Summary of Administrative Events” you’ll see an overview of some events – mostly errors or problems – that occurred on your PC. For a more easier to read and more categorized overview, head on over to “Windows Logs” for Windows-related events or to “Applications and Services Logs” for events that are related to your installed software and hardware.
Note: Many of Windows’ own events are also located under the “Applications and Services Logs\Microsoft\Windows” tree:
If you just like to see the latest warnings and error message, go to “Custom Views” and select “Administrative Events”.
There’s a lot of stuff going on in the background that you probably will never notice during your day-to-day work.
How can I react to an event?
This isn’t as tricky as it sounds. As we mentioned in the beginning, you can actually set up Windows to automatically react on a certain event. Let’s use a simple example:
Say, your internet connection cuts off at random times and for no apparent reason. All other solutions (driver updates, router firmware update, various settings) have failed, so the only solution is to disconnect and reconnect to your network manually. This is quite annoying, right? Wouldn’t it be cool to have a task that automatically does that for you whenever the internet connection fails?
To solve the problem, you need to watch Event Viewer very closely. Wait for the problem to happen and then look up Event Viewer to see if you can link your problem to a specific event. Let’s stick to the example of the cranky internet connection. Under “Administrative Events” you will probably see at least one event that tells you that the internet connection isn’t working properly. An example for this might be:
You need to be absolutely sure that this event is related to your error. It’s probably best, if you restart your machine and wait again for the problem to appear again – see if the very same error occurs. Now, you need to write down the following information from the event:
The Log Name, Event ID and the “Source” (the category of the event) are the important pieces of information here.
Again, all you need to figure out is:
- Does my error produce an event? If so, track it using “Event Viewer”.
- Find out its Log Name.
- Find out its Event Source.
- Find out its Event ID.
This is all you need for now.
Create a “trigger” based on your problem
Next, fire up the “Task Scheduler” as shown in our original blog post. Click on “Create Task”.
Make sure to name it accordingly, for example “Restart Internet Connection”. Go to “Triggers” and select the Event Source and the Event ID in order to be able to react automatically. To do that, click on “On a schedule” and switch to “On an event”.
Now go to “Log” and select the Log Name you found out earlier using Event Viewer. Same applies to Source and the Event ID. In the end, your custom trigger should look like this:
Hit “OK”. Now you’ve told Task Scheduler to automatically react when the Event ID 1001 occurs or – in other terms – when your internet connection fails again. So let’s tell Windows how this reaction should look like. This usually requires a bit of research, since you need a technical way to solve a problem: a command line, a script, a batch file or a little program.
In our example we created a little batch file with the following content:
This will flush the DNS cache, resets your IP address and other network information and gives you a fresh IP address. In between the three necessary commands (all beginning with “ipconfig”) you’ll see a command line that delays the execution of the next command by performing a network ping. This might be helpful for your troubleshooting endeavor! So what do these three commands do? In essence, this script renews your internet connection. Obviously, all your problems need individual solutions which can be hard to find. However, there are many guides or great forums out there that will help you accomplish this task.
If you figured out the solution, go to “Actions” and hit “New”. Make sure that “Start a program” is active and browse for your script or your program file by clicking on “Browse”.
Hit “OK”. In many cases, this is enough. If you like to control this task more specifically, go check out the “Conditions” and “Settings” tabs for more options. Here you can set when the task should stop or start or prevent it from launching if the computer doesn’t run on battery power.
From now on, every time the error “1001″ occurs, the Windows Task Scheduler will automatically run “Connection.bat” and reset the internet connection within seconds. By using this scheme, you can solve many problems 100% automatically. For example, you can detect when a program (e.g. a file downloader) crashes and restart it automatically – this is great when you’re not actually sitting on your computer. You can trust that when things go wrong, Windows sets them up all by yourself!
We know this is just one example out of a thousand. So let us know: Do you have a problem that you would like to fix using Task Scheduler? Or do you have a nice little batch file or script you’d like to share with us? Let us know!