From dd1772222db3e66ca8e8230d41dbc36d43952c7d Mon Sep 17 00:00:00 2001 From: Scheianu Ionut Date: Mon, 22 Sep 2025 19:51:37 +0300 Subject: [PATCH] createed a good service --- .../install_native_service.bat | 68 ++++++-- windows_print_service/install_simple.bat | 149 ++++++++++++++++++ windows_print_service/service_wrapper.bat | 4 + 3 files changed, 206 insertions(+), 15 deletions(-) create mode 100644 windows_print_service/install_simple.bat create mode 100644 windows_print_service/service_wrapper.bat diff --git a/windows_print_service/install_native_service.bat b/windows_print_service/install_native_service.bat index 8b8167b..48186a6 100644 --- a/windows_print_service/install_native_service.bat +++ b/windows_print_service/install_native_service.bat @@ -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 ( - 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% - pause - exit /b 1 + echo ❌ Service 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. diff --git a/windows_print_service/install_simple.bat b/windows_print_service/install_simple.bat new file mode 100644 index 0000000..a0bc800 --- /dev/null +++ b/windows_print_service/install_simple.bat @@ -0,0 +1,149 @@ +@echo off +REM Quality Recticel Print Service - Simple Native Installation +REM This version uses the most basic approach to avoid command line parsing issues + +echo ================================================ +echo Quality Recticel Print Service - Native Windows +echo ================================================ +echo. + +REM Check if running as administrator +net session >nul 2>&1 +if %errorLevel% NEQ 0 ( + echo ERROR: This script must be run as Administrator! + echo Right-click on this file and select "Run as administrator" + pause + exit /b 1 +) + +echo ✅ Administrator privileges confirmed +echo. + +REM Service configuration +set SERVICE_NAME=QualityRecticelPrintService +set SERVICE_DIR=C:\Program Files\QualityRecticel\PrintService + +echo Creating service directory: %SERVICE_DIR% +if not exist "%SERVICE_DIR%" ( + mkdir "%SERVICE_DIR%" 2>nul + if errorlevel 1 ( + echo ❌ Failed to create service directory + pause + exit /b 1 + ) +) +echo ✅ Service directory created + +echo. +echo Copying service files... + +REM Copy PowerShell service file +if not exist "%~dp0print_service.ps1" ( + echo ❌ print_service.ps1 not found in installer directory + echo Make sure all service files are in the same folder as this installer + pause + exit /b 1 +) +copy /Y "%~dp0print_service.ps1" "%SERVICE_DIR%\print_service.ps1" +echo ✅ PowerShell service copied + +REM Create a simple service executable using PowerShell +echo Creating service executable... +echo @echo off > "%SERVICE_DIR%\start_service.bat" +echo cd /d "%SERVICE_DIR%" >> "%SERVICE_DIR%\start_service.bat" +echo powershell.exe -ExecutionPolicy Bypass -NoProfile -File "print_service.ps1" >> "%SERVICE_DIR%\start_service.bat" + +echo ✅ Service files prepared + +echo. +echo Removing any existing service... +sc query "%SERVICE_NAME%" >nul 2>&1 +if not errorlevel 1 ( + echo Found existing service, removing it... + sc stop "%SERVICE_NAME%" >nul 2>&1 + timeout /t 2 /nobreak >nul + sc delete "%SERVICE_NAME%" >nul 2>&1 + timeout /t 2 /nobreak >nul + echo ✅ Existing service removed +) + +echo. +echo Installing Windows Service... +echo Command: sc create %SERVICE_NAME% binPath="%SERVICE_DIR%\start_service.bat" +echo. + +REM Create service with absolute minimal parameters +sc create "%SERVICE_NAME%" binPath="%SERVICE_DIR%\start_service.bat" + +if errorlevel 1 ( + echo. + echo ❌ Service creation failed. Let's try troubleshooting... + echo. + echo Checking sc command availability: + sc /? + echo. + echo Current user context: + whoami + echo. + echo Trying alternative service creation method: + sc create TestService binPath="cmd.exe /c echo test" + sc delete TestService >nul 2>&1 + echo. + echo If the above worked, the issue is with our service path. + echo If it failed, there's a deeper Windows service issue. + echo. + pause + exit /b 1 +) + +echo ✅ Service created successfully + +echo. +echo Configuring service startup... +sc config "%SERVICE_NAME%" start=auto +sc config "%SERVICE_NAME%" DisplayName="Quality Recticel Print Service" + +echo. +echo Starting the service... +sc start "%SERVICE_NAME%" + +if errorlevel 1 ( + echo ⚠️ Service created but failed to start + echo This is normal - let's check what happened... + echo. + echo Service status: + sc query "%SERVICE_NAME%" + echo. + echo You can start it manually later with: sc start %SERVICE_NAME% +) else ( + echo ✅ Service started successfully +) + +echo. +echo Testing service connectivity... +timeout /t 3 /nobreak >nul +powershell -Command "try { $response = Invoke-WebRequest -Uri 'http://localhost:8765/health' -TimeoutSec 5; Write-Host '✅ Service is responding: ' $response.StatusCode } catch { Write-Host '⚠️ Service not responding yet (this is normal, may need a few seconds)' }" + +echo. +echo ================================================ +echo Installation Summary +echo ================================================ +echo. +echo Service Name: %SERVICE_NAME% +echo Service Directory: %SERVICE_DIR% +echo Service URL: http://localhost:8765 +echo Log File: %SERVICE_DIR%\print_service.log +echo. +echo Service Management Commands: +echo Start: sc start %SERVICE_NAME% +echo Stop: sc stop %SERVICE_NAME% +echo Status: sc query %SERVICE_NAME% +echo Delete: sc delete %SERVICE_NAME% +echo. +echo Next Steps: +echo 1. Wait 10-30 seconds for service to fully start +echo 2. Test: Open http://localhost:8765/health in your browser +echo 3. Install Chrome extension if needed +echo 4. Test printing from Quality Recticel web application +echo. +pause \ No newline at end of file diff --git a/windows_print_service/service_wrapper.bat b/windows_print_service/service_wrapper.bat new file mode 100644 index 0000000..961ac93 --- /dev/null +++ b/windows_print_service/service_wrapper.bat @@ -0,0 +1,4 @@ +@echo off +REM Service wrapper for PowerShell print service +cd /d "C:\Program Files\QualityRecticel\PrintService" +powershell.exe -ExecutionPolicy Bypass -NoProfile -WindowStyle Hidden -File "print_service.ps1" \ No newline at end of file