@echo off

echo INFO: Netprobe RMS update script for Windows x64 version 0.9.3
echo INFO: For ITRS Geneos (http://www.itrsgroup.com/)
echo INFO: Written by Howard Lee

if "%1"=="" goto usage
goto check1

:usage
echo.
echo Usage: %0 geneos-netprobe-version.windows-x64.setup.exe ["Target Dir"]
goto exit

:check1
echo INFO: Computer name: %COMPUTERNAME%
echo INFO: Running from: %CD%

set NETPROBEDIR="%~2"
if "%~2"=="" set NETPROBEDIR="%cd%"
for /f "delims=" %%j in ('dir NetprobeNT*.exe /b') do @set NETPROBEINST=%%~nj
for /f "delims=" %%k in ('na_getenv.exe %NETPROBEINST% NET_PORT') do @set NETPROBEPORT=%%k

if %NETPROBEPORT% GEQ 1 goto check2
goto failed

:check2
if %NETPROBEPORT% LEQ 65536 goto passed
goto failed

:passed
echo INFO: Netprobe directory: %NETPROBEDIR%
echo INFO: Netprobe service name: %NETPROBEINST%
echo INFO: Netprobe port: %NETPROBEPORT%
echo INFO: The current Netprobe will be uninstalled, and the installation will proceed.
echo set NETPROBEDIR=%NETPROBEDIR%> rms-env-x64.bat
echo set NETPROBEINST=%NETPROBEINST%>> rms-env-x64.bat
echo set NETPROBEPORT=%NETPROBEPORT%>> rms-env-x64.bat
goto exit

:failed
echo INFO: Netprobe directory: %NETPROBEDIR%
echo INFO: Netprobe service name: %NETPROBEINST%
echo INFO: Netprobe port: %NETPROBEPORT%
echo ERROR: Unable to detect the current Netprobe service, installation will not continue.
del %1
goto exit

:exit
