I wrote a batch script that asks for an input. The script closes whenever I type "2" and hit Enter. I checked the loop but it looks completely fine. At first I thought it was an error with some of the variables, but it wasn't. Also this script checks for admin privileges but with the permissions, it doesn't work. I could do all the commands successfully without loading it as admin privileges. By the way, please explain it in a way so that I can understand. I am 13 years old...
This is my code:
@echo off
chcp 65001 >nul
color 0A
title Slimy's Account Hacking Tool
set /p pass="Enter password: "
cls
if "%pass%" NEQ "slimy" exit
:menu
echo.
echo ***************
echo Menu
echo ***************
echo.
echo.
echo 1) List Users on Computer
echo 2) Create a New User
echo 3) Change a User's Password
echo 4) Delete a User Account
echo 5) Exit Slimy's Account Hacking Tool
echo.
set /p input="©️ "
if %input% EQU 1 (
title List Users
cls
net user
pause
cls
goto menu
)
if "%input%" EQU 2 (
call checkadmin
title Create a New User
cls
set /p user="USERNAME: "
set /p password="PASSWORD: "
net user %user% %password% /add
echo New user created with credentials:
echo %user% : %password%
pause
cls
goto menu
)
if %input% EQU 3 (
call checkadmin
title Change a USer's Password
cls
set /p username="TARGET USER: "
set /p passsword="NEW PASSWORD: "
net user %username% %password%
pause
cls
goto menu
)
if %input% EQU 4 (
cls
echo you have no morals and are messed up for trying to do this.
timeout /t 3
cls
goto menu
)
if %input% EQU 5 Exit
:checkadmin
net session >nul
if %errorlevel% NEQ 0 (
cls
echo.
echo Restart the script and run it as admin.
)
Notice that your condition for a “2” has quotes around the variable name:
if "%input%" EQU 2 (
The comparison then becomes: does "2"
equal 2
. The answer is no.
Using quotes is often a good idea, but you must also put quotes around the other side:
if "%input%" EQU "2" (
Notice also that your script ends with an exit
, which will terminate the cmd interpreter. If you only mean to terminate your script, you should instead use one of goto :EOF
or exit /b
.