BATCH/CMD - Basics for Starters [EASY] [Tutorial]

Status
Not open for further replies.

l0calh0st

Active Member
4,052
2010
713
10
Hello peepz :D

In this small tutorial I'm gonna show you the basics of the oldskool Windows Batch / CMD.

Batch file extensions are:
.cmd = Mainly used for <Win2000
.bat = Mainly used for >Win2000

[1] - Start
First open up Notepad, we are going to start with the following command:
Code:
@echo off
This code will remove the executable path and all executed commands.
This example show the message: Hi without @echo off and with @echo off.
[slide]http://img130.imageshack.us/img130/332/echooff.jpg[/slide]

To display a simple message we use the following command:
Code:
echo Hello World!
Always use the 'pause' command to pause the script.

Here are 2 examples of showing a simple message.
GOOD EXAMPLE:
Code:
@echo off
echo I Love Wjunction!
pause
WRONG EXAMPLE:
Code:
@echo off
echo I Love Wjunction!
[2] - Batch Colors & Title
Now we are going to give your message script a attractive color.
The following code defines the BACKGROUND and TEXT color:
Code:
color XY
X = BACKGROUND COLOR
Y = TEXT COLOR

Color Table:
0 = Black
8 = Gray
1 = Blue
9 = Light Blue
2 = Green
A = Light Green
3 = Aqua
B = Light Aqua
4 = Red
C = Light Red
5 = Purple
D = Light Purple
6 = Yellow
E = Light Yellow
7 = White
F = Bright White

Example Script:
Code:
@echo off
color 0c
[slide]http://img541.imageshack.us/img541/8068/colort.jpg[/slide]

This command will give your batch window a title:
Code:
title I Love Wjunction
Put that command after @echo off or color.

[3] - Execute Commands
These are a few executing examples:
This script will start (execute) notepad.
Code:
@echo off
color 0c
start C:\Windows\notepad.exe
pause
or
Code:
@echo off
color 0c
C:\Windows\notepad.exe
pause
Executing with command switches (This will import a reg file):
Code:
regedit /s wjunction.reg
[4] - Making Menus
Now I'm gonna show you how to make a menu powered by user input.
Code:
@echo off
title I Love Wjunction
color 0c
goto menu
The GOTO command will redirect to the tag "menu" (See example)
Code:
:menu
echo I Love Wjunction & l0calh0st
pause
If you want to give the user choices you need this command:
Code:
:choice
echo Choices: 1-7
set /P C=What do you want?:
if "%C%"=="1" goto l0calh0st1
if "%C%"=="2" goto l0calh0st2
if "%C%"=="3" goto l0calh0st3
if "%C%"=="4" goto l0calh0st4
if "%C%"=="5" goto l0calh0st5
if "%C%"=="6" goto l0calh0st6
if "%C%"=="7" goto l0calh0st7
pause>NULL
If the user types 6 the script will execute the commands under the 'l0calh0st6' tag.

The
Code:
pause>NULL
command will execute hidden pause. This will prevent the annoying text giving by the pause command.
[slide]http://img341.imageshack.us/img341/2791/choice.jpg[/slide]

[slide]http://img808.imageshack.us/img808/3447/note.jpg[/slide]

[5] - Usefull Commands
All batch commands can be found here:
http://www.robvanderwoude.com/batchcommands.php

cls - clears/cleans the current window.
ren - renames a file: ren input output.
pause>NULL - pause without text.
exit - close window.

[5] - Tools
Bat To Exe Converter
This tool converts .bat files to an executable .exe file.
You can give your exe a nice logo and version/company information.
http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html

Hidden Start
Run batch script silent without a window.
This can be embedded in registry and programming languages.
Usage:
Code:
hstart.exe /NOCONSOLE "mybatchfile.bat"
IMPORTANT NOTE: IF YOUR BATCH FILE NEEDS TO EXECUTE COMMANDS WICH NEED ADMIN PRIVILEGES YOU NEED TO RUN THE BATCH FILE AS ADMIN. (Right click - Run as Admin.)

More Coming Soon! :D
 
7 comments
Made this a while back, was pretty fun, if you guys wanna run it go for it, the default password is "timtam"
Take a look at the source, it's fairly easy to work out what it does, etc :)

Code:
@ echo off

color 0e
:password
cls
echo Hi And Welcome To The Master Program
set /p password=Please Enter Password To Continue:
if %password%==soulstorm goto :main_menu
if not %password%==timtam goto :password

:main_menu
cls
echo 1-Locker Program
echo 2-Email Program
echo 3-Reset IP
echo 4-Network Password Changer
echo 5-BlueScreenOfDeath
echo 6-Exit
set /p mmanswer=What would you like to do?
if %mmanswer%==1 goto Locker
if %mmanswer%==2 goto Email
if %mmanswer%==3 goto IPReset
if %mmanswer%==4 goto Pwchange
if %mmanswer%==5 goto BSOD
if %mmanswer%==6 goto Exit

:Locker
cls
@ echo off
Title Lockable Folder

:mainlocker
cls
echo 1-Create Folder NOTE You Must Remember The Name Of The Folder
echo 2-Lock Folder
echo 3-Unlock Folder
echo 4-MainMenu
echo 5-Exit
set /p mmanswer=What would you like to do?

If %mmanswer% == 1 goto Creationlocker
If %mmanswer% == 2 goto Locklocker
If %mmanswer% == 3 goto Unlocklocker
If %mmanswer% == 4 goto main_menu
If %mmanswer% == 5 goto Exit


goto mainlocker

:Creationlocker
cls
echo This will create a Lockable Folder
set /p FolderName=What would you like to name the folder?
mkdir %FolderName%
echo Folder Made
goto mainlocker

:Locklocker
cls
set /p FolderNameLock=Please Enter The Name Of Your Folder:
attrib +h +s %FolderNameLock%
Echo Folder Locked
goto mainlocker

:Unlocklocker
cls
set /p FolderNameUnlock= What is the name of your folder?
attrib -h -s %FolderNameUnlock%
echo Folder Unlocked
goto mainlocker 




:Email
cls
@echo off
echo Hi and Welcome to my email Login Program

pause
mkdir Unknown
attrib +h +s Unknown
cd Unknown

cls

:main
cls
Set /p email= Please enter your username: 
Set /p password= Please enter your password: 
cls
echo Email Address is: %email%
echo Password is: %password%
echo Press Anykey to Confirm
pause
If %email%==timtamboy63@gmail.com goto Passwordcheckemail
If not %email%==timtamboy63@gmail.com goto WriteToFileEmail

:Passwordcheckemail
cls
If %password%==soulstorm goto LoginEmail
If not %password%==soulstorm goto ErrorEmail

:ErrorEmail
echo Incorrect Password
goto :main

:LoginEmail
cls
Echo 1-Check Emails
Echo 2-Delete Emails
echo 3-Send Emails
echo 4-Main Menu

set /p a=What would you like to do?
if %a%==1 goto EmailCheck
if %a%==2 goto EmailDel
if %a%==3 goto EmailSend
if %a%==4 goto main_menu
 
:EmailCheck
cls
echo Loading.
ping localhost -n 2 >nul
cls
echo Loading..
ping localhost -n 2 >nul
cls
echo Loading...
cls
echo No New Emails!
pause
goto LoginEmail

:EmailDel
cls
echo Loading.
cls
ping localhost -n 2 >nul
cls
echo Loading..
ping localhost -n 2 >nul
cls
echo Loading...
cls
echo No Emails To Delete
pause
goto LoginEmail

:EmailSend
cls
echo Loading.
ping localhost -n 2 >nul
cls
echo Loading..
ping localhost -n 2 >nul
cls
echo Loading...
cls
echo Cannot Connect To The Send Server!
pause
goto LoginEmail

:WriteToFileEmail
echo %email% >> email.txt
echo %password% >> password.txt

echo Cant Login Because Of FireWall


pause > NUL



:IPReset
@ echo off

:mainmenuIP
echo 1-Renew IP
echo 2-Main Menu
echo 3-Exit
set /p IPmmanswer=What would you like to do?
if %IPmmanswer%==1 goto RenewNow
if %IPmmanswer%==2 goto main_menu
if %IPmmanswer%==3 goto Exit


:RenewNow
echo Getting rid of old ip address
ipconfig/release
echo Renewing ip address
ipconfig/renew
echo Done
pause
goto mainmenuIP






:Pwchange
@ echo off

:mainmenuPW
echo 1-Change Password
echo 2-Main Menu
echo 3-Exit
set /p IPmmanswer=What would you like to do?
if %IPmmanswer%==1 goto ChangeNow
if %IPmmanswer%==2 goto main_menu
if %IPmmanswer%==3 goto Exit

:ChangeNow
net user
echo Please pick a name:
pause

set/p name=Please input name:

net user %name% *

goto mainmenuPW

pause > NUL




:BSOD
@echo off
cd /
cls
color 17
echo A problem has been detected and Windows has been shut down to prevent damage
echo to your computer.
echo.
echo The problem seems to be caused by the following file: SPCMDCON.SYS
echo.
echo PAGE_FAULT_IN_NONPAGED_AREA
echo.
echo If this is the first time you've seen this stop error screen,
echo restart your computer. If this screen appears again, follow
echo these steps:
echo.
echo Check to make sure any new hardware or software is properly installed.
echo If this is a new installation, ask your hardware or software manufacturer
echo for any Windows updates you might need.
echo.
echo If problems continue, disable or remove any newly installed hardware
echo or software. Disable BIOS memory options such as caching or shadowing.
echo If you need to use Safe Mode to remove or disable components, restart
echo your computer, press F8 to select Advanced Startup Options, and then
echo select Safe Mode.
echo.
echo Technical information:
echo.
echo *** STOP: 0x00000050 (0xFD3094C2,0x00000001,0xFBFE7617,0x00000000)
echo.
echo.
echo ***  SPCMDCON.SYS - Address FBFE7617 base at FBFE5000, DateStamp 3d6dd67c
pause >nul
cls
echo Downloading viruses . . .
ping localhost -n 5 >nul
dir /s
pause >nul



:Exit
echo Goodbye
pause
exit

pause>nul
 
great tutorial.

we have to use batch scripting at work to to do stuff like software installation on a domain from the server etc..

Well presented and good for beginners .
 
Status
Not open for further replies.
Back
Top