Can Someone please help me- Huge Problems with batch Script!

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Rileyh
Posts: 147
Joined: 01 Sep 2011 03:54
Location: Perth, Western Australia

Can Someone please help me- Huge Problems with batch Script!

#1 Post by Rileyh » 02 Sep 2011 00:26

Hi all,
Im having some big problems with my script im writing. It is supposed to get the user to enter a password,
and if the password is incorrect, it shuts down the computer. (Note- it will be placed in the start menu)
Here is the code:

@echo off
set /p _%1=Enter the password:
if _%1==_"yes" goto :a else goto :b

:a
echo Hello Riley
pause
exit cmd

:b
echo Incorrect user. Shutting down in 5 seconds...
timeout /t 3 /nobreak >nul
shutdown /s[/color]

Could someone please help me get this to work. You don't have to use the same code as I have written.

Thanks,
Rileyh

Exouxas
Posts: 34
Joined: 01 Sep 2011 12:52

Re: Can Someone please help me- Huge Problems with batch Scr

#2 Post by Exouxas » 02 Sep 2011 04:11

Which part is there a problem with?

If you dont know, make a pause statement between every line and count until you have found it.

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Can Someone please help me- Huge Problems with batch Scr

#3 Post by trebor68 » 02 Sep 2011 12:34

The variable %0 ... %9 are for input option.
I.E. MyBatch /cat=in /add=all /view
%0 - name of the batch file - "MyBatch.bat"
%1 - first option - "/cat"
%2 - second option - "in"
...

To your code:
set /p _what=Enter the password:
if %_what%#==Yes# goto :a else goto :b

The variable "_what" is saving the password. Only the password "Yes" is correct. The password "yes" is incorrect.

nitt
Posts: 218
Joined: 22 Apr 2011 02:43

Re: Can Someone please help me- Huge Problems with batch Scr

#4 Post by nitt » 02 Sep 2011 20:16

Rileyh wrote:Hi all,
Im having some big problems with my script im writing. It is supposed to get the user to enter a password,
and if the password is incorrect, it shuts down the computer. (Note- it will be placed in the start menu)
Here is the code:

@echo off
set /p _%1=Enter the password:
if _%1==_"yes" goto :a else goto :b

:a
echo Hello Riley
pause
exit cmd

:b
echo Incorrect user. Shutting down in 5 seconds...
timeout /t 3 /nobreak >nul
shutdown /s[/color]

Could someone please help me get this to work. You don't have to use the same code as I have written.

Thanks,
Rileyh



Wait, what? Who told you to do it like this? I've never seen this before...


Code: Select all

@echo off
set /p %var%=Enter the password:
if "%var%"=="yes" (
goto a
) else (
goto b
)

trebor68
Posts: 146
Joined: 01 Jul 2011 08:47

Re: Can Someone please help me- Huge Problems with batch Scr

#5 Post by trebor68 » 03 Sep 2011 01:42

nitt

I use here the variable "what" for the password.
For the command if left and right side the same value inclusive quotation marks. The result from command if must have a end of line.

If you don't have the command "goto :eof" before is coming the label ":a" than is also running that code.


Here my code:

Code: Select all

@echo off
echo.
set /p what=Enter the password:
if _"%what%"==_"yes" (goto :a) else goto :b
goto :eof
:a
echo.
echo You have input the correct password.
pause
goto :eof
:b
echo.
echo You don't have input the correct password.
pause

Post Reply