I have a situation where a windows service on one server should not be started until a windows service on a different server has started. What I'd like to do is set the service dependencies but the standard "sc <service1> depend= service2"
doesn't seem to cater for this.
I could wrap the service code in a TryUntilSuccesful() sort of call but I would like to know if there is a recomended way to set up dependencies for windows services across servers in the same domain.
Dependencies between Windows Services on the same machine are managed by the Service Control Manager (SCM). The SCM can't/won't help you if your service is dependent on a Service on a different machine.
Therefore you will have to get some code of your own running in order to monitor in some fashion whether the remote service is running or not, and to get that code running you'll have to allow your service to start with or without the dependency.
It's difficult to prescribe a detailed solution without knowing the purpose of your service, but in principle you probably need your service to have two modes of operation: one where it does nothing except monitor in some fashion whether the remote service on which it depends is running; and the another where it performs its full functionality as well as continuing to monitor the dependency.
This last point is crucial - you will in any case have to monitor the dependency continuously, not just around the time your service is starting, because unlike the single machine situation, the SCM on the remote machine will not prevent the remote service being stopped, as it knows nothing about your dependency on it.