<# .SYNOPSIS Stop ROA2WEB Telegram Bot Service .DESCRIPTION Stops the ROA2WEB Telegram Bot Windows service gracefully. .EXAMPLE .\Stop-TelegramBot.ps1 #> [CmdletBinding()] param( [string]$ServiceName = "ROA2WEB-TelegramBot", [int]$Timeout = 30 ) $ErrorActionPreference = "Stop" Write-Host "`n[*] Stopping ROA2WEB Telegram Bot Service..." -ForegroundColor Cyan try { $service = Get-Service -Name $ServiceName -ErrorAction Stop if ($service.Status -eq "Stopped") { Write-Host " [OK] Service is already stopped" -ForegroundColor Green exit 0 } # Stop service Stop-Service -Name $ServiceName -Force Write-Host " [*] Service stop command issued" -ForegroundColor Yellow # Wait for service to stop $elapsed = 0 while ($service.Status -ne "Stopped" -and $elapsed -lt $Timeout) { Start-Sleep -Seconds 1 $service.Refresh() $elapsed++ Write-Host " [*] Waiting for service to stop... ($elapsed/$Timeout)" -ForegroundColor Yellow } if ($service.Status -eq "Stopped") { Write-Host " [OK] Service stopped successfully" -ForegroundColor Green exit 0 } else { Write-Host " [ERROR] Service did not stop within timeout (Status: $($service.Status))" -ForegroundColor Red Write-Host " You may need to force kill the process" -ForegroundColor Yellow exit 1 } } catch { Write-Host " [ERROR] Failed to stop service: $_" -ForegroundColor Red exit 1 }