User:Buga-buga

Batch file guide!

note: this is for windows xp, i havnt tried it on any other operating systems.

I guess you are here to learn how to make a batch file program! These are not only usefull,

but somtimes fun!

Alright so you may be asking yourself 'Uh oh a program!' Yes! Your very own program! No need to compile, and it is very easy to edit and change it.

Ok, the first thing you need to do is to open notepad, or any other text editor. Got it?

Next, type

@echo off echo Hello World! look at me! pause

Each on a seperate line.

Now, click file then save as, go to where you want to save it (I use desktop, it is easiest

for me), then change it from .txt to 'All file types'. Now name it firstbatch.bat and save it.

Remember:


 * All files types
 * firstbatch.bat

Now close notepad.

Next, go to where you saved it and double click it!

Then it will open up what looks like a command prompt but is really your batch file and will

display 'Hello World! look at me!' or whatever you wrote for that, then 'press any key to

continue' and when you press any key it will close.


 * note! to easily change your batch file right click it then choose edit!**

Congradulations on your first batch file! But wait! What the heck is that echo stuff? Here is a helpfull chart to show you:

-

@ this doesnt echo what you typed back. this is used mainly before echo off. sorry if

thats hard to understand, just at the beggining type @echo off ok good

-

echo This is what you use if you want text to appear. For instance,

@echo off hey whats up pause

would not work, while

@echo off echo hey whats up pause

would show hey whats up, then press any key to continue.

--

pause this is used to show the press any key to continue. If you dont have pause, the

program will do its job then shut itself down right when its done. Try your first program

without pause, and it will end very quickly.

Alright cool! experiment with the stuff untill you get bored then continue.

Ok here is a scenario. Each time you turn on your computer, you always check all the files in

your windows folder. But one day you get tired of all that clicking. To save time you would make a batch file on your desktop.

@echo off echo Press enter to check the windows folder. pause dir C:\windows pause

once your done, each time you click the batch file it will show you all the stuff in the

windows folder.

But what if you want to check all the folder from there? after all, right when you type

anything it will close! heres a way!

@echo off echo Press enter to check the firefox folder. pause dir C:\windows command.com

ok, you got the command prompt! yeah i know, it works, but its messed up, i am too lazy to

figure it out. this shows that you can do more than 1 thing with a batch file...hopefully

yours will be more sucessful than mine was.

Alright! Are you ready to make a program that does stuff? alright

try this:

@ECHO OFF


 * Start

ECHO What do you want to do? ECHO press 1 or 2 ECHO 1: shutdown in 5 minutes ECHO 2: open firefox

SET Choice= SET /P Choice=""

IF '%Choice%'=='1' GOTO shutdown IF '%Choice%'=='2' GOTO firefox

ECHO "%Choice%" ERROR ERROR LOL wrong answer ECHO choose again.. GOTO Start


 * shutdown

SHUTDOWN -S -F -T 300 GOTO End


 * firefox

C: cd\Program Files cd Mozilla Firefox firefox.exe

GOTO End


 * End


 * note: to stop the shutdown go to run then type shutdown -a*
 * you should change the directeries if firefox or whatever else isn't in there.*

awesome! now just type 1 or 2 to shutdown in 5 minutes or open firefox! amazing! you can edit

all of this stuff and add more options really easily! alright now, lets break this down:

The : is a specific point in the program that you can go to.

SET Choice= SET /P Choice="" is when you are going to start asking questions.

IF '%Choice%'=='1' GOTO shutdown means if your choice is 1, it will go to :shutdown

of course, you dont have to make yourself type 1 each time. you could change it to SHUTDOWN!!!

and, for the firefox one, you can make it be LOLFIRE.


 * i dont know if it can have spaces though, i tried it with "fox of fire" but it didnt work

for me. maby im missing somthing..

now the IF '%Choice%'=='2' GOTO firefox makes it go to.... :firefox !!! woah

but what if somone types somthing besides 1 or 2? then it will just continue down going,

saying ERROR ERROR LOL wrong answer. then choose again, then it will goto the start, which

just so happens to be :start.

what happens if you choose the firefox?

well, first it goes to C:

then it does cd\Program Files i have no idea why it has to be cd\ it didnt work for me

without

cd Mozilla Firefox

again, no idea why this time you dont need the \ but o well

then, it will execute firefox.exe!

finally, the GOTO end...goes to the :end

you can also add a pause at the very end if you want.

thats about it and have fun!