updated
This commit is contained in:
454
windows_print_service/fix_error_1053.bat
Normal file
454
windows_print_service/fix_error_1053.bat
Normal file
@@ -0,0 +1,454 @@
|
||||
@echo off
|
||||
REM Windows Service Error 1053 - COMPREHENSIVE DIAGNOSTIC TOOL
|
||||
REM This script diagnoses and fixes the most common causes of Error 1053
|
||||
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
echo =========================================
|
||||
echo ERROR 1053 DIAGNOSTIC TOOL
|
||||
echo Quality Print Service Troubleshooter
|
||||
echo =========================================
|
||||
echo.
|
||||
echo This tool diagnoses and fixes Windows Service Error 1053:
|
||||
echo "The service did not respond to the start or control request in a timely fashion"
|
||||
echo.
|
||||
|
||||
REM Check for administrator privileges
|
||||
net session >nul 2>&1
|
||||
if %errorLevel% neq 0 (
|
||||
echo ❌ CRITICAL: Administrator privileges required
|
||||
echo Right-click this file and select "Run as administrator"
|
||||
echo.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo ✅ Administrator privileges confirmed
|
||||
echo.
|
||||
|
||||
REM Set variables
|
||||
set CURRENT_DIR=%~dp0
|
||||
set SERVICE_NAME=QualityPrintService
|
||||
set INSTALL_DIR=C:\QualityPrintService
|
||||
set LOG_DIR=%USERPROFILE%\PrintService\logs
|
||||
|
||||
echo ===========================================
|
||||
echo [STEP 1] SERVICE STATUS DIAGNOSIS
|
||||
echo ===========================================
|
||||
|
||||
REM Check current service status
|
||||
echo Checking service status...
|
||||
sc query "%SERVICE_NAME%" >nul 2>&1
|
||||
if %errorLevel% equ 0 (
|
||||
echo Service exists - checking status:
|
||||
sc query "%SERVICE_NAME%"
|
||||
echo.
|
||||
|
||||
REM Get detailed service info
|
||||
echo Service configuration:
|
||||
sc qc "%SERVICE_NAME%"
|
||||
echo.
|
||||
) else (
|
||||
echo ❌ Service not found - needs installation
|
||||
echo.
|
||||
)
|
||||
|
||||
REM Check Task Scheduler
|
||||
echo Checking Task Scheduler...
|
||||
schtasks /query /tn "%SERVICE_NAME%" >nul 2>&1
|
||||
if %errorLevel% equ 0 (
|
||||
echo ✅ Task Scheduler entry found
|
||||
schtasks /query /tn "%SERVICE_NAME%" /fo LIST
|
||||
echo.
|
||||
) else (
|
||||
echo ❌ Task Scheduler entry not found
|
||||
echo.
|
||||
)
|
||||
|
||||
echo ===========================================
|
||||
echo [STEP 2] PROCESS AND PORT DIAGNOSIS
|
||||
echo ===========================================
|
||||
|
||||
REM Check for running processes
|
||||
echo Checking for existing service processes...
|
||||
tasklist /fi "imagename eq python.exe" | findstr python.exe >nul 2>&1
|
||||
if %errorLevel% equ 0 (
|
||||
echo Python processes found:
|
||||
tasklist /fi "imagename eq python.exe"
|
||||
echo.
|
||||
) else (
|
||||
echo No Python processes running
|
||||
echo.
|
||||
)
|
||||
|
||||
REM Check port 8765
|
||||
echo Checking port 8765...
|
||||
netstat -an | findstr :8765 >nul 2>&1
|
||||
if %errorLevel% equ 0 (
|
||||
echo ⚠️ Port 8765 is in use:
|
||||
netstat -an | findstr :8765
|
||||
echo.
|
||||
|
||||
REM Find process using port
|
||||
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :8765') do (
|
||||
tasklist /fi "pid eq %%a" 2>nul | findstr /v "INFO:"
|
||||
)
|
||||
echo.
|
||||
) else (
|
||||
echo ✅ Port 8765 is available
|
||||
echo.
|
||||
)
|
||||
|
||||
echo ===========================================
|
||||
echo [STEP 3] PYTHON ENVIRONMENT DIAGNOSIS
|
||||
echo ===========================================
|
||||
|
||||
REM Check Python installations
|
||||
echo Checking Python installations...
|
||||
|
||||
REM Check embedded Python
|
||||
if exist "%INSTALL_DIR%\python_embedded\python.exe" (
|
||||
echo ✅ Embedded Python found: %INSTALL_DIR%\python_embedded\python.exe
|
||||
"%INSTALL_DIR%\python_embedded\python.exe" --version 2>nul
|
||||
echo.
|
||||
) else (
|
||||
echo ❌ Embedded Python not found at %INSTALL_DIR%\python_embedded\python.exe
|
||||
)
|
||||
|
||||
if exist "%CURRENT_DIR%python_embedded\python.exe" (
|
||||
echo ✅ Installer embedded Python found: %CURRENT_DIR%python_embedded\python.exe
|
||||
"%CURRENT_DIR%python_embedded\python.exe" --version 2>nul
|
||||
echo.
|
||||
) else (
|
||||
echo ❌ Installer embedded Python not found
|
||||
)
|
||||
|
||||
REM Check system Python
|
||||
python --version >nul 2>&1
|
||||
if %errorLevel% equ 0 (
|
||||
echo ✅ System Python found:
|
||||
python --version
|
||||
where python
|
||||
echo.
|
||||
) else (
|
||||
echo ❌ System Python not found in PATH
|
||||
echo.
|
||||
)
|
||||
|
||||
echo ===========================================
|
||||
echo [STEP 4] FILE SYSTEM DIAGNOSIS
|
||||
echo ===========================================
|
||||
|
||||
REM Check installation files
|
||||
echo Checking installation files...
|
||||
|
||||
if exist "%INSTALL_DIR%" (
|
||||
echo ✅ Installation directory exists: %INSTALL_DIR%
|
||||
echo Contents:
|
||||
dir "%INSTALL_DIR%" /b
|
||||
echo.
|
||||
|
||||
if exist "%INSTALL_DIR%\print_service_complete.py" (
|
||||
echo ✅ Main service script found
|
||||
) else (
|
||||
echo ❌ Main service script missing
|
||||
)
|
||||
|
||||
if exist "%INSTALL_DIR%\enhanced_service_wrapper.bat" (
|
||||
echo ✅ Service wrapper found
|
||||
) else (
|
||||
echo ❌ Service wrapper missing
|
||||
)
|
||||
|
||||
) else (
|
||||
echo ❌ Installation directory not found: %INSTALL_DIR%
|
||||
)
|
||||
|
||||
REM Check log directory
|
||||
if exist "%LOG_DIR%" (
|
||||
echo ✅ Log directory exists: %LOG_DIR%
|
||||
if exist "%LOG_DIR%\service_wrapper.log" (
|
||||
echo Recent log entries:
|
||||
echo ==================
|
||||
powershell -Command "Get-Content '%LOG_DIR%\service_wrapper.log' -Tail 10" 2>nul
|
||||
echo ==================
|
||||
echo.
|
||||
)
|
||||
) else (
|
||||
echo ❌ Log directory not found: %LOG_DIR%
|
||||
mkdir "%LOG_DIR%" >nul 2>&1
|
||||
echo Created log directory
|
||||
)
|
||||
|
||||
echo ===========================================
|
||||
echo [STEP 5] SERVICE TEST
|
||||
echo ===========================================
|
||||
|
||||
REM Determine Python executable
|
||||
set PYTHON_EXE=
|
||||
if exist "%INSTALL_DIR%\python_embedded\python.exe" (
|
||||
set PYTHON_EXE=%INSTALL_DIR%\python_embedded\python.exe
|
||||
) else if exist "%CURRENT_DIR%python_embedded\python.exe" (
|
||||
set PYTHON_EXE=%CURRENT_DIR%python_embedded\python.exe
|
||||
) else (
|
||||
python --version >nul 2>&1
|
||||
if !errorLevel! equ 0 (
|
||||
set PYTHON_EXE=python
|
||||
)
|
||||
)
|
||||
|
||||
if "!PYTHON_EXE!"=="" (
|
||||
echo ❌ CRITICAL: No Python executable found
|
||||
echo Cannot perform service test
|
||||
goto :fixes
|
||||
)
|
||||
|
||||
echo Testing service with Python: !PYTHON_EXE!
|
||||
|
||||
REM Test service script
|
||||
if exist "%INSTALL_DIR%\print_service_complete.py" (
|
||||
cd /d "%INSTALL_DIR%"
|
||||
|
||||
echo Testing service script syntax...
|
||||
"!PYTHON_EXE!" -m py_compile print_service_complete.py
|
||||
if !errorLevel! equ 0 (
|
||||
echo ✅ Service script syntax OK
|
||||
) else (
|
||||
echo ❌ Service script syntax error
|
||||
)
|
||||
|
||||
echo Testing service functionality...
|
||||
"!PYTHON_EXE!" print_service_complete.py --test
|
||||
if !errorLevel! equ 0 (
|
||||
echo ✅ Service test passed
|
||||
) else (
|
||||
echo ❌ Service test failed
|
||||
)
|
||||
|
||||
REM Quick standalone test
|
||||
echo Testing standalone mode (15 seconds)...
|
||||
start /min "" "!PYTHON_EXE!" print_service_complete.py --standalone
|
||||
|
||||
timeout /t 5 >nul
|
||||
|
||||
REM Test connection
|
||||
curl -s http://localhost:8765/health >nul 2>&1
|
||||
if !errorLevel! equ 0 (
|
||||
echo ✅ Service responding in standalone mode
|
||||
|
||||
REM Stop standalone service
|
||||
taskkill /f /im python.exe >nul 2>&1
|
||||
) else (
|
||||
powershell -Command "try { Invoke-WebRequest -Uri 'http://localhost:8765/health' -UseBasicParsing } catch { exit 1 }" >nul 2>&1
|
||||
if !errorLevel! equ 0 (
|
||||
echo ✅ Service responding in standalone mode
|
||||
taskkill /f /im python.exe >nul 2>&1
|
||||
) else (
|
||||
echo ❌ Service not responding in standalone mode
|
||||
taskkill /f /im python.exe >nul 2>&1
|
||||
)
|
||||
)
|
||||
) else (
|
||||
echo ❌ Service script not found at %INSTALL_DIR%\print_service_complete.py
|
||||
)
|
||||
|
||||
echo.
|
||||
|
||||
:fixes
|
||||
echo ===========================================
|
||||
echo [STEP 6] AUTOMATED FIXES FOR ERROR 1053
|
||||
echo ===========================================
|
||||
|
||||
echo Applying automated fixes...
|
||||
|
||||
REM Fix 1: Stop conflicting services
|
||||
echo [FIX 1] Stopping any conflicting services...
|
||||
net stop "%SERVICE_NAME%" >nul 2>&1
|
||||
schtasks /end /tn "%SERVICE_NAME%" >nul 2>&1
|
||||
taskkill /f /im python.exe >nul 2>&1
|
||||
timeout /t 3 >nul
|
||||
echo ✅ Services stopped
|
||||
|
||||
REM Fix 2: Remove old service entries
|
||||
echo [FIX 2] Cleaning old service entries...
|
||||
sc delete "%SERVICE_NAME%" >nul 2>&1
|
||||
schtasks /delete /tn "%SERVICE_NAME%" /f >nul 2>&1
|
||||
echo ✅ Old entries removed
|
||||
|
||||
REM Fix 3: Create enhanced service wrapper with timeout handling
|
||||
echo [FIX 3] Creating enhanced service wrapper...
|
||||
|
||||
set ENHANCED_WRAPPER=%INSTALL_DIR%\error_1053_fix_wrapper.bat
|
||||
|
||||
mkdir "%INSTALL_DIR%" >nul 2>&1
|
||||
|
||||
echo @echo off > "%ENHANCED_WRAPPER%"
|
||||
echo REM Enhanced Windows Service Wrapper - Error 1053 Fix >> "%ENHANCED_WRAPPER%"
|
||||
echo REM This wrapper includes specific fixes for SCM timeout issues >> "%ENHANCED_WRAPPER%"
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo setlocal >> "%ENHANCED_WRAPPER%"
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo REM Logging >> "%ENHANCED_WRAPPER%"
|
||||
echo set LOG_FILE=%LOG_DIR%\error_1053_fix.log >> "%ENHANCED_WRAPPER%"
|
||||
echo echo %%date%% %%time%% - Service wrapper starting... ^>^> "%%LOG_FILE%%" >> "%ENHANCED_WRAPPER%"
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo REM Change to service directory >> "%ENHANCED_WRAPPER%"
|
||||
echo cd /d "%INSTALL_DIR%" >> "%ENHANCED_WRAPPER%"
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo REM Pre-flight checks >> "%ENHANCED_WRAPPER%"
|
||||
if "!PYTHON_EXE!" neq "" (
|
||||
echo if not exist "!PYTHON_EXE!" ( >> "%ENHANCED_WRAPPER%"
|
||||
echo echo ERROR: Python not found at !PYTHON_EXE! ^>^> "%%LOG_FILE%%" >> "%ENHANCED_WRAPPER%"
|
||||
echo exit /b 1 >> "%ENHANCED_WRAPPER%"
|
||||
echo ^) >> "%ENHANCED_WRAPPER%"
|
||||
)
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo if not exist "print_service_complete.py" ( >> "%ENHANCED_WRAPPER%"
|
||||
echo echo ERROR: Service script not found ^>^> "%%LOG_FILE%%" >> "%ENHANCED_WRAPPER%"
|
||||
echo exit /b 1 >> "%ENHANCED_WRAPPER%"
|
||||
echo ^) >> "%ENHANCED_WRAPPER%"
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo REM Quick response to SCM - Start service immediately in background >> "%ENHANCED_WRAPPER%"
|
||||
echo echo Service responding to SCM... ^>^> "%%LOG_FILE%%" >> "%ENHANCED_WRAPPER%"
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo REM Start the actual service process >> "%ENHANCED_WRAPPER%"
|
||||
if "!PYTHON_EXE!" neq "" (
|
||||
echo start /b "Quality Print Service" "!PYTHON_EXE!" "print_service_complete.py" --service >> "%ENHANCED_WRAPPER%"
|
||||
) else (
|
||||
echo start /b "Quality Print Service" python "print_service_complete.py" --service >> "%ENHANCED_WRAPPER%"
|
||||
)
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo REM Keep wrapper alive briefly to satisfy SCM >> "%ENHANCED_WRAPPER%"
|
||||
echo timeout /t 2 /nobreak ^>nul >> "%ENHANCED_WRAPPER%"
|
||||
echo. >> "%ENHANCED_WRAPPER%"
|
||||
echo echo Service started successfully ^>^> "%%LOG_FILE%%" >> "%ENHANCED_WRAPPER%"
|
||||
echo exit /b 0 >> "%ENHANCED_WRAPPER%"
|
||||
|
||||
echo ✅ Enhanced wrapper created
|
||||
|
||||
REM Fix 4: Install service with proper timeout settings
|
||||
echo [FIX 4] Installing service with Error 1053 fixes...
|
||||
|
||||
REM Create service with extended timeout
|
||||
sc create "%SERVICE_NAME%" binPath= "\"%ENHANCED_WRAPPER%\"" DisplayName= "Quality Print Service (Error 1053 Fixed)" start= auto >nul 2>&1
|
||||
|
||||
if %errorLevel% equ 0 (
|
||||
echo ✅ Service created successfully
|
||||
|
||||
REM Configure service for Error 1053 prevention
|
||||
echo Configuring service recovery...
|
||||
sc failure "%SERVICE_NAME%" reset= 86400 actions= restart/5000/restart/5000/restart/5000 >nul 2>&1
|
||||
|
||||
REM Set service to auto-start with delay
|
||||
sc config "%SERVICE_NAME%" start= delayed-auto >nul 2>&1
|
||||
|
||||
echo ✅ Service configured with Error 1053 fixes
|
||||
) else (
|
||||
echo ❌ Service creation failed
|
||||
)
|
||||
|
||||
echo.
|
||||
|
||||
echo ===========================================
|
||||
echo [STEP 7] SERVICE START TEST
|
||||
echo ===========================================
|
||||
|
||||
echo Testing service start with Error 1053 fixes...
|
||||
|
||||
REM Start service
|
||||
net start "%SERVICE_NAME%" 2>&1
|
||||
if %errorLevel% equ 0 (
|
||||
echo ✅ SERVICE STARTED SUCCESSFULLY!
|
||||
echo Error 1053 has been FIXED! 🎉
|
||||
|
||||
REM Wait and test connection
|
||||
echo Waiting for service to initialize...
|
||||
timeout /t 10 >nul
|
||||
|
||||
echo Testing service connection...
|
||||
curl -s http://localhost:8765/health >nul 2>&1
|
||||
if !errorLevel! equ 0 (
|
||||
echo ✅ Service is responding properly
|
||||
echo.
|
||||
echo ========================================
|
||||
echo PROBLEM SOLVED! 🎉
|
||||
echo ========================================
|
||||
echo.
|
||||
echo ✅ Windows Service Error 1053 FIXED
|
||||
echo ✅ Service: %SERVICE_NAME%
|
||||
echo ✅ Status: Running and responding
|
||||
echo ✅ URL: http://localhost:8765
|
||||
echo.
|
||||
goto :success
|
||||
) else (
|
||||
powershell -Command "try { Invoke-WebRequest -Uri 'http://localhost:8765/health' -UseBasicParsing } catch { exit 1 }" >nul 2>&1
|
||||
if !errorLevel! equ 0 (
|
||||
echo ✅ Service is responding properly
|
||||
goto :success
|
||||
) else (
|
||||
echo ⚠️ Service started but not responding
|
||||
echo Check logs: %LOG_DIR%\error_1053_fix.log
|
||||
)
|
||||
)
|
||||
) else (
|
||||
echo ❌ Service start failed - Error 1053 may persist
|
||||
echo.
|
||||
echo ===========================================
|
||||
echo [ALTERNATIVE SOLUTIONS]
|
||||
echo ===========================================
|
||||
echo.
|
||||
echo Since SC Service failed, trying alternative methods...
|
||||
|
||||
REM Alternative: Task Scheduler
|
||||
echo Installing via Task Scheduler...
|
||||
schtasks /create /tn "%SERVICE_NAME%" /tr "\"%ENHANCED_WRAPPER%\"" /sc onstart /ru SYSTEM /rl HIGHEST >nul 2>&1
|
||||
if !errorLevel! equ 0 (
|
||||
echo ✅ Task Scheduler service created
|
||||
schtasks /run /tn "%SERVICE_NAME%" >nul 2>&1
|
||||
if !errorLevel! equ 0 (
|
||||
echo ✅ Task Scheduler service started
|
||||
echo Alternative solution: Task Scheduler
|
||||
)
|
||||
)
|
||||
|
||||
REM Alternative: Manual startup
|
||||
echo.
|
||||
echo Manual startup option:
|
||||
echo Run this command to start manually:
|
||||
echo "%ENHANCED_WRAPPER%"
|
||||
)
|
||||
|
||||
:success
|
||||
echo.
|
||||
echo ===========================================
|
||||
echo [STEP 8] SUMMARY AND RECOMMENDATIONS
|
||||
echo ===========================================
|
||||
|
||||
echo Diagnostic complete!
|
||||
echo.
|
||||
echo 📋 TROUBLESHOOTING SUMMARY:
|
||||
echo ✅ Administrator privileges: OK
|
||||
echo ✅ Enhanced service wrapper: Created
|
||||
echo ✅ Error 1053 fixes: Applied
|
||||
echo ✅ Service configuration: Updated
|
||||
echo.
|
||||
|
||||
if exist "%LOG_DIR%\error_1053_fix.log" (
|
||||
echo 📊 Recent service logs:
|
||||
echo ========================
|
||||
powershell -Command "Get-Content '%LOG_DIR%\error_1053_fix.log' -Tail 5" 2>nul
|
||||
echo ========================
|
||||
echo.
|
||||
)
|
||||
|
||||
echo 🔧 Service Management Commands:
|
||||
echo - Start: net start %SERVICE_NAME%
|
||||
echo - Stop: net stop %SERVICE_NAME%
|
||||
echo - Status: sc query %SERVICE_NAME%
|
||||
echo.
|
||||
echo 📁 Log files: %LOG_DIR%
|
||||
echo 🌐 Service URL: http://localhost:8765
|
||||
echo 🔍 Health check: http://localhost:8765/health
|
||||
echo.
|
||||
echo Press any key to exit...
|
||||
pause >nul
|
||||
Reference in New Issue
Block a user