@echo off

:: Change directory to script location
pushd "%~dp0"

echo current directory: %CD%
SET path_to_installer=%CD%\LISS
SET path_to_monitorscv=%windir%\System32
SET monitorsvc_name=SSMonitorSvc

echo Path to installer: %path_to_installer%
echo Path to monitor svc: %path_to_monitorscv%

:: Check if service exist
%windir%\System32\sc.exe query %monitorsvc_name% > NUL
IF %ERRORLEVEL% EQU 1056 GOTO RUNNING
IF %ERRORLEVEL% EQU 1060 GOTO MISSING

::Stop any running service
:RUNNING
%windir%\System32\sc.exe stop %monitorsvc_name%

:: Copy monitor service
:MISSING
xcopy /I /Y SSMonitor.exe %path_to_monitorscv%\

%windir%\System32\pnputil.exe /add-driver "%path_to_installer%\LnvSST.inf" /install /subdirs
IF %ERRORLEVEL% NEQ 0 GOTO install_error ELSE goto install_complete

:install_error
:: delete the service

:install_complete
:: for other, specify here

popd