1

In a build pipeline for our .NET application, we automated the stopping and starting of our IIS server through

net stop WAS and net start W3SVC. But there is a problem with the first command. If the service for some reason is not running then stopping it will throw an error

The Windows Process Activation Service service is not started.

and our pipeline won't continue because of this. We however would like that if the IIS server is already down, this error is not thrown. Hence how to not raise an error when stopping a non-running service?

3
  • Check if WAS is already running first. There are a number of different ways you can check this.
    – DavidPostill
    Aug 4, 2021 at 17:53
  • Maybe look at using sc.exe, the exit code of that will be the response from the SCM. E.g. sc.exe stop workfolderssvc. Note this is a stopped service example. echo %errorlevel% returns 1062 which is ERROR_SERVICE_NOT_ACTIVE or The service has not been started. Aug 4, 2021 at 20:23
  • As already mentioned, you have to check the service's state and implement the desired actions yourself. Should I use NET or SC to start/stop/restart our Windows Services? outlines some of the issues you may face when calling NET and SC from batch files.
    – CoreTech
    Aug 5, 2021 at 5:59

0

You must log in to answer this question.

Browse other questions tagged .