Restart a service when an event occurs

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.

2 thoughts on “Restart a service when an event occurs”

  1. 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?

Leave a Comment

Your email address will not be published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top