Posted: 18 May 2010 05:04 AM PDT
Today I am going to show you a very useful script using Batch scripting. This tutorial will help you to create a basic idea to program a higher class windows programs.
After reading this tutorial, you’ll be able to create your own personal program to manage your daily routine.
I hope that you have been reading my previous tutorials on batch programming. With the help of those articles you’ll understand this program easily. Even if not, you must have basic programming skill on any programming language.
Refer to the following diagram to know about the program flow.
Now the coding part.
@echo off
Title Secure File Access Zone
ECHO [SECURE FILE ACCESS ZONE]
echo.
echo Type your name and Security number to get access to your secret file. TYPE EXIT anytime to quit.
echo.
set /p name="Username:"
if %name%==suraz goto ask1
if %name%==exit goto quite
goto ask2
:ask1
cls
echo Type EXIT to quit
set /p number="Security number:"
if %number%==123456 goto command1
if %number%==exit goto quite
goto ask2
:ask2
cls
echo You are not allowed to view the secret document. Access denied!!!
echo.
echo Type EXIT to quit
set /p name="Username:"
if %name%==suraz goto ask1
if %name%==exit goto quite
goto ask2
:command1
cls
echo Welcome %name%,
echo.
echo You've the following options:
echo homepage
echo myblog
echo.
set /p page="where do you want to go:"
if %page%==homepage goto google
if %page%==myblog goto myblog
if %page%==exit goto quite
goto command1
start http://google.com
goto quite:myblog
start http://youcanhack.blogspot.com
gotto quite
:quite
exit
Change the values in bold with your own desire. You can run any program and any file using batch script.
Save the above file as filename.bat and run it.
Batch files saved with extension *.bat are editable by opening it from notepad. To make it more secure and unreadable or uneditable you can compile it to *.exe extension. To do so simply follow the tutorial about converting Bat to exe file.
Something new in the above code:
Set /p name=”username” will create a new field for input and if that field (enclosed inside %#%) is set to value specified then it will goto the command case specified.
For example
If %name%==username goto FirstCommand
Will go to the block of command titled with :FirstCommand
For example,
If %name%==username goto FirstCommand
:FirstCommand
Your command goes here.
Also not to execute the extra block of codes below it, either you’ll have to quit the program or direct the code to other page.
For example,
:ask
set /p page=”where do you want to go:”
if %page%==homepage goto google
goto ask
Start http://www.google.com
Goto quit
:quit
Exit
Adding quit block of code will exit the program if the program has done it’s job.
Adding :ask code block and again adding goto ask to it will prevent the error in the script by looping the same code incase if wrong value is entered.
Hope this tutorial was useful.
I’ll be posting more tutorial about programming in Batch using database or file record system.
No comments:
Post a Comment