From 3d7ff9aac09db93e52f4c53f079d67ee9e0ea9f1 Mon Sep 17 00:00:00 2001 From: Gregory Lirent Date: Thu, 3 Jul 2025 21:56:20 +0300 Subject: [PATCH] v0.1.5 Fixes --- .gitignore | 2 +- Program.cs | 1 + install.bat | 103 +++++++++++++++++++++++++++++++++++++++++++++++ webmr-api.csproj | 1 + 4 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 install.bat diff --git a/.gitignore b/.gitignore index 06879a2..9778ec1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/.vs/ +/.*/ /bin/ /obj/ /Properties/ diff --git a/Program.cs b/Program.cs index a9aad57..508a88f 100644 --- a/Program.cs +++ b/Program.cs @@ -9,6 +9,7 @@ using WebmrAPI.Services; var builder = WebApplication.CreateBuilder(args); +builder.Services.AddWindowsService(); builder.Services.Configure(builder.Configuration); builder.Services.AddLogging(config => { diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..5053830 --- /dev/null +++ b/install.bat @@ -0,0 +1,103 @@ +@echo off +REM install.bat - Script for installing/uninstalling ProcessMonitoringService on the target machine. +REM +REM --- Run as Administrator --- +REM This script must be run with administrator privileges to create and manage Windows services. +REM If the script is not run as administrator, it will attempt to restart itself with elevated privileges. + +setlocal + +REM Check if the script is running with administrator privileges +NET SESSION >NUL 2>&1 +IF %ERRORLEVEL% NEQ 0 ( + echo. + echo This script must be run with administrator privileges. + echo Attempting to restart with elevated privileges... + echo. + powershell -Command "Start-Process -FilePath '%~dpnx0' -Verb RunAs" + exit /b +) + +echo Script is running with administrator privileges. + +REM --- Service Settings --- +SET "SERVICE_NAME=ProcessMonitoringService" +SET "SERVICE_DISPLAY_NAME=Process Monitoring Service" +SET "SERVICE_DESCRIPTION=A service for detailed monitoring processes and memory regions." + +REM The service executable is in the same directory as install.bat +SET "SERVICE_EXE_PATH=%~dp0%SERVICE_NAME%.exe" + +REM --- Options --- +SET "ACTION=%1" +IF "%ACTION%"=="" SET "ACTION=install" + +echo. +echo --- Executing action: %ACTION% --- +echo. + +IF /I "%ACTION%"=="install" GOTO :INSTALL +IF /I "%ACTION%"=="uninstall" GOTO :UNINSTALL + +echo Unknown action: "%ACTION%". +echo Usage: +echo %~nx0 install - Creates and starts the service. +echo %~nx0 uninstall - Stops, deletes the service. After this, manually delete the folder. +GOTO :END + +:INSTALL +echo --- Step 1: Create Windows Service --- +echo Creating service "%SERVICE_DISPLAY_NAME%" (%SERVICE_NAME%)... +IF NOT EXIST "%SERVICE_EXE_PATH%" ( + echo ERROR: Service executable not found: "%SERVICE_EXE_PATH%". + GOTO :END +) + +sc create "%SERVICE_NAME%" binPath="\"%SERVICE_EXE_PATH%\"" DisplayName="%SERVICE_DISPLAY_NAME%" start= auto +IF %ERRORLEVEL% NEQ 0 ( + echo ERROR: Failed to create service. A service with this name might already exist or you lack permissions. + GOTO :END +) +echo Service created successfully. + +echo --- Step 2: Set Service Description --- +sc description "%SERVICE_NAME%" "%SERVICE_DESCRIPTION%" +IF %ERRORLEVEL% NEQ 0 ( + echo WARNING: Failed to set service description. +) + +echo --- Step 3: Start Service --- +echo Starting service "%SERVICE_NAME%"... +sc start "%SERVICE_NAME%" +IF %ERRORLEVEL% NEQ 0 ( + echo ERROR: Failed to start service. Check service logs. + GOTO :END +) +echo Service started successfully. +GOTO :END + +:UNINSTALL +echo --- Stop Service --- +echo Stopping service "%SERVICE_NAME%"... +sc stop "%SERVICE_NAME%" +IF %ERRORLEVEL% NEQ 0 ( + echo WARNING: Failed to stop service. The service might not be running or you lack permissions. +) + +echo --- Delete Windows Service --- +echo Deleting service "%SERVICE_NAME%"... +sc delete "%SERVICE_NAME%" +IF %ERRORLEVEL% NEQ 0 ( + echo ERROR: Failed to delete service. The service might not exist or you lack permissions. + GOTO :END +) +echo Service deleted successfully. + +echo For complete removal, please manually delete the folder from which install.bat was run. +GOTO :END + +:END +echo. +echo Operation completed. +endlocal +pause diff --git a/webmr-api.csproj b/webmr-api.csproj index 038aea7..aca6ed7 100644 --- a/webmr-api.csproj +++ b/webmr-api.csproj @@ -26,5 +26,6 @@ +