Restart a service when an event occurs

by Mitch Tulloch [Published on 13 Sept. 2012 / Last Updated on 22 May 2012]

How to restart a service when a specific event is logged in the event logs.

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.

See Also

Featured Links