Batch Files

Thursday, February 11, 2010 by BBTUNA
Hi....well, i decided to try and do my first tutorial on how you can use batch files to your full extent...

....Technically, DOS provides just eight basic batch file commands -- CALL, ECHO, FOR, GOTO, IF, PAUSE, REM, and SHIFT -- plus a tiny assortment of miscellaneous doodads: replaceable parameters, environment variables, labels, double == signs, and @ signs. That's it! Not too much to learn, even for the most fervent DOS-hater. But the tools these few commands can create will astonish you.....

PC Computing - DOS Power Tools by Paul Somerson

Batch files can be used for a large amout of different things, anything from gettting specific commands to start at specific times, to opening cmd in a limited account, to getting a first easy taste to the magic of programming, to just have the thrill of being to write in it!

Batch files are made from the basic notepad (WIN + R, then type in notepad).
Inside notepad the fun can begin.

BASIC BATCH FILES

To start with, we'lll make a simple .bat file to say "Hello World" and then pause.

@echo off
echo Hello World!
echo.
pause ::
exit
rem I love undergroundsystems.org!

Ok, now to have fun and disect it :P

To start with there's the @echo off. The @ means that the "echo off" part of the code isnt run visibly to the user. The "echo off" is also a secret spy tool! When this is put in, the user can still run the program, but with the flipping
"C:\documents and settings\my documents\" or however your logged on.

The echo is like the "COUT" comman in C. It sends whatever you write after it to the screen of your bat file. When you wrote "echo Hello World!", it sends to the screen "Hello World!", ommitting the echo. The "echo." is a nifty command to make writing in a batch file a lot easier. It basically just leaves a blank line, which i can tell you is a hell'ov a lot easier to see, than say:

Hello World
Press any key to continue...

:eek: :eek: :eek:

Next there is the "pause ::". Now I dont think there is any difference if you write "pause" or "pause ::". In any case, they both do the same visible thing. :rolleyes: when you type this into your batch file, it will say when you run the program:

"Press any key to continue" Gosh not a please! :mad:

As soon as you click any key, the program will continue to the next line of the code. which in our case is the "exit" command. This does what any jack-a$$ might think it does....exits or shutsdown the program. Nothing spectacular lol.

Finally in our little program, there is the "rem I love US.org!". Now if you added this into your program when you ran it, you might have/or might not have been a bit puzzled to see that it didnt pop up. WTF This is because its just for you to write your notes after it...maybe not for a program like "Hello World", but something much longer and harder to script.

Phew, that was a hell of a lot for 5 lines of programming! (goes off to get a cup'a'tea.)

GETTING CMD WITH BATCH FILES

Many people use batch files to get good'old cmd, in say a limited user. First can I say that im not encouraging anyone to try and do this, errr, its for administrators to test their security?....what is it :rolleyes: ....erm for security testing purposes only?....oh well, this isnt top secret super hacker stuff...

Most cmd commands can be run from a batch file, and cmd can also be run from a batch file..Here is a little script i just made (sorry for any mistakes), which will try and open cmd with a variety of methods:


@echo off
pause
cmd.exe
pause
command.com
pause
cmd
pause
c:\WINDOWS\system32\cmd.exe
pause
rem ############echo please modify this accordingly############
COPY "c:\WINDOWS\system32\cmd.exe" "c\documents and settings\##please enter your username here##\my documents"
pause
exit


Now, this code simply just goes through different ways to open up cmd.. The first 5 ways will always work..unless your admin :P (yer, i know you'll try this in schools), blocks them. If your admin is like the BOFH: (http://www.google.co.uk/search?hl=en&q=bofh&meta=) he might even have banned batch files, but oh well.... they did for me.. :madman:

Final section now..

RUNNING EASIER SCRIPTS!

Now batch files can also be used to make nice simple scripts that help tha tards out there. :tard:

Here is one which basically helps you make a new user on your non-networked computer.

@echo off
:A
cls
echo Poetic-Justics's user creation program.
echo.

set /p n="Old User-name: "
echo.
set /p m="New user-name: "
echo.
set /p p="New user-name password: "
echo.
set /p g="new user-group: "
echo.
set /p s="Are you sure you want to do this? "
if %s%==yes goto B
if %s%==no goto c

:B
cls
net user %m% %p% /ADD
net user %n% /DELETE
net group %g% %m% /ADD

:C
cls
echo Thanks for using this easy user creation....blah, blah, blah..
echo.
pause ::
exit

Now you could also add in things such as, "please confirm the password" or whatever, but im too tired :P In case anyone did want to try and do that though its :

set /p h="please confirm password: "
if %h%==%p% goto "whereever you want it to go to"

FINAL WORDS!

Anyway, here are my final words on cmd. They are a great way to start programming in my view, its a lot easier than most other proper things like C, delphi ect...but its a lot more limited. Its really easy to learn actually, and when you can, you get the great feeling that you can do most things with them.

Some links that might help you (they did help me) are:

*http://www.robvanderwoude.com/batchfiles.html
*http://www.ericphelps.com/batch/tricks/index.htm
*http://www.ericphelps.com/batch/
Posted in | 0 Comments »

0 comments:

Post a Comment

About Me

Blog Archive