• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

Running a batch file when a service stops.

I want to setup my servers so that when a windows service stops that it runs a batch file which triggers a .ps1 script that sends me a mail. I know that my bat file works but how can I make windows run that bat file when a service stops?
0
technolutions
Asked:
technolutions
  • 3
  • 2
1 Solution
 
Farhan KaziSystems EngineerCommented:
You can configure service "Recovery" option to "Run a program" (or batch file) when service fails.

Click Start -> Run -> Services.msc -> Right click on Service -> Properties -> Recovery -> Under First failure drop down list select "Run a program" -> Click browse button and select batch file that you want to run.

Hope this helps!
Farhan
0
 
technolutionsAuthor Commented:
My browse button is grayed out?!
0
 
technolutionsAuthor Commented:
If I type in the path of the batch file without browsing it doesn't work when I stop the service.
0
 
Farhan KaziSystems EngineerCommented:
Did you select "Run a program" from "first failure" drop down list ?
0
 
Farhan KaziSystems EngineerCommented:
It will only work in case of service failure.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now