You are not connected. Please login or register

Simple Batch/DOS

3 posters

Go down  Message [Page 1 of 1]

1Simple Batch/DOS  Empty Simple Batch/DOS Wed Aug 11, 2010 12:19 am

-Insane.Dragon-

-Insane.Dragon-

Hey, well there's a simple little language called Batch. It's really fun, it was the foundation of DOS, and Windows itself. I may be wrong about this, but without DOS or Batch we wouldn't be in the world with Windows as we know it.

Lets start off with the simple things.

@Echo off ; this tells the computer to not show the file location of where the batch file is, i.e C:\Documents and Settings\Administrator\Desktop

Echo ; this tells the computer to print a line of text, i.e Echo Hello this is a test! That would print Hello this is a test on the command prompt

Pause ; this tells the computer to wait for a key to be pressed

Title ; this will give the window a title, i.e title Test Program

color ; this will change the color in the window, such as the font and the background, i.e "color 0a" would give you a black background with lime green text

CALL ; this will "call" or execute another batch file in the current directory. i.e CALL test2.bat

Copy ; this can copy files i.e "copy file.txt c:" that would copy the text file to your C drive

goto ; this tells the computer to go to a certain line in the batch file i.e:


@Echo off
title Test program
color 0a
:1
echo this is a repeating batch file
goto 1

by doing that it will go in an infinite loop because the ":1" is a line that "goto 1" refers to.
make sure that you have the ":" before any variable to go to.

Now lets go a bit further,

The if, then, commands. which is Boolean logic, here are some Boolean operators that you can use:

For the operator AND:

if 1 and 2 then 3 ; so if 1 and 2 are both true then 3 will be the outcome

For the operator OR:

if 1 or 2 then 3 ; so if either 1 or 2 is true then 3 would be the outcome

For the operator NOT:

if not 1 not 2 then 3 ; if 1 is true and 2 is not then 3 would not be the outcome

For the operator ELSE:

if ( 1 and 2 condition is true) then else 3 ; so, if 1 and 2 condtion is true, then do 0, otherwise do 3

For the operator =:

if 1 = 2 then 3 ; so if 1 is equal to 2 then 3 is the outcome

For the operator = =:

If 1 = = 2 then 3 ; so if 1 is not the same as 2, 3 will be the outcome

For the operator >:

if 1 > 2 then 3 ; so if 1 is greater than 2 then 3 is the outcome

For the operator <:

if 1 < 2 then 3 ; so if 1 is less than 2, the outcome is 3

For the operator >=:

if x >= y then 3 ; so if 1 is greater than 2 then 3 will be the outcome if 1=2 then 3 will be the outcome

For the operator <=:

if 1 <= 2 then 3 ; so if 1 is less than 2, then 3 will be the outcome, if 1=2 then 3 will be the outcome



set /p ; this allows you to make a menu or something, I don't really know how to say how it preforms but whatever.... so the usage of this would be like this:

set /p x=Enter a choice
if "%X%"=="1" goto Choice1
Here, x would be your variable that you use.
By looking at the "if "%X%"=="1" goto Choice1" you can see some previous commands in there like "goto"

Well, let's take a look of what we've done so far...

Here is a program that I made to kill LanSchool:

@echo off
title LanSchool RAPiST
color 9f
echo =============LanSchooler=============
echo. 1. View networked computers
echo. 2. Kill student.exe file
echo. 3. Run teacher program
echo. 4. Kill the teacher program
echo.=====================================
set /p x=Enter a Number:
if "%X%"=="1" goto networkview
if "%X%"=="2" goto killer
if "%X%"=="3" goto teacher
if "%X%"=="4" goto techkill

:techkill
call techkill.bat
EXIT


:killer
CALL Kill.bat
EXIT

:teacher
CALL HAHA.bat
EXIT

You can see all the commands and how they work in a file.

Now you try:

copy paste this into notepad and save it as all files as "title here.bat" w/o quotes -.-

@Echo off
title Test
color 9f
Echo this is a test program
pause

that is a simple little program.

Try this one that's a little more intricate:


@Echo off
title Menu 2.0
color 3d
echo =============
echo 1. go to 1
echo 2. go to 2
echo =============

set /p x=Enter a number:
if "%x%"=="1" then goto 1
if "%x%"=="2" then goto 2

:1
echo WELCOME TO MAH WORLD!!!
pause

:2
echo shit....
pause

Yeah this is my very first guide..... I know it's shit but I just made it off the top of my head XD

~xXINSANE.DRAGONXx

2Simple Batch/DOS  Empty Re: Simple Batch/DOS Sun Aug 22, 2010 8:24 pm

Demon450



i always love batch,and you can implement these into a C/C++ program using:
system("commnad");
yes with the quotes, and if you need to put quotes on the line above put the \ before the quote so it is printed as:
"

3Simple Batch/DOS  Empty Re: Simple Batch/DOS Tue Aug 24, 2010 10:25 pm

Angrymasteryoda

Angrymasteryoda

nice little guide always good to know more DOS

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum

 

Free forum | ©phpBB | Free forum support | Report an abuse | Forumotion.com