Batch script closing CMD with no apparent error

I have a batch script made in notepad. It works, but there’s 2 segments of the script that make it close the cmd, and I just can’t understand why.

Here’s the script

@echo off
setlocal enabledelayedexpansion
title JC-ServerManager v1.0.0

set "database=admins.txt"
set "try_file=tryvalue.txt"

:: Leitura do valor de 'try' a partir do ficheiro 'tryvalue.txt'
if exist "%try_file%" (
    set /p try=<"%try_file%"
) else (
    set /a try=3
    echo 3 >"%try_file%"
)

:START
cls
powershell -Command Write-Host -NoNewLine -ForegroundColor Yellow " ----------------------------- Server Manager v1.0.0 ----------------------------- " & echo.

:: Verifica se o utilizador está bloqueado
if "%try%" equ "blocked" (
    powershell -Command Write-Host -NoNewLine -ForegroundColor Red "Your account is blocked. Please contact server admin to recover your permission." & echo.
    echo Contact:
    echo ...Email: [email protected]
    echo ...Phone: +351 967 041 910
    echo. & pause
    exit /b
)

echo. & echo LOGIN: & echo.

set /p "user=...User: "
set /p "password=...Password: "

echo. & echo Checking data...

set "authenticated=false"
set "user_found=false"
set "user_status=OK"
set "user_permission=DEFAULT"

:: Verifica se o nome de usuário e a senha não estão vazios
if "%user%"=="" (
    powershell -Command Write-Host -NoNewLine -ForegroundColor Red "User cannot be empty" & echo.
    echo. & pause
    goto :START
)

if "%password%"=="" (
    powershell -Command Write-Host -NoNewLine -ForegroundColor Red "Password cannot be empty" & echo.
    echo. & pause
    goto :START
)

:: Verifica credenciais do usuário, status e permissões
for /f "tokens=1,2,3,4,5 delims=:" %%a in ('type "%database%"') do (
    if "%user%" equ "%%b" (
        set "user_found=true"
        if "%password%" equ "%%c" (
            if "%%d" equ "BLOCKED" (
                powershell -Command Write-Host -NoNewLine -ForegroundColor Red "Your account is blocked. Please contact server admin to recover your permission." & echo.
                echo Contact:
                echo ...Email: [email protected]
                echo ...Phone: +351 967 041 910
                echo. & pause
                exit /b
            ) else (
                set "authenticated=true"
                set "user_permission=%%e"
                goto :AUTHENTICATED
            )
        )
    )
)

:: Verifica se o usuário foi encontrado mas a senha estava incorreta
if "!user_found!"=="true" (
    powershell -Command Write-Host -NoNewLine -ForegroundColor Red "Incorrect password" & echo.
    set /a try-=1
    if !try! equ 0 (
        :: Atualiza o status do usuário para BLOCKED
        (for /f "tokens=1,2,3,4,5 delims=:" %%a in ('type "%database%"') do (
            if "%%b" equ "%user%" (
                echo %%a:%%b:%%c:BLOCKED:%%e
            ) else (
                echo %%a:%%b:%%c:%%d:%%e
            )
        )) > "%database%"
        echo blocked >"%try_file%"
    ) else (
        echo !try! >"%try_file%"
    )
    echo. & pause
    goto :START
)

:: Verifica se as credenciais estavam incorretas e o usuário não foi encontrado
if "!authenticated!"=="false" (
    powershell -Command Write-Host -NoNewLine -ForegroundColor Red "User not found or incorrect password" & echo.
    echo. & pause
    goto :START
)

:AUTHENTICATED
powershell -Command Write-Host -NoNewLine -ForegroundColor Green "You have been successfully authenticated!" & echo. & pause
:: Reset do contador de tentativas após autenticação bem-sucedida
set /a try=3
echo 3 >"%try_file%"
goto :OPTIONS

:OPTIONS
cls
powershell -Command Write-Host -NoNewLine -ForegroundColor Yellow " ----------------------------- Server Manager v1.0.0 ----------------------------- " & echo.

echo. & echo OPTIONS:
echo.
powershell -Command Write-Host -NoNewLine -ForegroundColor White "[1] Profile" & echo.
powershell -Command Write-Host -NoNewLine -ForegroundColor White "[2] Server Stats" & echo.
powershell -Command Write-Host -NoNewLine -ForegroundColor White "[3] Connect to the server" & echo.

:: Exibe a opção de administrador apenas se a permissão for ADMIN
if "%user_permission%"=="ADMIN" (
    powershell -Command Write-Host -NoNewLine -ForegroundColor White "[4] Admin - Manager" & echo.
)

echo. & echo.
powershell -Command Write-Host -NoNewLine -ForegroundColor White "[9] Logout" & echo.
powershell -Command Write-Host -NoNewLine -ForegroundColor White "[0] Exit" & echo.
echo.
set /p "aws1=^"

if "%aws1%"=="1" goto :PROFILE
if "%aws1%"=="2" goto :STATS
if "%aws1%"=="3" goto :CONNECT

:: Verifica a permissão para a opção admin
if "%aws1%"=="4" if "%user_permission%"=="ADMIN" goto :ADMIN
if "%aws1%"=="9" goto :START
if "%aws1%"=="0" (
    exit /b
) else goto :AWSERROR

:PROFILE
cls
echo profile
pause
goto :OPTIONS

:STATS
cls
echo stats
pause
goto :OPTIONS

:CONNECT
cls
echo connect
pause
goto :OPTIONS

:ADMIN
cls
echo admin
pause
goto :OPTIONS

:AWSERROR
powershell -Command Write-Host -NoNewLine -ForegroundColor Red "Error: Invalid option. Please choose one from the option menu." & echo. & pause
cls
goto :OPTIONS

endlocal
exit /b

The 2 segments causing problems to the script are:

:: Verifica se o usuário foi encontrado mas a senha estava incorreta
if "!user_found!"=="true" (
    powershell -Command Write-Host -NoNewLine -ForegroundColor Red "Incorrect password" & echo.
    set /a try-=1
    if !try! equ 0 (
        :: Atualiza o status do usuário para BLOCKED
        (for /f "tokens=1,2,3,4,5 delims=:" %%a in ('type "%database%"') do (
            if "%%b" equ "%user%" (
                echo %%a:%%b:%%c:BLOCKED:%%e
            ) else (
                echo %%a:%%b:%%c:%%d:%%e
            )
        )) > "%database%"
        echo blocked >"%try_file%"
    ) else (
        echo !try! >"%try_file%"
    )
    echo. & pause
    goto :START
)

and

:: Verifica se as credenciais estavam incorretas e o usuário não foi encontrado
if "!authenticated!"=="false" (
    powershell -Command Write-Host -NoNewLine -ForegroundColor Red "User not found or incorrect password" & echo.
    echo. & pause
    goto :START
)

They should show an error message, just like every other option, but instead, if the user or password are wrong, the cmd just closes. If they’re empty or correct it works, even the blocked status accounts works. The only issue is with the incorrect credentials.

Btw I am using 2 .txt files to run the script:

tryvalue.txt

3

and admins.txt

1:user1:password1:OK:ADMIN
2:user2:password2:OK:DEFAULT
3:user3:password3:BLOCKED:DEFAULT

I’ve tried to use an older version of the script and it works, but not with all the options I want it to be able to do.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật