$services = 'PCAsvc','DPS','DiagTrack','EventLog','SysMain','Schedule','DusmSvc','Appinfo','WSearch' function Start-ServiceAsAdmin { param( [string[]]$Names ) if (-not $Names -or $Names.Count -eq 0) { return } # Build the command that will run elevated $serviceList = ($Names | ForEach-Object { "'$($_.Replace("'", "''"))'" }) -join ',' $command = "Start-Service -Name $serviceList -ErrorAction SilentlyContinue" # Encode it to avoid quoting problems when passing it to pwsh $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) try { $pwsh = (Get-Process -Id $PID).Path Start-Process ` -FilePath $pwsh ` -Verb RunAs ` -ArgumentList '-NoProfile', '-EncodedCommand', $encodedCommand ` -Wait ` -ErrorAction Stop Start-Sleep -Milliseconds 500 } catch { Write-Host "" Write-Host "Permissao de administrador cancelada." -ForegroundColor Yellow Start-Sleep -Seconds 1 } } function Show-Menu { Clear-Host Write-Host "Pre-Scan KumaRP" -ForegroundColor Cyan Write-Host "-------------`n" $script:missing = @() for ($i = 0; $i -lt $services.Count; $i++) { $name = $services[$i] $svc = Get-Service -Name $name -ErrorAction SilentlyContinue Write-Host ("[{0}] {1,-12}" -f ($i + 1), $name) -NoNewline if ($svc -and $svc.Status -eq 'Running') { Write-Host " OK" -ForegroundColor Green } else { Write-Host " EM FALTA" -ForegroundColor Red $script:missing += $name } } Write-Host "" Write-Host "" if ($missing.Count -eq 0) { Write-Host "Estas OK para jogar" -ForegroundColor Green } else { Write-Host "Tens estes servicos em falta:" -ForegroundColor Red foreach ($name in $missing) { Write-Host " - $name" -ForegroundColor Red } Write-Host "" Write-Host "[A] Ativar todos em falta" } Write-Host "[R] Atualizar" Write-Host "[Q] Sair" } :main while ($true) { Show-Menu $choice = Read-Host "`nOpcao" switch ($choice.ToUpper()) { 'A' { if ($missing.Count -gt 0) { Start-ServiceAsAdmin -Names $missing } } 'R' { # Loop automatically refreshes } 'Q' { break main } default { if ($choice -match '^\d+$') { $index = [int]$choice - 1 if ($index -ge 0 -and $index -lt $services.Count) { $name = $services[$index] $svc = Get-Service -Name $name -ErrorAction SilentlyContinue if (-not $svc) { Write-Host "" Write-Host "$name nao foi encontrado." -ForegroundColor Red Start-Sleep -Seconds 1 } elseif ($svc.Status -eq 'Running') { Write-Host "" Write-Host "$name ja esta ativo." -ForegroundColor Green Start-Sleep -Seconds 1 } else { Start-ServiceAsAdmin -Names @($name) } } } } } }