I have a Windows service that I build on a build server and then install on multiple remote servers using Sysinternals PSExec and sc create. This was worked well to this point but I now have a need to set the recovery options for the service so the service will restart itself or the machine in the event of a failure.

In a perfect World I would be able to pass some parameters in my sc create command but it doesn't appear that easy.

Can anybody help me?

Thanks, Chris


You are correct in that sc won't manipulate these settings. These settings are stored in the "FailureActions" REG_BINARY value, which is mostly opaque in nature. Your best bet would be to set the value as you want it on a test service then export the registry value. You would just import it after you use sc to create the service in your deployment script.

The API to manipulate these settings is ChangeServiceConfig2, and it's conceivable that you could code something to manipulate the values as you desire if you need flexibility.

  • Thanks for you response Evan. I'm currently using a batch script that installs the service each time I build. It deletes the existing service using sc delete and then uses sc create to reinstall the service. – user36540 Jun 24 '11 at 18:22
  • Sorry, my previous comment was cut off. I think I can swing the solution you presented above but it adds a couple degrees of complication. Is it possible to update the binary for my service without deleting it? If I don't delete then the recovery options would remain intact. – user36540 Jun 24 '11 at 18:24
  • 1
    As long as the service is stopped you can update the binary. There's no need to re-register the service as long as the binary's path and filename remains the same. – Evan Anderson Jun 24 '11 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.