The top answer to this question tells me how to stop/start a remote service. Great.
Now, all I need is to wait for the actual stop/start to complete. So, what I’m looking for is a dos command to:
- Start a service, should return only after the service is started (or after a timeout, raising error level)
- Stop a service, return only after the service is stopped
I created a set of batch scripts that use sc.exe to do just this. They are attached below. To run these scripts, you should be a user with administration rights on the target machine and running this from a computer that is a member of the same domain. It’s possible to set it up to be able to run from outside of the domain (like from a VPN) but there are a lot of layers of security to work through involving firewalls, DCOM and security credentials.
One of these days, I’m going to figure out the PowerShell equivalent, which should be much easier.
safeServiceStart.bat
safeServiceStop.bat
safeServiceRestart.bat