# Gateway Service Fix Script # Requires Administrator privileges Write-Host "=== OpenClaw Gateway Service Fix ===" -ForegroundColor Cyan Write-Host "" # Check administrator privileges $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin) { Write-Host "ERROR: Administrator privileges required" -ForegroundColor Red Write-Host "Please right-click this script and select 'Run as Administrator'" -ForegroundColor Yellow pause exit 1 } Write-Host "SUCCESS: Administrator privileges confirmed" -ForegroundColor Green Write-Host "" # Check current Gateway status Write-Host "Checking Gateway status..." -ForegroundColor Cyan $gatewayProcess = Get-Process -Name node -ErrorAction SilentlyContinue | Where-Object { $_.CommandLine -like "*openclaw*gateway*" } if ($gatewayProcess) { Write-Host "Gateway is running (PID: $($gatewayProcess.Id))" -ForegroundColor Green Write-Host " Start time: $($gatewayProcess.StartTime)" -ForegroundColor Gray } else { Write-Host "Gateway is not running" -ForegroundColor Red } Write-Host "" # Check port listening Write-Host "Checking port 18789..." -ForegroundColor Cyan $portCheck = Test-NetConnection -ComputerName 127.0.0.1 -Port 18789 -InformationLevel Quiet -WarningAction SilentlyContinue if ($portCheck) { Write-Host "Port 18789 is listening" -ForegroundColor Green } else { Write-Host "Port 18789 is not listening" -ForegroundColor Red } Write-Host "" # Check scheduled task Write-Host "Checking scheduled task..." -ForegroundColor Cyan $taskExists = schtasks /Query /TN "OpenClaw Gateway" 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host "Scheduled task already exists" -ForegroundColor Green # Show task details Write-Host "" Write-Host "Task details:" -ForegroundColor Cyan schtasks /Query /TN "OpenClaw Gateway" /FO LIST /V 2>&1 | Select-String -Pattern "Task To Run|State|Next Run Time" } else { Write-Host "Scheduled task does not exist" -ForegroundColor Red Write-Host "" # Create scheduled task Write-Host "Creating scheduled task..." -ForegroundColor Cyan $taskPath = "$env:USERPROFILE\.openclaw\gateway.cmd" # Check if task file exists if (Test-Path $taskPath) { Write-Host "Task file found: $taskPath" -ForegroundColor Gray } else { Write-Host "ERROR: Task file not found at $taskPath" -ForegroundColor Red pause exit 1 } $createTask = schtasks /Create /TN "OpenClaw Gateway" /TR $taskPath /SC ONLOGON /RL HIGHEST /F 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host "SUCCESS: Scheduled task created" -ForegroundColor Green # Verify task was created $verifyTask = schtasks /Query /TN "OpenClaw Gateway" 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host "VERIFIED: Task is now registered" -ForegroundColor Green } else { Write-Host "WARNING: Task creation reported success but verification failed" -ForegroundColor Yellow } } else { Write-Host "ERROR: Failed to create scheduled task" -ForegroundColor Red Write-Host "Error output: $createTask" -ForegroundColor Gray } } Write-Host "" Write-Host "=== Fix Complete ===" -ForegroundColor Cyan Write-Host "" Write-Host "Next steps:" -ForegroundColor Yellow Write-Host "1. Run: openclaw gateway status" -ForegroundColor White Write-Host "2. Check: openclaw status" -ForegroundColor White Write-Host "3. Access: http://127.0.0.1:18789/" -ForegroundColor White Write-Host "" pause