Files
my-botty/scripts/blocksysreboot.ps1
T

61 lines
2.4 KiB
PowerShell

# blocksysreboot.ps1 — prevents Windows auto-restart while Hermes is running
# Run: powershell -NoProfile -ExecutionPolicy Bypass -File blocksysreboot.ps1
# Keep running in a terminal window. Ctrl+C to stop.
# Verify registry keys are set (requires admin — set them once manually)
$wuPolicy = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"
$auPolicy = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU"
$noReboot = (Get-ItemProperty -Path $wuPolicy -Name "NoAutoRebootWithLoggedOnUsers" -ErrorAction SilentlyContinue).NoAutoRebootWithLoggedOnUsers
$noUpdate = (Get-ItemProperty -Path $auPolicy -Name "NoAutoUpdate" -ErrorAction SilentlyContinue).NoAutoUpdate
if ($noReboot -ne 1) {
Write-Host "[blocksysreboot] ERROR: NoAutoRebootWithLoggedOnUsers not set."
Write-Host "[blocksysreboot] Run this once as admin:"
Write-Host " Set-ItemProperty -Path $wuPolicy -Name NoAutoRebootWithLoggedOnUsers -Value 1 -Type DWord"
exit 1
}
if ($noUpdate -ne 1) {
Write-Host "[blocksysreboot] ERROR: NoAutoUpdate not set."
Write-Host "[blocksysreboot] Run this once as admin:"
Write-Host " Set-ItemProperty -Path $auPolicy -Name NoAutoUpdate -Value 1 -Type DWord"
exit 1
}
Write-Host "[blocksysreboot] Registry protection verified."
# Pause Windows Update for 35 days
try {
wuauclt /pause 2>&1 | Out-Null
Write-Host "[blocksysreboot] WU paused for 35 days."
} catch {
Write-Host "[blocksysreboot] wuauclt /pause failed: $($_.Exception.Message)"
}
Write-Host "[blocksysreboot] Protection active. Running watchdog..."
Write-Host "[blocksysreboot] Press Ctrl+C to stop."
Write-Host ""
$lastCheck = 0
while ($true) {
$hermes = Get-Process -Name "hermes" -ErrorAction SilentlyContinue
if (-not $hermes) {
Write-Host "[blocksysreboot] Hermes not running. Exiting (registry settings remain)."
Write-Host "[blocksysreboot] To restore WU: run as admin:"
Write-Host " Remove-ItemProperty -Path $wuPolicy -Name NoAutoRebootWithLoggedOnUsers"
Write-Host " Remove-ItemProperty -Path $auPolicy -Name NoAutoUpdate"
Write-Host " wuauclt /reset"
exit 0
}
# Re-apply WU pause every 24 hours
$now = (Get-Date).Ticks
if (($now - $lastCheck) -gt (24 * 3600 * 10000000)) {
$lastCheck = $now
try { wuauclt /pause 2>&1 | Out-Null } catch {}
Write-Host "[blocksysreboot] WU re-paused."
}
Start-Sleep -Seconds 60
}