In our recent QA automation efforts we had the requirement to stop some Windows services before performing a task in our scripts. The scripts need to pause until these services return to a started state. The approach we took to this was to write some batch files that would stop, start or restart the services using Microsofts SysInternal tools, specifically psservice. PSService is a component of SysInternals that allows a user (typically an administrative user) to start, stop or restart a service from a remote location. Very handy for automation testing. Once the loop ended (service finished starting), the cmd line would write out a “Finished.txt” file that the script watched for and cleaned up before moving on.
REM Restart MSSQLSERVER on specified server
psservice \\{computername} -u {username} -p {user password} restart {service name}
:Loop1
timeout /t 10
sc query {service name} | find /i "running" || goto Loop1
exit
Related posts: