@echo off

:: BatchGotAdmin
:-------------------------------------
REM  --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
    echo Requesting administrative privileges...
    goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
    echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

    "%temp%\getadmin.vbs"
    exit /B

:gotAdmin
    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
    pushd "%CD%"
    CD /D "%~dp0"
:--------------------------------------


SET MINIMUM_JAVA_VERSION=1.6

ECHO Detecting Java JRE %MINIMUM_JAVA_VERSION% compatible environment..

TestJavaWin.vbs %MINIMUM_JAVA_VERSION% 2> nil

IF ERRORLEVEL 2 GOTO INSTALLED
IF ERRORLEVEL 1 GOTO NOT_INSTALLED
IF ERRORLEVEL 0 GOTO ERROR

:NOT_INSTALLED
ECHO No compatible Java JRE version detected.
ECHO 32 bit Java Runtimes %MINIMUM_JAVA_VERSION% are required for agent installation
GOTO EXIT

:ERROR
ECHO Unable to detect available Java JRE version.
GOTO FORCE

:FORCE
CHOICE /M "Do you still want to continue?"
IF ERRORLEVEL 2 GOTO EXIT
IF ERRORLEVEL 1 GOTO RUN
GOTO EXIT

:INSTALLED
echo Compatible Java JRE version detected.

:RUN
set /p jre_path=<Result.txt
"%jre_path%" -cp .;classes.jar;classes12.zip TCInstallerMain -unInstall -Windows32.zip -InstallAgent-Nt.bat

:EXIT
PAUSE