@echo off REM Quality Recticel Print Service - Windows Native Installation REM This script creates a lightweight PowerShell-based print service 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 install_native_service.bat 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... copy /Y "%~dp0print_service.ps1" "%SERVICE_DIR%\print_service.ps1" if %errorLevel% neq 0 ( 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 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 ❌ 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. echo Configuring service recovery options... sc failure "%SERVICE_NAME%" reset=30 actions=restart/5000/restart/5000/restart/5000 echo. echo Starting the service... sc start "%SERVICE_NAME%" if errorlevel 1 ( echo ⚠️ Service created but failed to start automatically echo You can start it manually from Services (services.msc) echo Or run: sc start %SERVICE_NAME% ) else ( echo ✅ Service started successfully ) echo. echo Checking service status... sc query "%SERVICE_NAME%" | find "RUNNING" >nul if errorlevel 1 ( echo ⚠️ Service is not running. Check the log file for details. ) else ( echo ✅ Service is running properly ) echo. echo ================================================ echo Installation Complete! 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 Testing endpoints: echo Health Check: http://localhost:8765/health echo Printers: http://localhost:8765/printers echo Print PDF: POST to http://localhost:8765/print/pdf echo. echo To manage the service: echo Start: sc start %SERVICE_NAME% echo Stop: sc stop %SERVICE_NAME% echo Delete: sc delete %SERVICE_NAME% echo Status: sc query %SERVICE_NAME% echo Restart: sc stop %SERVICE_NAME% ^&^& sc start %SERVICE_NAME% echo. echo Next Steps: echo 1. Install the Chrome extension from the Quality Recticel system echo 2. Test printing from the web application echo 3. Check the log file if there are any issues echo. pause