[TUT] Intermidiate Batch

View previous topic View next topic Go down

[TUT] Intermidiate Batch

Post by Logic_Bomb on Thu Jan 07, 2010 7:56 pm

Here you will learn how to to use the paramiters call menu's you saw in 'Beginner' and 'Call' batch tutorials along with a few other bit's and pieces.

How to set up a password that a user can change to access a batch file.

Ok here is the main code that you will be using, I will then explain section of code for you and let you try it for yourself.

Code:

:start
@echo off
cls
if exist PW.bat goto exist
echo We seem to be aware that you have no password,
echo Please Set one to continue... (Press any key)
pause > null
echo.

:newpass
cls
set /p Pass= New password:
echo Please Re-Type to confirm.
set /p Pass2= Re-Type New Password:
if %pass% == %pass2% goto writeoutln

:Nomatch
cls
Echo Passwords did not match please re-try...
echo Press any key to enter a new pass...
pause > NUL
goto newpass

:writeoutln
cls
echo set Password=%pass% > PW.bat
echo Success press any key to log-on...
pause > nul
goto start

:exist
cls
call PW.bat
set /p PW1= Please enter password:
if %PW1% == %password% goto loggedon

:incorrect
cls
echo You have entered an incorrect password
echo Press any key to try again...
Pause > Nul
goto exist

:loggedon
cls
echo you logged on well done, Press any key to change pass...
pause > NUL
goto newpass


Tip: put a break between sections in your code (I.e the :flags) this way it keeps your coding tidier and less confusing.

Now I will explain the new commands I have used and the way I have used paramiters...

Key:

CommandUse
@echo on/off Turns the repeat of Text on or off.
EchoShows the text that you type after echo E.g ( Echo {Text} ).
ClsClears any Text on the console window.
set {type} {Paramname}= {(/P only) display text} Set a paramiter.
NulOutputs nothing on selected operation.
echo {text or Param} > {File or Location}Echos whatever you like into a document.
:{Word}Sets a checkpoint within the code that it can go foward or back too.
Pause Stops the Code and awaits user input.

Here are a few sections you may have not seene before...

Code:

:newpass
cls
set /p Pass= New password:
echo Please Re-Type to confirm.
set /p Pass2= Re-Type New Password:
if %pass% == %pass2% goto writeoutln


This is uses paramiters multiple time to make sure you have entered the same pass twice, The bit you may not understand is:

Code:

if %pass% == %pass2% goto writeoutln

Here what it does, "%pass%" and "%pass2%" are both paramiters for the entered passwords set above by "set /p pass=" and "set /p pass2=" these are then varified by the bottom line, Which basically states 'if the two passes mach goto the writeoutln section if not continue the code', So it uses the 'if' statement to start the comparsion, Then it states "%pass", it then uses "==", The double equals sign says the the next paramiter or word must be directly identical (Case sensitive) - then it continues to state "%pass2".

So that should be that section covered.
The next section you may not understand is the following:

Code:

:writeoutln
cls
echo set Password=%pass% > PW.bat
echo Success press any key to log-on...
pause > nul
goto start


This section may look pretty confusing b ut is accually very basic, the bit you possibly won't understand is the "echo set Password=%pass% > PW.bat" this is accually very simple:

"echo" = indicates obviously that you are entering text to write out.

"set password=%pass%" = The text that you want outputting where-ever with the variable of the password.

">" = Indicates that the it is going to write to a file not into the command prompt, you could also use ">>" (">" Tells the code to write over anything else in the following file and ">>" will tell the code to write on the next line within the following document).

"PW.bat" = This is the document we want to write "set password=%pass%" too.

So if I say it in english it is saying write "set password= %pass%" too the document PW.bat whilst overwriting naything else within that documnet.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I hope I have done well in this tutorial and I hope you all have much fun messign around with this code and making it your own =D

Happy coding!

Kiz

_________________
Forum Founder
Web-Admin
Forum Moderator
------------------------------
Underground Activator
-------------------------------
ภєשєг ђคςк ค ђคςкєг
avatar
Logic_Bomb
Admin
Admin

Posts : 161
Join date : 2009-05-12
Age : 25
Location : Cyberspace

View user profile http://the-underground.darkbb.com

Back to top Go down

Re: [TUT] Intermidiate Batch

Post by Matsen on Thu Jan 07, 2010 9:33 pm

Nice tut for beginners in batch Smile they will like it Smile (im not one of them Razz)

+1!

_________________
Spread my word:

ภєשєг ђคςк ค ђคςкєг

- Matsen
avatar
Matsen
R4TT3R
R4TT3R

Posts : 75
Join date : 2009-05-24

View user profile http://Look at ur web url...

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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