@echo off
:6
cls

echo 				* Digital SIGNER SERVICE 7.0.2 *
echo.
echo Select appropriate option as per your requirements :
echo.
echo Press 0 to EXIT.
echo Press 1 for System Information.
echo Press 2 for Java version running in system.
echo Press 3 to check for Digital Signer Service 7.0.2 running status.
echo Press 4 for All information.

echo.
set /p input=Enter Choice: 
echo.
if %input% == 1 (goto 1) else if %input% == 2 (goto 2) else if %input% == 3 (goto 3) else if %input% == 4 (goto 4) else if %input% == 0 (exit) else (goto 6)
:1
echo [1] Checking System Information:
systeminfo | find "OS Name"
systeminfo | find "OS Version"
systeminfo | find "System Type"
echo.
goto exit

:2
echo [2] Checking Java version running in system:
java -version
if %ERRORLEVEL% == 9009 (echo Java is not Installed. Kindly Installed Java version 1.8.0_151 or latest)
echo.
goto exit
:3
echo [3] Checking for port 55103........
echo.
for /f  "useback tokens=* delims=" %%# in (
    `wmic process where "CommandLine like '%%Digital Signer Service%%' and not CommandLine like '%%wmic%%' " get  ProcessId /Format:Value`
) do (
    for /f "tokens=* delims=" %%a in ("%%#") do set "%%a"
)

if [%processId%]==[] (goto check) else (echo "Digital Signer Service 7.0.2" is running on port 55103. Kindly stop the "Digital Signer Service" to install it again. &goto:exit)
echo.

:check
netstat -ano | findstr "55103" 
echo.
if %ERRORLEVEL% == 0 (echo Other process is running on port "55103". Kindly stop that process to install Digital Signer Service.) else (echo Port "55103" is free, continue to install Digital Signer Service.)
echo.

goto exit
:4
echo [A] Checking System Information:
systeminfo | find "OS Name"
systeminfo | find "OS Version"
systeminfo | find "System Type"
echo.
echo [B] Checking Java version running in system:
java -version
if %ERRORLEVEL% == 9009 (echo Java is not Installed. Kindly Installed Java version 1.8.0_151 or latest)
echo.
echo [C] Checking for port 55103........
echo.
for /f  "useback tokens=* delims=" %%# in (
    `wmic process where "CommandLine like '%%DscSignerService.jar%%' and not CommandLine like '%%wmic%%' " get  ProcessId /Format:Value`
) do (
    for /f "tokens=* delims=" %%a in ("%%#") do set "%%a"
)

if [%processId%]==[] (goto check) else (echo "Digital Signer Service" is running on port 55103. Kindly stop the "Digital Signer Service" to install it again. &goto:exit)
echo.
:0
exit
:exit
echo.
set /p input2=Press '1' to Continue to main menu or Press '0' for EXIT: 
echo.
if %input2% == 1 (goto 6) else if %input2% == 0 (exit) else (goto 6)
echo.
