@echo off
setlocal EnableExtensions

title NetTicket RDP Setup
color 0F

set "SCRIPT=%~dp0install-rdp-thumbprints-for-netticket.ps1"

echo.
echo ============================================================
echo  NetTicket RDP Setup
echo ============================================================
echo.

if not exist "%SCRIPT%" (
    color 0C

    echo ERROR:
    echo The required PowerShell file was not found.
    echo.
    echo Expected file:
    echo %SCRIPT%
    echo.
    echo Download both files to the same folder:
    echo.
    echo   Start-NetTicket-RDP.cmd
    echo   install-rdp-thumbprints-for-netticket.ps1
    echo.
    echo Do not rename either file.
    echo.

    pause
    exit /b 1
)

echo Choose an option:
echo.
echo   1. Install or show current status
echo   2. Uninstall NetTicket RDP thumbprints
echo   3. Exit
echo.

choice /C 123 /N /M "Enter 1, 2, or 3: "

if errorlevel 3 goto :EXIT
if errorlevel 2 goto :UNINSTALL
if errorlevel 1 goto :INSTALL

:INSTALL
cls

echo.
echo ============================================================
echo  Install or show NetTicket RDP status
echo ============================================================
echo.
echo Starting PowerShell...
echo.

powershell.exe ^
    -NoProfile ^
    -ExecutionPolicy Bypass ^
    -Command "Unblock-File -LiteralPath '%SCRIPT%' -ErrorAction SilentlyContinue; & '%SCRIPT%'"

set "EXITCODE=%ERRORLEVEL%"

echo.
echo ============================================================

if "%EXITCODE%"=="0" (
    color 0A
    echo  The operation completed successfully.
) else (
    color 0C
    echo  The operation returned an error.
    echo  Exit code: %EXITCODE%
)

echo ============================================================
echo.
echo Review the information above.
echo Press any key to close this window.
echo.

pause >nul
exit /b %EXITCODE%

:UNINSTALL
cls

echo.
echo ============================================================
echo  Uninstall NetTicket RDP thumbprints
echo ============================================================
echo.
echo Starting PowerShell...
echo.

powershell.exe ^
    -NoProfile ^
    -ExecutionPolicy Bypass ^
    -Command "Unblock-File -LiteralPath '%SCRIPT%' -ErrorAction SilentlyContinue; & '%SCRIPT%' -Uninstall"

set "EXITCODE=%ERRORLEVEL%"

echo.
echo ============================================================

if "%EXITCODE%"=="0" (
    color 0A
    echo  The operation completed successfully.
) else (
    color 0C
    echo  The operation returned an error.
    echo  Exit code: %EXITCODE%
)

echo ============================================================
echo.
echo Review the information above.
echo Press any key to close this window.
echo.

pause >nul
exit /b %EXITCODE%

:EXIT
echo.
echo No changes were made.
timeout /T 2 /NOBREAK >nul
exit /b 0
