I'm trying to build a release pipeline in devops that re-deploys a windows service to a deployment pool. That is all working quite nicely, the only problem is that when copying the new .exe for the windows-service to its directory I need to stop the windows-service. Currently I just run
sc.exe stop "service name"
but if the service is stopped for any reason, this will cause an error ("The service has not been started."). I therefore need a way to determin if the job is currently running, and only stop it then. The same would go for starting the service, as it has to be in a stopped state to start it again.
Any help would be appreciated.