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
Can Someone please help me- Huge Problems with batch Script!
Moderator: DosItHelp
Re: Can Someone please help me- Huge Problems with batch Scr
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.
If you dont know, make a pause statement between every line and count until you have found it.
Re: Can Someone please help me- Huge Problems with batch Scr
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.
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.
Re: Can Someone please help me- Huge Problems with batch Scr
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
)
Re: Can Someone please help me- Huge Problems with batch Scr
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:
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