Thursday, May 10, 2007

Windows: Quick Start Multiple Services using Batch and Net

One thing that irritates the hell out of me as a developer is that I constantly have to change configurations between development, BAU, and leisure on my PC. I keep all my development and test environments in separate virtual machines using VMWare so I can hose them and restore them, use these as test beds for new application without worrying about cluttering up my registry, and for browsing to some of the more "questionable" sites on the web without fear of corrupting my host machine. This allows me to keep the amount of garbage on my host environment down to a minimum. This also means I do not run all my services at startup, allowing for speedier work on my host PC and faster boot times, and less exposed services running.

The irritating part is that VMWare has a lot of services associated with it. So when i want to play a game, which I will typically do on my host rather than a VM for performance reasons, I have to shut down all 5 of the services that are associated with it. Under my database development VM, I have to start and stop all services associated with Sql server when I want to use it, or with MySql. Under the web development VM, I have to start and stop IIS or Apache depending on which platform I am testing (I keep all these under logical groupings rather than keep separate VM's for each). Having to point and click to start services is a PITA.

However, a quick solution is a trick that is old hand to many administrators and old DOS guys. I use seperate batch files to quickly start and stop the multiple services associated with an application. For example, on my host PC, I have 2 batch files for VMWare, one to start and one to stop. In order to start and stop services, I use the built in NET command. The file to start my services looks like this:

@echo off
net start "VMware Authorization Service"
net start "VMware Registration Service"
net start "VMware DHCP Service"
net start "VMware NAT Service"
net start "VMware Virtual Mount Manager Extended"

And the script to stop them looks like:

@echo off
net stop "VMware Registration Service"
net stop "VMware Authorization Service"
net stop "VMware DHCP Service"
net stop "VMware NAT Service"
net stop "VMware Virtual Mount Manager Extended"

While not exactly cutting edge, it is a quick tip that saves me a lot off waiting time. Of course if you run into the issue with the Registration Service not starting in a timely manner, I wrote an article several months back on how to fix that here.

No comments: