48 lines
1.2 KiB
Batchfile
48 lines
1.2 KiB
Batchfile
@echo off
|
|
setlocal
|
|
|
|
set "SERVICE_NAME=ProcessMonitorService"
|
|
set "BASE_DIR=%~dp0"
|
|
set "EXE_PATH=%BASE_DIR%process-monitor.exe"
|
|
set "CONFIG_PATH=%BASE_DIR%process-monitor.conf"
|
|
|
|
if not exist "%EXE_PATH%" (
|
|
echo EXE not found: "%EXE_PATH%"
|
|
echo Build the project first.
|
|
exit /b 1
|
|
)
|
|
|
|
if not exist "%CONFIG_PATH%" (
|
|
echo Config not found: "%CONFIG_PATH%"
|
|
echo Expected config next to the EXE.
|
|
exit /b 1
|
|
)
|
|
|
|
sc query "%SERVICE_NAME%" >nul 2>&1
|
|
if %errorlevel% equ 0 (
|
|
echo Service "%SERVICE_NAME%" already exists. Removing old service...
|
|
sc stop "%SERVICE_NAME%" >nul 2>&1
|
|
sc delete "%SERVICE_NAME%"
|
|
timeout /t 2 /nobreak >nul
|
|
)
|
|
|
|
echo Installing service "%SERVICE_NAME%"...
|
|
sc create "%SERVICE_NAME%" binPath= "\"%EXE_PATH%\" \"%CONFIG_PATH%\"" start= auto
|
|
if errorlevel 1 (
|
|
echo Service installation failed.
|
|
exit /b 1
|
|
)
|
|
|
|
echo Setting service description...
|
|
sc description "%SERVICE_NAME%" "Process Monitor service"
|
|
|
|
echo Starting service "%SERVICE_NAME%"...
|
|
sc start "%SERVICE_NAME%"
|
|
if errorlevel 1 (
|
|
echo Service was installed, but start failed.
|
|
exit /b 1
|
|
)
|
|
|
|
echo Service "%SERVICE_NAME%" installed and started successfully.
|
|
exit /b 0
|