You may have lots of software installed on your PC, but you don't need it running all the time. If you want to save some system resources or just create a distraction-free environment in one click, a simple batch file can help.
First I'll walk through how to create a batch file for anyone unfamiliar with the handy Windows scripts, and then explain how to use some simple commands to start or stop resource-draining services or kill distracting applications.
Creating a Batch File and Starting Applications
To create a batch file, all you need to do is create a new, plain-text file with the .bat extension, and enter any commands in the file the same way that you would use them on the command line. You then execute the batch file (by, say, double-clicking it), and it'll run through the commands in the order you've written them into the file. Simple enough?
If you wanted to start a new instance of an application you should precede it with the start command. For example, to create a batch file that would start Notepad and open a new Explorer window that shows a certain folder, you could put these two lines into the batch file:
start explorer c:pathtostart
The batch file displays each command as output on the console, so if you would like to prevent that you can add the @ symbol before the command to eliminate extra output, or you can simply put this line at the top of the file:
Now that we've got a few simple batch-file basics out of the way, let's move on to more useful batch file tasks. (Remember, you can copy and paste any of the commands below into a plain text file, save it with the .bat extension, and you've got yourself a batch file.)
Stop or Start Services in a Batch File
Many applications these days install a bunch of supporting services that help the application, but they really don't need to be running all the time. On my system, I've found this is especially true for virtual machine software, which often installs a bunch of heavy services that use a lot of extra resources. If you aren't running a virtual machine all the time, they really don't need to be running.
What we can do is create a batch file that stops the services, and another batch file that starts them back up. To do this, you can simply use the net command with start or stop as the first parameter, and then the name of the service after it. You can either use the service short name, or the display name in quotes, like one of these two examples:
net stop wuaserv
net stop "Windows Update"
You can find the service names easily enough by opening the Services tool (use your Start menu search to find Services and run it) and double-clicking on one of the services. You'll see the short service name highlighted in the example below:
(For another way to look at the services that are currently running on your system, pull up the Windows Task Manager [Ctrl+Shift+Escape]and click the Services tab.)
You can start the services again by using the opposite command, like so:
net start wuaserv
Note that if you're using Windows 7 or Vista and you've still got UAC enabled, you'll need to run the batch file as administrator to actually stop the service. You can create a shortcut to the batch file and specify to always start as administrator in the shortcut properties to eliminate having to right-click every time.
Kill Applications with a Batch File
While stopping services is helpful to free up some system resources, you'll be able to free up a lot more resources by killing applications that don't need to be running — which can also be very helpful in killing distracting notifications and the like when you really want to focus. For instance, if you really should be writing that paper, you could have a KillDistractions.bat file that turns off everything else other than your preferred text editor.
To kill an application from the command line or a batch file, all you have to do is use the taskkill command with the /IM parameter, which matches the image name column from Task Manager—which is really just the file name of the application executable. For instance, to kill Notepad you would use the command like this:
taskkill /IM notepad.exe
This command by default will simulate clicking the red X in the corner of the window, so you'll be prompted to save your work if necessary. If you wanted to kill applications instantly without saving anything, you could use the /F parameter to force kill instead, like this:
taskkill /F /IM notepad.exe
taskkill /F /IM chrome.exe
You've got plenty of other parameters to choose from with the taskkill command, which you can browse with the /? parameter (i.e., type
Create a Shortcut to Start the Batch File
Now that we've walked through the basic commands you'll need to create a batch file that starts or stops all the services and applications we don't need running, we can make the last line of the batch file start up the application that we're planning on running, and then customise the shortcut to start the batch file minimised so the Command Prompt window isn't flashing on the screen. So right-click your desktop or in any Explorer window, go to New -> Shortcut, and point it toward your batch script.
If you click the Advanced button on the shortcut window, you'll be able to specify to run the application as administrator if necessary. If you're stopping services in the batch file, you'll need to use this option, though you should note that any applications you start in the batch file will also be started as administrator. Of course, if you've disabled UAC, this won't matter either way.
Putting It All Together
Now that you know how to stop services, kill applications, and create the proper shortcuts, it's time to put it all together into a useful combination. Here's an example script that I use to kill distractions when I'm ready to switch into writing mode, but you could customise this to fit anything you might need.
taskkill /IM tweetdeck.exe
taskkill /IM chrome.exe
taskkill /IM firefox.exe
taskkill /IM pidgin.exe
taskkill /IM notepad.exe
Since I often use virtual machines to do my testing, I've also created batch files that start and stop the services when necessary to make sure that I'm only wasting resources when I actually need the virtual machines running. To stop the services, I've created a file called stopvmware.bat, though I've also set all these services to manual startup, so I only need to use this after I close VMware.
net stop VMAuthdService
net stop VMnetDHCP
net stop "VMware NAT Service"
net stop "VMUSBArbService"
Then when I need to start VMware again, I can simply use my startvmware.bat file, which starts up the services and then launches the VMware application.
net start VMAuthdService
net start VMnetDHCP
net start "VMware NAT Service"
net start "VMUSBArbService"
start "C:Program Files (x86)VMwareVMware Workstationvmware.exe"
You can customise these scripts to do anything you might want, and tailor them to your environment, but this should give you the tools you need to get started creating your own time-saving batch files.