Batch file for remotely re-starting a service

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

Facebook Twitter Linkedin

Related posts:

  1. TestComplete Simple CSV Reader (C# script)
  2. File Parsing for Troubleshooting
  3. Add JavaScript to your WordPress plugin.
  4. Using a .NET assembly (DLL) with Test Complete 7.52
  5. SQL – QA Analyst Interview Problem

About Mike

I am a Software Quality Assurance Professional that recently graduated college with a Bachelor's of Science in Computer Information Systems.
This entry was posted to the following categories: Automation. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>