Let’s say you want to restart a service such as the SQL Server service when an event with a specific event ID is logged in the Windows event logs. You can do this as follows:
1. Open Event Viewer and navigate to the log that contains the event you want to associate with a task.
2. Right-click the event and select Attach Task To This Event.
3. Walk through the Create Basic Task Wizard to create the new task.
4. Create a simple batch file with sc stop service_name and sc start service_name.
5. Open the task you just created and edit it to make the action performed by the task to be running the batch file.
6. Edit the task to specify the event ID needed to trigger the task.
7. Save the changes to the task.
Mitch Tulloch is a seven-time recipient of the Microsoft Most Valuable Professional (MVP) award and widely recognized expert on Windows administration, deployment and virtualization. For more tips by Mitch you can follow him on Twitter or friend him on Facebook.
Nice article! Just a question though, how do I monitor in the event logs the task after it has restarted the service to check the number of times it has happened?
Depends on what monitoring product you’ve deployed in your environment e.g. SCOM or a third-party solution.
If you don’t have any monitoring software installed you can filter the event log for event ID 7035 and 7036 to view any services that have restarted. See the following for more info:
http://eventid.net/display.asp?eventid=7035&source=
http://eventid.net/display.asp?eventid=7036&source=