149 lines
4.4 KiB
Batchfile
149 lines
4.4 KiB
Batchfile
@echo off
|
|
REM Quality Label Printing Service - Simple Native Installation
|
|
REM This version uses the most basic approach to avoid command line parsing issues
|
|
|
|
echo ================================================
|
|
echo Quality Label Printing 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=QualityLabelPrinting
|
|
set SERVICE_DIR=C:\Program Files\QualityLabelPrinting\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 Label Printing 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 |