Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 offTitle 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 Endcls
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

Replace
If %auth%=="Yes" GOTO End
:Loop
If %auth%=="Yes" GOTO Endwith
If /I "%auth%"=="Yes" GOTO End
:Loop
If /I "%auth%"=="Yes" GOTO EndYou 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.

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.

![]() |
![]() |
![]() |

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