You are viewing our Forum Archives. To view or take place in current topics click here.
Batch Tutorial + Useful and Cool Batch Scripts
Posted:

Batch Tutorial + Useful and Cool Batch ScriptsPosted:

Charmeleon
  • Wise One
Status: Offline
Joined: Aug 03, 201112Year Member
Posts: 523
Reputation Power: 23
Status: Offline
Joined: Aug 03, 201112Year Member
Posts: 523
Reputation Power: 23
Well, my latest task is to learn batch scripting, so I figured I would teach you guys what I learned so far. A batch file is a computer file, containing commands to be executed by a computer. Batch files characteristically use a .bat file extension. Batch files can be used for simply conveying messages, making viruses, or making complex programs.

To create a batch file, open a blank notepad file. Paste or write in the code, then save as "anything.bat". The .bat extension is very important. Also, make sure you select "All Files" when saving. To run the file, double click the icon. To edit afterward, right click and edit.

Basic batch commands:

@echo off- Commonly used at the beginning of a script. Makes the commands issued not show up in command prompt window.
echo- Batch files open in Command Prompt windows. Anything written after "echo" is shown in the window.
color ??- Sets the color of the text and background of the window. See below for colors. (replace ?? with color codes)
title- Gives the window a title.
pause- temporarily pauses the commands, resuming when the user presses any key on the keyboard.
quit- Closes window.


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

The first character is the color of the background, the second is the color of the text.

Now that you have the basics, you should be able to follow along with these scripts.


Basic message:

@echo off
echo Hello TTG! What's Up?
pause
echo If you're reading this, you just created a batch file!
pause
echo Goodbye
pause
quit


More Advanced:

@echo off
title My Batch File
color 03
echo Anything you want to say goes here.
pause
echo Continue however many times desired.
pause
quit


Hopefully you have gotten the hang of batch already. Now lets move onto something more useful.

Do you have a certain URL that you want to remember? Maybe you don't really want to save it on your computer somewhere? Well batch can be used as sort of a complex shortcut.

Simple shortcut:

@echo off
echo Ready to visit your site?
pause
start iexplore.exe [ Register or Signin to view external links. ]
quit

This would open internet explorer and navigate to google. Replace google with the URL of your choice. You may be thinking that you might have well use a regular shortcut. Well, can a regular shortcut do this?

@echo off
title Authentication
color 0a
echo Welcome, YOURNAMEGOESHERE
echo Please Enter Your Password:
set /p password=
if %password% == PASSGOESHERE goto correct ELSE FALSE goto false
:false
echo Authentication Failed:
pause
echo Deleting Information
shutdown.exe -s -t 10 -c "System Shutting Down"
quit
:correct
echo Thank You YOURNAMEHERE
start iexplore.exe (site URL goes here)
pause
quit

*Warning: above script will shutdown pc if the password is entered incorrectly. To remove this, remove the shutdown.exe line from script. Also, replace info with your own.


Loading Effect:

The loading effect does basically nothing, but gives your file a great look. All it does is display loading and changes the amount of periods.

@echo off
title Authentication
echo Welcome Back.
pause
echo Let me connect you.
pause
echo Loading.
ping localhost -n 2 >nul
cls
echo Loading..
ping localhost -n 2 >nul
cls
echo Loading...
ping localhost -n 2 >nul
cls
echo Connected
pause
quit

All this code is doing, is replacing the text of loading very fast. Loading doesn't look like it is changing, but the periods do.


Fake Viruses:

Opening Unlimited CMD Windows-

@echo off
:top
start
goto top

The same can be done with any program. Lets say you want to use notepad instead.

@echo off
:top
start notepad.exe
goto top

Creating unlimited windows will eventually crash your computer, and I recommend you don't do it. For a safer alternative, try this:

@echo off
title SPAM
start
start
start
start
start
quit

This will open 5 windows. You can alter the amount of windows by adding/subtracting starts.


Complex Fake Virus:

@echo off
title Virus Scan
color 0a
echo A virus has been detected in your system...
pause
echo Initiating Virus Scan.
ping localhost -n 2 >nul
cls
echo Initiating Virus Scan..
ping localhost -n 2 >nul
cls
echo Initiating Virus Scan
ping localhost -n 2 >nul
cls
echo 247 Threats Found
echo Would you like to remove?
pause
echo Removing...
echo Trojanvx37.exe is attempting to format harddrive.
echo Would you like to cancel?
pause
echo Harddrive will now be formated. Please Wait...
pause
echo Your computer is being shutdown to protect information
shutdown.exe

While this script is completely harmless, It will shutdown your computer when it is run.


Other Cool Scripts:

Matrix Effect-

@echo off
cls
title Enter The Matrix
color 02

set string=Wake up Neo...
set /a len=18
call :DisplayText

ping localhost -n 4 >nul
set string=The Matrix has you...
set /a len=25
call :DisplayText

ping localhost -n 4 >nul
set string=Follow the white rabbit.
set /a len=28
call :DisplayText

ping localhost -n 4 >nul
set string=Knock, knock, Neo...
set /a len=24
call :DisplayText

ping localhost -n 4 >nul


goto matrix


:DisplayText

set /a dispvar =1
set /a len +=1

:DisplayLoop

CALL SET str=%%string:~0,%dispvar%%%

cls
echo %str%
ping localhost -n 1 >nul

set /a dispvar +=1

if '%dispvar%'=='%len%' goto enddisplay

goto DisplayLoop

:enddisplay
exit /b

:matrix
setlocal enabledelayedexpansion
for /l %%A in (1,1,39) do (
set /a rnd=!random!%%5+1
if !rnd!==1 (
set /a rnd2=!random!%%26+1
set num=1
for %%A in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if !rnd2!==!num! (
set add=%%A
)
set /a num+=1
)
) else set /a add=!rnd!%%2
set var=!var! !add!
)
echo !var!
call :matrix
#2. Posted:
Charmeleon
  • Wise One
Status: Offline
Joined: Aug 03, 201112Year Member
Posts: 523
Reputation Power: 23
Status: Offline
Joined: Aug 03, 201112Year Member
Posts: 523
Reputation Power: 23
Edited to add new scripts, fake viruses, and matrix effect.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.