Best viewed in Firefox

Awesty Productions

A Fun Interactive Batch Script

September 11th, 2007 by awesty

In this tutorial you will learn how to make a cool little batch script that can interact with the user.

First open up notepad and enter this code:

@echo off
cls
echo What is your name?
set /p name=
if ‘%name%’ == ‘awesty’ goto awesome
echo You suck!
pause
exit
:awesome
Color 4f
echo.
echo You RULE!
pause

Now if you save it as something.bat, make sure that the ‘Save As Type…’ is set to ‘All Files’, and double click it a console window should appear. If you enter awesty you will get the message You Rule! and the console will turn red. If you enter anything else you will get told that you suck. How does it work you ask?

@echo off
cls

Take away the @echo off and run the script again. It should look like C:\Some Folder\>What is your name?, instead of just What is your name?. The @ in front of ‘echo off’ stops the echo off from being displayed. ‘cls’ just clears the screen.

The next line (echo What is your name?) just outputs ‘What is your name?’ to the console. If you type echo, everything after it on the same line will be outputted (yes… I know its not a real word).

set /p name=
if ‘%name%’ == ‘awesty’ goto awesome

’set /p name=’ sets the variable name to whatever the user enters. the next line is an if statement checking if the variable name (’%name%’) is equal to awesty. If it is it will go to the label awesome, if not it will just continue with the script. I will explain more about that later.

echo You suck!
pause
exit

Outputs You suck! then pauses (waits for the user to hit a key) and then exits the program.

:awesome
Color 4f
echo.
echo You RULE!
pause

This is where the if statement takes you if it returns true. It changes the background color to Red and the font color to white (4 = red, f = white). It then makes a new line and outputs You RULE!, waits for the user to hit a key and then exits. We didn’t need to write ‘exit’ to make the program exit this time because there is no code following so it exits automatically.

Try messing around with that script and see what else you can get it to do.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • del.icio.us
  • digg
  • Furl
  • MyShare
  • NewsVine
  • Netscape
  • Reddit
  • Simpy
  • Slashdot
  • StumbleUpon
  • Technorati
  • YahooMyWeb

RSS feed | Trackback URI

14 Comments »

Comment by chris Subscribed to comments via email
2007-09-13 05:27:27

good job, it was fun to mess with

 
Comment by MR.LAUGH Subscribed to comments via email
2007-09-14 21:50:09

Wow, that’s pretty cool.

 
Comment by am
2007-09-16 17:04:12

very nice blog thanks… please dont forgot to visit my blog also… i have alots of free movies and software application download…

 
Comment by Kurt Subscribed to comments via email
2007-10-06 10:35:48

This is pretty cool

 
Comment by Kurt Subscribed to comments via email
2007-10-06 11:37:05

Awesty I’m trying to make something like

@echo off
echo Quiz Time!
echo Who Owns this computer?
set /p name=
if ‘%name%’ == ‘kurt’ goto awesome
if ‘%name%’ == ‘Kurt’ goto awesome
Color 4f
echo Incorrect!

:awesome
Color 2f
echo.
echo Correct!

@echo off
echo What are Kurt’s favorite pets?
set /p name=
if ‘%name%’ == ‘Frodo and Lucy’ goto yep
if ‘%name%’ == ‘frodo and lucy’ goto yep
if ‘%name%’ == ‘Lucy and Frodo’ goto yep
if ‘%name%’ == ‘lucy and frodo’ goto yep
Color 4f
echo Incorrect!

:yep
Color 2f
echo.
echo Correct!

but it is not working out.

Comment by awesty
2007-10-06 11:44:26

It would be more like this:

@echo off
echo Quiz Time!
echo Who Owns this computer?
set /p name=
if ‘%name%’ == ‘kurt’ goto awesome
if ‘%name%’ == ‘Kurt’ goto awesome
Color 4f
echo Incorrect!
goto parttwo
:awesome
Color 2f
echo.
echo Correct!
:parttwo
echo What are Kurt\'s favorite pets?
set /p name=
if ‘%name%’ == ‘Frodo and Lucy’ goto yep
if ‘%name%’ == ‘frodo and lucy’ goto yep
if ‘%name%’ == ‘Lucy and Frodo’ goto yep
if ‘%name%’ == ‘lucy and frodo’ goto yep
Color 4f
echo Incorrect!
exit
:yep
Color 2f
echo.
echo Correct!

 
 
Comment by Kurt Subscribed to comments via email
2007-10-06 11:38:21

Oh never mind I had to make it 1 word but how do I make it a sentence???

 
Comment by Kurt Subscribed to comments via email
2007-10-07 02:30:26

do you no how to make a sentence tho i also made a robot program called Xtron the code is so far
@echo off
cls
Color 0f
echo Enter your username below.
set /p word=
if ‘%word%’ == ‘kurt’ goto Correct
if ‘%word%’ == ‘Kurt’ goto Correct
Color 4f
echo Wrong!
pause
exit
//————————————
:Correct
Color 2f
echo CORRECT!
pause
//————————————
@echo off
Color 0f
cls
echo Enter your password below.
set /p word=
if ‘%word%’ == ‘lucy’ goto Correct
if ‘%word%’ == ‘Lucy’ goto Correct
Color 4f
echo Wrong!
pause
exit
//————————————
:Correct
Color 2f
echo CORRECT!
pause
//———————————–
:Emotion
@echo off
Color 0f
cls
echo Welcome back Kurt! How are you feeling today?
set /p word=
if ‘%word%’ == ‘Sad’ goto Sad
if ‘%word%’ == ‘sad’ goto Sad
if ‘%word%’ == ‘Mad’ goto Mad
if ‘%word%’ == ‘mad’ goto Mad
if ‘%word%’ == ‘Angry’ goto Angry
if ‘%word%’ == ‘angry’ goto Angry
if ‘%word%’ == ‘happy’ goto Happy
if ‘%word%’ == ‘Happy’ goto Happy
if ‘%word%’ == ‘Bored’ goto Bored
if ‘%word%’ == ‘bored’ goto Bored
if ‘%word%’ == ‘Normal’ goto Normal
if ‘%word%’ == ‘normal’ goto Normal
if ‘%word%’ == ‘Good’ goto Good
if ‘%word%’ == ‘good’ goto Good
if ‘%word%’ == ‘Excited’ goto Excited
if ‘%word%’ == ‘excited’ goto Excited
Color 4f
echo I don’t know that emotion!
pause
goto Emotion
//———————————–
:Sad
@echo off
cls
Color 1f
echo Well I hope you feel better later.
pause
goto Questions
//———————————–
:Mad
@echo off
cls
Color 4f
echo Well don’t try to beat me up then!
pause
goto Questions
//————————————–
:Angry
@echo off
cls
Color 4f
echo Well don’t try to beat me up then!
pause
goto Questions
//————————————–
:Happy
@echo off
cls
Color 6f
echo I’m having a great day too!
pause
goto Questions
//————————————-
:Bored
@echo off
cls
Color f0
echo Well play a game or something!
pause
goto Questions
//————————————-
:Normal
@echo off
cls
Color 0f
echo Ok that’s good!
pause
goto Questions
//————————————
:Good
@echo off
cls
Color 3f
echo Ok that’s good!
pause
goto Questions
//————————————
:Excited
@echo off
cls
Color E1
echo Why?
set /p word=
echo Cool!
pause
goto Questions
//————————————
:Questions
@echo off
cls
Color 0f
echo Any questions?
set /p word=
if ‘%word%’ == ‘what is your name’ goto Name
if ‘%word%’ == ‘name’ goto Name
if ‘%word%’ == ‘Yes’ goto Questions
if ‘%word%’ == ‘yes’ goto Questions
if ‘%word%’ == ‘yep’ goto Questions
if ‘%word%’ == ‘Yep’ goto Questions
if ‘%word%’ == ‘No’ goto No
if ‘%word%’ == ‘no’ goto No
if ‘%word%’ == ‘nope’ goto No
if ‘%word%’ == ‘Nope’ goto No
if ‘%word%’ == ‘Nty’ goto No
if ‘%word%’ == ‘nty’ goto No
Color 4f
echo I dont know!
pause
goto Questions
//———————————–
:Questions 2
@echo off
cls
Color 0f
echo Ok ask me then.
set /p word=
if ‘%word%’ == ‘Name’ goto Name
if ‘%word%’ == ‘name’ goto Name
Color 4f
echo I dont know!
pause
goto Questions 2
//———————————–
:Name
@echo off
cls
Color 0f
echo My name is Xtron.
echo Any more questions?
set /p word=
if ‘%word%’ == ‘What is your name’ goto Name
if ‘%word%’ == ‘what is your name’ goto Name
if ‘%word%’ == ‘Yes’ goto Yes
if ‘%word%’ == ‘yes’ goto Yes
if ‘%word%’ == ‘yep’ goto Yes
if ‘%word%’ == ‘Yep’ goto Yes
if ‘%word%’ == ‘No’ goto No
if ‘%word%’ == ‘no’ goto No
if ‘%word%’ == ‘nope’ goto No
if ‘%word%’ == ‘Nope’ goto No
if ‘%word%’ == ‘Nty’ goto No
if ‘%word%’ == ‘nty’ goto No
Color 4f
echo I dont know!
pause
//———————————-
:No
@echo off
cls
Color 0f
echo Reminder! Do you have a test to study for or homework to do???
set /p word=
if ‘%word%’ == ‘Yes’ goto Yes
if ‘%word%’ == ‘yes’ goto Yes
if ‘%word%’ == ‘yep’ goto Yes
if ‘%word%’ == ‘Yep’ goto Yes
if ‘%word%’ == ‘No’ goto Close me
if ‘%word%’ == ‘no’ goto Close me
if ‘%word%’ == ‘nope’ goto Close me
if ‘%word%’ == ‘Nope’ goto Close me
Color 4f
echo I think you made a spelling error!
pause
goto No
//——————————–
:Yes
@echo off
cls
Color 0f
echo Well go do your work then if you need help on math and stuff come to me.
echo (once you prgram me to.)
set /p word=
if ‘%word%’ == ‘Exit’ goto G-MAil
if ‘%word%’ == ‘exit’ goto G-MAil
if ‘%word%’ == ‘Continue’ goto G-MAil
if ‘%word%’ == ‘continue’ goto G-MAil
Color 4f
echo I dont know!
pause
goto Yes
//——————————-
:G-MAil
@echo off
cls
Color 0f
echo Did you check your G-mail today?
set /p word=
if ‘%word%’ == ‘Yes’ goto Close me
if ‘%word%’ == ‘yes’ goto Close me
if ‘%word%’ == ‘yep’ goto Close me
if ‘%word%’ == ‘Yep’ goto Close me
if ‘%word%’ == ‘No’ goto Check it
if ‘%word%’ == ‘no’ goto Check it
if ‘%word%’ == ‘Nope’ goto Check it
if ‘%word%’ == ‘nope’ goto Check it
Color 4f
echo I think you made a spelling error!
pause
goto G-Mail
//——————————-
:Check it
@echo off
cls
Color 0f
echo Well go check it then!
set /p word=
echo Do you want to continue?
:Check it 2
set /p word=
if ‘%word%’ == ‘Yes’ goto Close me
if ‘%word%’ == ‘yes’ goto Close me
if ‘%word%’ == ‘yep’ goto Close me
if ‘%word%’ == ‘Yep’ goto Close me
if ‘%word%’ == ‘No’ goto Check it 2
if ‘%word%’ == ‘no’ goto Check it 2
if ‘%word%’ == ‘Nope’ goto Check it 2
if ‘%word%’ == ‘nope’ goto Check it 2
Color 4f
echo I think you made a spelling error!
pause
goto Check it
//——————————-

//——————————-

//——————————-
:Close me
@echo off
cls
Color 0f
echo Do you wan’t to close me?
set /p word=
if ‘%word%’ == ‘Yes’ goto Yes
if ‘%word%’ == ‘yes’ goto Yes
if ‘%word%’ == ‘yep’ goto Yes
if ‘%word%’ == ‘Yep’ goto Yes
if ‘%word%’ == ‘No’ goto No
if ‘%word%’ == ‘no’ goto No
if ‘%word%’ == ‘nope’ goto No
if ‘%word%’ == ‘Nope’ goto No
Color 4f
echo I think you made a spelling error!
pause
goto No
//——————————-
:No
@echo off
cls
Color 0f
echo What do you want to do then?
set /p word=
if ‘%word%’ == ‘question’ goto Questions
if ‘%word%’ == ‘Question’ goto Questions
if ‘%word%’ == ‘questions’ goto Questions
if ‘%word%’ == ‘Questions’ goto Questions
Color 4f
echo I can’t do that!
pause
goto No
//——————————-
:Yes
@echo off
cls
Color 0f
echo Well see you later then!
pause
exit
//——————————
the //— is for organization i need sentence thing for the name still tho

Comment by awesty
2007-10-16 16:59:14

What do you mean?

Like so the user can reply a sentence instead of one word?

Comment by Kurt Subscribed to comments via email
2008-02-02 12:06:06

Yes sorry It took so long lol…

 
 
 
Comment by Kieren Subscribed to comments via email
2008-07-19 15:15:08

so how do you reply in a sentence?

 
Comment by mabs
2008-08-16 05:41:50

One of the most helpful code snippets I’ve found in a long time. I knew there was a way to do it, but didn’t know how. Thanks!

 
Comment by Kurt Subscribed to comments via email
2008-08-16 07:05:36

Wow I remember this it was like a year ago… and you never answered me haha

 
Comment by Kieren Subscribed to comments via email
2008-08-18 17:34:58

Lol, he still hasn’t.

 
Name (required)
E-mail (required - never shown publicly)
URI
Subscribe to comments via email
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> in your comment.