Fun with a batch file for starting and stopping “Development” related services


Here's the scenario: you are a programmer in both hobby and career, but you've got other hobbies, like video games. But first and foremost, you are a programmer… So not only do you have a number of video games sucking up precious hard drive space, you have a full blown installation of Visual Studio, Sql Server Express, IIS, all running on your local machine. Come game time, you've got all these services sitting around waiting to be used in some development, meanwhile you're trying to get max frames-per-second with Crysis…

Not a big deal, Windows+R then "services.msc" and those pesky services down, get your game on and then… Oh wait, some more development… Back to services.msc and turn them back on. Gets very old, very quick…

So I decided to do a little something about it, a very little something, I wrote a batch file to present a little start or stop menu and start up the services or shut them down.

Here is a list of services I felt like adding in there, there could be more… I could have turned off svncache, etc… I figured why bother… The list I used is:

  • SQL Server Browser
  • SQL Server VSS Writer
  • World Wide Web Publishing Service
  • IIS Admin Service
  • Machine Debug Manager
and the code ends up looking like this:
   1: ECHO off
   2: CLS
   4: IF "%1"=="" GOTO MENU
   6: SET M=%1
   9: :MENU
  10: ECHO.
  11: ECHO ---------------------------------
  12: ECHO Start or Stop the Dev Environment
  13: ECHO ---------------------------------
  14: ECHO  S : Start the dev environment services
  15: ECHO  P : the dev environment services
  16: ECHO  Q : Do nothing and quit
  17: ECHO.
  19: SET /P M=Type S, P, or Q then press Enter: 
  22: IF "%M%"=="S" GOTO START
  23: IF "%M%"=="s" GOTO START
  24: IF "%M%"=="P" GOTO STOP
  25: IF "%M%"=="p" GOTO STOP
  26: IF "%M%"=="Q" GOTO CLEANUP
  27: IF "%M%"=="q" GOTO CLEANUP
  28: IF "%M%"=="/?" GOTO HELP
  29: IF "%M%"=="-?" GOTO HELP
  30: IF "%M%"=="--help" GOTO HELP
  32: ECHO Invalid Mode: %M%
  35: :START
  36:   net start "SQL Server (SQLEXPRESS)"
  37:   net start "SQL Server Browser"
  38:   net start "SQL Server VSS Writer"
  39:   net start "World Wide Web Publishing Service"
  40:   net start "IIS Admin Service"
  41:   net start "Machine Debug Manager"
  44: :STOP
  45:   net stop "SQL Server (SQLEXPRESS)"
  46:   net stop "SQL Server Browser"
  47:   net stop "SQL Server VSS Writer"
  48:   net stop "World Wide Web Publishing Service"
  49:   net stop "IIS Admin Service"
  50:   net stop "Machine Debug Manager"
  53: :HELP
  54:   ECHO Usage:
  55:   ECHO dev-environ.bat [Mode = S | P | Q]
  56:   ECHO   Mode: S = Start the dev environment services
  57:   ECHO   Mode: P = Stop the dev environment services
  58:   ECHO   Mode: Q = Quit this .bat and do nothing
  59:   ECHO.
  60:   GOTO EOF
  62: :CLEANUP
  63:   ECHO.
  64:   ECHO Done.
  66: :EOF

Not terribly clean, and I probably could have done it with a windows app with c#, but it would have been so much work for the same result. Anyway, enjoy!

Caveat: With Widnows 7 (or Vista) with the UAC enabled, you'll want to right-click on the .bat or shortcut to it and and run it as Administrator so that it has permissions to stop or start the windows services.

The contents of the code above are conveniently located below under Attachment's for this entry. Cut down on the cut and paste errors 😉

Trackback URL for this post:
Attachment Size
dev-environ.bat 1.44 KB