I'm having a few issues writing a script to modify the recovery options for a remote service - i.e. add a executable to run on error.
It will have one command line argument
sc %machinename% failure Bla.ServiceName command= "\"E:\Program Files\App\SendEmail.bat" {0}
I've looked at this question, but I can't seem to get it to work as I'd expect.
Anybody have any pointers - similarly if this is easier in C#/PowerShell I'd be happy to consider looking at those options.
Just had another try based on suggestions - the below works but I'd like to remove the "-" if possible. If I do I get an invalid option from the command prompt.
sc %machinename% failure Service command= "\"E:\Program Files\App\Monitoring\SendEmail.bat\" "Service-is-down-on-env""
Edit...
It seems I didn't test the obvious adding a slash at the end. For those who are wanting to do something similar it should be:
sc %machinename% failure Service command= "\"E:\Program Files\App\Monitoring\SendEmail.bat\" Service is down on env"
Thanks guys, I knew it might provoke some thought if I wrote it down!
One thing I did notice I can't do is make the message appear as one command line argument - is there something I'm missing there?