Cmd says goto univabile help?

May 26, 2010 at 15:12:41
Specs: Windows 7
I am working on this batch file. When I goto choice 5 (my admin part) and i enter the correct password, it says GOTO uxpected at this time. Then it closes out. Can someone help me? Here is my batch file im working on...

@echo off
Color a
Echo 1. Shutdown
Echo 2. Restart
Echo 3. Hibernate
Echo 4. Quit
Echo 5. Admin
Choice /C 12345 /N /M "Press 1,2,3,4 or 5."
if errorlevel == 5 goto five
if errorlevel == 4 goto four
if errorlevel == 3 goto three
if errorlevel == 2 goto two
if errorlevel == 1 goto one
:five
Set input=
Set /p=Admin Password:
if %input%==pass GOTO Admin
if not %input%==pass GOTO Wrong
:Admin
Echo Hello master.
:Wrong
Echo Wrong password, please try again.
ping localhost -n 3 >nul
cls
goto five
:four
Echo Good bye.
ping localhost -n 3 >nul
Exit
:three
Echo Now Hibernating.
Shutdown /h
Exit
:two
Echo Now Restarting.
Shutdown /r
Exit
:one
Echo Now Shutting down.
Shutdown /s
Exit


See More: Cmd says goto univabile help?

Report •

#1
May 27, 2010 at 08:54:52
This question must be posted in the Programming Forum as there is no DOS in Windows 7 (it is a NT kernel system).

So stated your r knowledge of batch scripting is quite poor as

1) to check ErrorLevel you have to code

if ErrorLevel 5

2) Your if has no meaning, replace with

if "%input%"=="pass" GOTO :Admin

and for now I stop here.


Report •

#2
May 27, 2010 at 17:35:53
the quotes on if %input%==pass are optional so thats wrong. I was right on that.. and if errorlevel == 5 is correct i tested it its when i type in the "pass" part it doesnt work!

Report •

#3
May 28, 2010 at 07:08:21
Replace

Set /p=Admin Password:

with

Set /P input=Admin Password:

I missed that mistake, but I confirm you have a raw knowledge of batch scripting and suggest you try to press the Enter key instead of typing any password to see why double quotes are needed in IF statements.


Report •

Related Solutions

#4
May 29, 2010 at 09:19:20
Thanks I must have missed that! It works I tested it!

Report •

Ask Question