Start Services Using a Batch File

If you use your person computer as a testing server you probably have several services running in the background (a web server, database, caching service, etc). Individually these services tend to have a small footprint. If you’re running enough of them however, they can start to impact your machine’s performance. If you have them set to auto start they can also increase your startup time. Ideally you would want to start them when you need them and stop them when you’re done with them, but that can be a hassle for multiple services. A simple solution is to create a batch file to start all of your services, and another one to stop them.

Follow these steps to create your batch file:

  1. Open up your service manager by either typing services.msc into your run dialog or by navigating to Control Panel > Administrative Tools > Services.
  2. Locate the services you want to run on demand and set them to manual by right clicking the service, clicking Properties, then setting the Startup type to Manual.
  3. Create a new text file (name it whatever you want, I used “start”) and open it up in a plain text editor (ex notepad). Do not use Word.
  4. For each service you want to start on demand add the following line of text:
    net start "Service Name"
    Replace Service Name with the name of the service you want to start. The service name should be quoted.
  5. Change the file extension to .bat.
  6. To create a bat file for stopping services, repeat steps 3 through 5 using stop in place of start in step 4.

Here is the start.bat file I am using:

net start "Apache2.2"
net start "MySQL"
net start "memcached Server"
net start "Neo4j-Server"

Caveats:

  • You may need to run your .bat file as an Administrator.
  • If the service you want to start has dependencies, make sure the dependent services are running before you start your service. You can do this by either setting the dependent services to auto start, or by adding them to your start.bat file before the service that depends on them.
  • There is no “net restart” command. If you want to create a batch file for restarting services, just use the stop command followed by the start command.

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>