Link to home
Start Free TrialLog in
Avatar of steveuk71
steveuk71

asked on

SC Query output

Hi

Could someone please enlighten me as to how do the following.
From time to time I need to shut down an application that runs as a service on a large number of servers, the service that requires shutting down can take anything from 30-60 mins and following a successful shutdown I need to run a súpplíed batch file that will that will run updates against this application.
Where I am stuck is on how to get a batch file to pick up on sc query "state stopped" on each server and if the service has stopped for the batch file to kick in.

So I am assuming the simplified order of this is.

1.Shutdown Service
2.Run sc query
3.If state stopped then run supplied_update.bat
4.If not wait or check again in 30 mins etc

Many Thanks
SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The sc query command could look like this:
sc \\ServerName ServiceName | findstr /i "stopped"

Open in new window

After the sc command, check %ERRORLEVEL% to determine whether the service was stopped, 0 would mean is has stopped, 1 would mean that it has another state. You could also explicitly check for "running" before you attempt the sc stop command.

I agree with Bill on using a servername list, you could add a status file per server to keep track of the service's state on each server.
Avatar of steveuk71
steveuk71

ASKER

Thanks Bill and Gerwin, Bill I agree with your comment and if there is any chance of some assistance with this matter it would be most appreciated.
Gerwin,the status file per server sounds interesting, could you please elaborate if possible.
Thanks
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many Many Thanks for this assistance, I haven't had time to go through and attempt to understand it just yet.