Computing.Net > Forums > Programming > Batch File Loop - Help

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File Loop - Help

Reply to Message Icon

Name: PrincessGeek
Date: January 23, 2007 at 11:38:56 Pacific
OS: XP
CPU/Ram: P4/1GB
Product: Dell
Comment:

Can anyone tell me how to write a batch file that will do the following?

1.) Ask the user for a product key?
2.) Then call a program at command line with the product key appended
3.) Then ask the user if the product key was correct and installed successfully
4.) Yes/No if yes, then do exit and if no then "loop" back to step 1.) again and do it all over

***I got step 1.)to step 4.), but the loop won't stop no matter if it's a "yes" or "no"

***here's my code***

can you see what's wrong?

************************
@echo off

Title Verify Registration Code

echo Please enter your registration key provided on the download site:

echo.

set /p Key=Here -^>

echo.

echo Your registration number is %key%

echo.

echo Processing...

echo.

echo %username%

echo.

call install %key%

echo Was your installation successful with the product key you entered? Please type "Yes" or "No", followed by the enter key...

echo.

set /p auth=Yes/No -^>

echo.

echo You answer was %auth%

pause

If %auth%=="Yes" GOTO End

:Loop
If %auth%=="Yes" GOTO End

cls

Title Verify Registration Code

echo Please enter your registration key provided on the download site:

echo.

set /p Key=Here -^>

echo.

echo Your registration number is %key%

echo.

echo Processing...

echo.

echo %username%

echo.

call install %key%

echo Was your installation successful with the product key you entered? Please type "Yes" or "No", followed by the enter key...

echo.

set /p auth=Yes/No -^>

echo.

echo You answer was %auth%

pause

SHIFT
GOTO Loop

:End

echo.

echo Thank you!

pause

ping -n 1 127.0.0.1>nul
ping -n 1 127.0.0.1>nul
ping -n 1 127.0.0.1>nul
ping -n 1 127.0.0.1>nul
ping -n 1 127.0.0.1>nul
ping -n 1 127.0.0.1>nul

*****************************

Thank you!

Thanks!

PrincessGeek



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: January 24, 2007 at 03:19:21 Pacific
Reply:

Replace

If %auth%=="Yes" GOTO End
:Loop
If %auth%=="Yes" GOTO End

with

If /I "%auth%"=="Yes" GOTO End
:Loop
If /I "%auth%"=="Yes" GOTO End

You missed the " embracing the variable, so the If is never satisfied, but the user types "Yes".

And better you add the /I switch that makes the If no case sensitive allowing to enter YES, Yes or even yEs.


0

Response Number 2
Name: IVO
Date: January 24, 2007 at 06:25:44 Pacific
Reply:

Another note, the SHIFT statement at the end of your script (that could be improved) seems meaningless as it acts on the %1, %2 and so on external variables not accessed in the posted batch.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch File Loop - Help

Batch file loop help www.computing.net/answers/programming/batch-file-loop-help/13017.html

Simple Batch File command help www.computing.net/answers/programming/simple-batch-file-command-help/16568.html

Batch File Formmatting Help, Please www.computing.net/answers/programming/batch-file-formmatting-help-please/14040.html