09-05-2008, 02:55 PM
i'll give a very basic example first and then explain everything in the code
heres one i made just to open firefox and itunes for me by clicking an icon
so to start off open notepad and type this in
when you go to save it make sure you save it as a .bat not a .txt
ok
first thing, @echo off, this means that it does not show the C:\ that you would normally see in the command line if you opened up MS-DOS
i use @echo off just so you only see text instead of the directory
echo opening... - it will display whatever you type after echo so i literally see "opening..."
same goes for the echo iTunes, echo Firefox, and so on
start itunes.exe - this launches iTunes, the start command will launch the program placed after "start"
same goes for "start firefox.exe"
pause-this will make "Press any key to continue...." to appear so it "pauses" it, once you do press a key then it will go to the exit command which will exit it
exit-this closes the window that all of this is displayed in
there are also other commands such as "cls" which clears everything
but yeah, try it out for yourself, you can even add more applications and what not if you like.
NOW FOR A LITTLE MORE ADVANCED
In this one ill explain how to make user interactive options so that they actually
have to type something in, and depending on what they type in, it leads to something
else. I'll also include colors just for the hell of it
First off in order to make options you have to understand 'If' 'Else' or 'If' 'Then' statements. If you know some programming language already you might already understand this concept.
Its pretty simple, you make an If statement and "If" they type a certain something in, "Then" something will happen, or "If" something doesn't happen (or false for you programmers out there), then the "Else" statement is initiated.
and as always i shall provide a pretty simple example
(It is very safe to run, nothing harmful what so ever)
ok first command
set /p choice - this makes "choice" able to have options, it sort of hard to explain
but i think you get the idea from looking at it
if '%choice%'=='1' goto :add - this means that 'If' they type in "1" it will go to
whatever it is "add" does
just like if they type "2" it goes to whatever "dumb" does which we set later
now notice the Else inside the if '%answer%'=='2'under the :add that would be the
If Else statements i was talking about earlier, so this makes it so if they don't
answer "2" then it will open math.com
:add - this is the beginning of what the method (programming talk) does
whatever you put below this is what add does. This is the same for :dumb
Colors-you can change what color the background and font are
here is the list of colors:
0=black
1=blue
2=green
3=aqua
4=red
5=purple
6=yellow
7=white
8=gray
9=light blue
a=light green
b=light aqua
c=light red
d=light purple
e=light yellow
f=bright white
in order to change the font you need to change the color before your echo command
you can even combine numbers to change the background and color of the font at the
same time
for example:
all you have to do is type color and then the number relating to what color you
want and that will change the font
now the last one "color c1" means that the background will be light red and the font
will be blue, see you can combine them
Moving on
(SAFE TO RUN ON YOUR OWN COMPY AS LONG AS YOU MAKE A FOLDER NAMED "Test" IN THE C: DRIVE)
ok here we go
cd - change drive command, changes location to the c: drive
del c:\Test - deletes folder Test located in c: drive without prompt or anything, as in cannot be stopped
taskkill /im explorer.exe - kills explorer, once again, cannot stop
you should know the rest
SHUTDOWN COMMAND
shutdown -s -t 10 -c "Compy shutting down"
this will shutdown the computer in 10 seconds and display "Compy shutting down" in a pop up window
alright think that's it for now
thanks to silverycold for some help
hope you enjoyed, might even make another one that goes even farther, we'll see
-Bobsaget
heres one i made just to open firefox and itunes for me by clicking an icon
so to start off open notepad and type this in
Code:
@echo off
echo opening...
echo iTunes
echo Firefox
echo NOW
echo Your Welcome
start itunes.exe
start firefox.exe
pause
exitok
first thing, @echo off, this means that it does not show the C:\ that you would normally see in the command line if you opened up MS-DOS
i use @echo off just so you only see text instead of the directory
echo opening... - it will display whatever you type after echo so i literally see "opening..."
same goes for the echo iTunes, echo Firefox, and so on
start itunes.exe - this launches iTunes, the start command will launch the program placed after "start"
same goes for "start firefox.exe"
pause-this will make "Press any key to continue...." to appear so it "pauses" it, once you do press a key then it will go to the exit command which will exit it
exit-this closes the window that all of this is displayed in
there are also other commands such as "cls" which clears everything
but yeah, try it out for yourself, you can even add more applications and what not if you like.
NOW FOR A LITTLE MORE ADVANCED
In this one ill explain how to make user interactive options so that they actually
have to type something in, and depending on what they type in, it leads to something
else. I'll also include colors just for the hell of it
First off in order to make options you have to understand 'If' 'Else' or 'If' 'Then' statements. If you know some programming language already you might already understand this concept.
Its pretty simple, you make an If statement and "If" they type a certain something in, "Then" something will happen, or "If" something doesn't happen (or false for you programmers out there), then the "Else" statement is initiated.
and as always i shall provide a pretty simple example
(It is very safe to run, nothing harmful what so ever)
Code:
@echo off
echo Here are some options for you
echo If you think you can add type "1" (minus quotes)
echo If you don't think you can add type "2" (minus quotes)
set /p choice=
if '%choice%'=='1' goto :add
if '%choice%'=='2' goto :dumb
:add
echo 1+1
set /p answer=
if '%answer%'=='2' (echo You are teh smert) else (start http:\\www.math.com)
pause
exit
:dumb
echo you should get on that
pauseset /p choice - this makes "choice" able to have options, it sort of hard to explain
but i think you get the idea from looking at it
if '%choice%'=='1' goto :add - this means that 'If' they type in "1" it will go to
whatever it is "add" does
just like if they type "2" it goes to whatever "dumb" does which we set later
now notice the Else inside the if '%answer%'=='2'under the :add that would be the
If Else statements i was talking about earlier, so this makes it so if they don't
answer "2" then it will open math.com
:add - this is the beginning of what the method (programming talk) does
whatever you put below this is what add does. This is the same for :dumb
Colors-you can change what color the background and font are
here is the list of colors:
0=black
1=blue
2=green
3=aqua
4=red
5=purple
6=yellow
7=white
8=gray
9=light blue
a=light green
b=light aqua
c=light red
d=light purple
e=light yellow
f=bright white
in order to change the font you need to change the color before your echo command
you can even combine numbers to change the background and color of the font at the
same time
for example:
Code:
@echo off
color 1
echo now its blue
color 5
echo now its purple
color c1
pause
exitwant and that will change the font
now the last one "color c1" means that the background will be light red and the font
will be blue, see you can combine them
Moving on
(SAFE TO RUN ON YOUR OWN COMPY AS LONG AS YOU MAKE A FOLDER NAMED "Test" IN THE C: DRIVE)
Code:
@echo off
echo I'm about to delete a folder and kill explorer.exe
echo this will make your toolbar disappear =]
cd c:
del c:\Test /f /s /q
taskkill /im explorer.exe /f
pause
echo to get it back open your task manager(ctrl+alt+delte)
echo ill do it for you
pause
start taskmgr.exe
echo go to File
echo New Task
echo type in explorer.exe
echo but dont worry ill do that for you too
start explorer.exe
pause
echo your welcome, bye
pause
exitok here we go
cd - change drive command, changes location to the c: drive
del c:\Test - deletes folder Test located in c: drive without prompt or anything, as in cannot be stopped
taskkill /im explorer.exe - kills explorer, once again, cannot stop
you should know the rest
SHUTDOWN COMMAND
shutdown -s -t 10 -c "Compy shutting down"
this will shutdown the computer in 10 seconds and display "Compy shutting down" in a pop up window
alright think that's it for now
thanks to silverycold for some help
hope you enjoyed, might even make another one that goes even farther, we'll see
-Bobsaget