Dec 27, 2008

Writing really simple batch files

The following is my contribution to society in the field of computing technology... and what I was doing when I ran out of things to do.


Batch files are like little automated drones that do your bidding when opened and exists with the .bat extension. Very basic stuff.

I've recently discovered how useful they are and wrote a couple of them yesterday just to automate things a bit.
The activities I routinely do : End processes, visit my top sites daily, update my log of mp3s and files installed and more recently, a playlist creator.
I've saved that much more time using batch files instead of doing it manually.

I'll give you the simpler one for an example, mmmkay?

Opening your favourite sites with a double click.
This is the command line:

@echo off
start browser.exe www.webbie.com


start = Initiates the program
browser.exe = the program. In this case, browser of your choice. If you choose not to include this line, the sites will open in your default browser.
www.webbie.com = Self-explanatory. If you want to open more than one site, just insert it after the first. Like so, "www.webbie1.com www.webbie2.com www.webbie3.com"

Pretty simple right?

So what you do is copy all that and save it in Notepad with a .bat extension. If "filename.bat.txt" appears, it's still a text file. Add sites and you're done.


But this is pretty useless compared to killing processes so I'm going to incude instructions for that too.

The commands:

@echo off
taskkill.exe /im process.exe /f
taskkill.exe /im process.exe /f
taskkill.exe /im process.exe /f


taskkill.exe = the program used
/im = image name (if you open Task Manager > Processes, you'll see image name on the first tab). This means I've chosen to use its process name to identify the process I want to kill
process.exe = the process to kill
/f = forces the process to close

Copy and save the commands in Notepad as a .bat file and remember to change the process names to ones you know won't screw anything up when you end it. If you're unsure about it, try searching for them on Process List or Process Library.

To read more about what taskkill.exe can do (or any other commands), type "/?" after the command in command prompt.
E.g. taskkill.exe /?, dir /? and defrag.exe /?


As a general precaution, don't download or open any batch files that you aren't familiar with... like duh.
If you want to see what else you can do with command lines, type "help" in command prompt.

It's pretty interesting once you figure out how to use them to make stuff work.

9 comments:

Deng, the very eveel genius said...

HahahAHAHaHAHAha.

Hwey. What's command prompt? And hor.. Can I incorporate the kill processes with the open browser so it's all in one batch file?

Deng, the very eveel genius said...

WoOOoooOooOo! Very cool. =)

cheahwey said...

I'll let you know.

cheahwey said...

Yes it does. Just insert them after the other.

Command prompt is MSDOS. The black screen with gray words, the one that no one really knows how to use anymore because we've been given Windows Aero's pretty GUI.

Aksel said...

Hey, pretty neat stuff, do you know if you can give task kill an if option? eg.

If (variable.exe) = true (running)
then taskkill.exe /variable.exe /f
Else taskkill.exe /variable2.exe /f

Thanks Before hand,

Aksel, 15,

cheahwey said...

I haven't quite figured out how to do that yet. But if I do, I'll be sure to post it here.
Just so you know, I don't know much about batch files. The most complicated command I have is a choice question asking if I want to open firefox. xD

Aksel said...

Hey, thank you very much for all your imput, I have by now figured out a way to make a loop, a yes and no situation and alot more, I can get my 'Bat' files to open anything and close anything I want and or know off by now thank to you, I'll talk to you again sometime,

Aksel, 15, Malaysia K.L.

cheahwey said...

Awesome, though I'm not entirely sure what a loop is.

Aksel said...

Loop - when it can go back to where you started, :P