createed a good service

This commit is contained in:
2025-09-22 19:51:37 +03:00
parent ed8ebd9e76
commit dd1772222d
3 changed files with 206 additions and 15 deletions

View File

@@ -38,33 +38,71 @@ echo.
echo Copying service files...
copy /Y "%~dp0print_service.ps1" "%SERVICE_DIR%\print_service.ps1"
if %errorLevel% neq 0 (
echo ❌ Error copying service files!
echo ❌ Error copying PowerShell service file!
echo Make sure print_service.ps1 is in the same directory as this installer.
pause
exit /b 1
)
copy /Y "%~dp0service_wrapper.bat" "%SERVICE_DIR%\service_wrapper.bat"
if %errorLevel% neq 0 (
echo ❌ Error copying service wrapper file!
echo Make sure service_wrapper.bat is in the same directory as this installer.
pause
exit /b 1
)
echo ✅ Service files copied successfully
echo.
echo Checking for existing service...
sc query "%SERVICE_NAME%" >nul 2>&1
if not errorlevel 1 (
echo ⚠️ Service already exists. Removing existing service first...
sc stop "%SERVICE_NAME%" >nul 2>&1
sc delete "%SERVICE_NAME%" >nul 2>&1
timeout /t 2 /nobreak >nul
)
echo.
echo Installing Windows Service...
REM Create the Windows service
sc create "%SERVICE_NAME%" ^
binpath="powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File \"%SERVICE_DIR%\print_service.ps1\"" ^
start=auto ^
displayname="Quality Recticel Print Service" ^
description="Local HTTP service for silent PDF printing from Quality Recticel web application"
REM Create the Windows service with corrected syntax
echo Creating service: %SERVICE_NAME%
echo Binary path: %SERVICE_DIR%\service_wrapper.bat
echo.
sc create %SERVICE_NAME% binPath="%SERVICE_DIR%\service_wrapper.bat" start=auto DisplayName="Quality Recticel Print Service"
REM Check if service creation succeeded
sc query %SERVICE_NAME% >nul 2>&1
if errorlevel 1 (
echoFailed to create Windows service
echo.
echo Troubleshooting:
echo 1. Make sure you're running as Administrator
echo 2. Check if the service already exists: sc query %SERVICE_NAME%
echo 3. If it exists, delete it first: sc delete %SERVICE_NAME%
pause
exit /b 1
echoService creation verification failed
goto :service_error
)
echo ✅ Service created successfully
REM Set description (may fail on older Windows, that's OK)
sc description %SERVICE_NAME% "Local HTTP service for silent PDF printing from Quality Recticel web application" >nul 2>&1
goto :service_created
:service_error
echo ❌ Failed to create Windows service
echo.
echo Troubleshooting:
echo 1. Make sure you're running as Administrator
echo 2. Check if the service already exists: sc query %SERVICE_NAME%
echo 3. If it exists, delete it first: sc delete %SERVICE_NAME%
echo.
echo Manual commands to try:
echo sc create %SERVICE_NAME% binPath="\"%SERVICE_DIR%\service_wrapper.bat\""
echo sc config %SERVICE_NAME% start=auto
echo.
pause
exit /b 1
:service_created
echo ✅ Windows service created successfully
echo.