Hack Forums

Full Version: you guessed it, another Batch tut!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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
Code:
@echo off
echo opening...
echo iTunes
echo Firefox
echo NOW
echo Your Welcome
start itunes.exe
start firefox.exe
pause
exit
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)
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
pause
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:
Code:
@echo off
color 1
echo now its blue
color 5
echo now its purple
color c1
pause
exit
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)
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
exit

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
Some of these batches don't even work.
like which ones? because i tested them on my computer
Batch Should Just go away! :P
lol youd like that wouldnt you, ive you seen you post on like every batch tut, but hey at least i didnt say that it was a virus ;)
i think i see what other people were saying. when i do this on my XP Pro laptop, i have

Code:
@echo off
echo opening...
echo iExplorer
echo Firefox
echo NOW
echo Your Welcome
start IEXPLORER.EXE
start firefox.exe
pause
exit

This seems to run, do nothing (obvisouely cos of the echo off), throws a hissy fit about not being able to find the progams! however, the first window pauses, and a new cmd.exe opens.

so i change this...

i think i see what other people were saying. when i do this on my XP Pro laptop, i have

Code:
@echo off
start "C:\Program Files\Internet Explorer\IEXPLORER.EXE"
start "C:\Portable\PortableApps\FirefoxPortable\FirefoxPortable.exe"
exit

and i'm left with the same problem, nothing happens, the first window pauses and wants a key pressed, when pressed it closes... and as before a new cmd.exe is opened.

Now, i see this as a minor problem, programs not opening... i tried this as i want to open about 4 programs at once.

any suggestions?
well for me internet explorer is iexplore.exe not iexplorer

and if its not working then try changing the drive using the cd commmand to where the applications are located
so itd be like
Code:
@echo off
cd c:\program files\internet explorer
start iexplore.exe
cd c:\portable\portableapps\firefoxportable
start firefoxportable.exe
try that?
absolute genious, i tried CD'ing and works fine, and you were correct, it was iexplore. which leads me to beleive the code submitted by OP was incorrect all the more, as it would have said "can't find iexplorer.exe" or somethin.

Big thanks bob :D This might be handy :D

one other question, you seem to know what you're talkin about. at work, cmd.exe is blocked by admins, however the command.com isn't.... anyway we can initiate a *.bat file in command.com? this way i can open all my systems etc at once. lol
thxxxxxxxxxx man , great tutorial
@nicolas cage
my pleasure =]

@karial
i'm not familiar with command.com, and since cmd.exe is blocked you mean you cant run any batch files? you've probably tried this but you never know, going to the run command and typing in cmd?
Pages: 1 2
Reference URL's