# ========================================== # Windows Update 彻底关闭脚本 (PowerShell) # 请以管理员身份运行 # ========================================== Write-Host ">>> [1/5] 停止并禁用所有更新相关服务..." -ForegroundColor Cyan $services = @("wuauserv", "UsoSvc", "WaaSMedicSvc", "bits", "dosvc", "CryptSvc") foreach ($svc in $services) { Stop-Service -Name $svc -Force -ErrorAction SilentlyContinue Set-Service -Name $svc -StartupType Disabled -ErrorAction SilentlyContinue # 通过注册表强制禁用 WaaSMedicSvc (该服务会自我修复) $regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\$svc" if (Test-Path $regPath) { Set-ItemProperty -Path $regPath -Name "Start" -Value 4 -Force Set-ItemProperty -Path $regPath -Name "FailureActions" -Value ([byte[]](0x00,0x00,0x00,0x00)) -Force -ErrorAction SilentlyContinue } } Write-Host " ? 服务已禁用" -ForegroundColor Green Write-Host ">>> [2/5] 禁用所有 Windows Update 计划任务..." -ForegroundColor Cyan $tasks = @( "\Microsoft\Windows\UpdateOrchestrator\Schedule Scan", "\Microsoft\Windows\UpdateOrchestrator\Schedule Scan Static Task", "\Microsoft\Windows\UpdateOrchestrator\USO_UxBroker", "\Microsoft\Windows\WindowsUpdate\Scheduled Start", "\Microsoft\Windows\WaaSMedic\PerformRemediation" ) foreach ($task in $tasks) { Disable-ScheduledTask -TaskName ($task.Split('\')[-1]) -TaskPath ($task.Substring(0, $task.LastIndexOf('\') + 1)) -ErrorAction SilentlyContinue | Out-Null } Write-Host " ? 计划任务已禁用" -ForegroundColor Green Write-Host ">>> [3/5] 写入注册表策略强制关闭更新..." -ForegroundColor Cyan $auPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" if (-not (Test-Path $auPath)) { New-Item -Path $auPath -Force | Out-Null } Set-ItemProperty -Path $auPath -Name "NoAutoUpdate" -Value 1 -Type DWord Set-ItemProperty -Path $auPath -Name "AUOptions" -Value 1 -Type DWord Set-ItemProperty -Path $auPath -Name "UseWUServer" -Value 1 -Type DWord $wuPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" Set-ItemProperty -Path $wuPath -Name "DisableOSUpgrade" -Value 1 -Type DWord Set-ItemProperty -Path $wuPath -Name "DoNotConnectToWindowsUpdateInternetLocations" -Value 1 -Type DWord Write-Host " ? 注册表策略已写入" -ForegroundColor Green Write-Host ">>> [4/5] 添加防火墙规则阻断更新流量..." -ForegroundColor Cyan $fwRules = @( @{Name="Block_WindowsUpdate_HTTP"; RemoteAddress=@("13.107.4.50","13.107.6.152","13.107.9.152","23.102.135.246"); Port=80}, @{Name="Block_WindowsUpdate_HTTPS"; RemoteAddress=@("13.107.4.50","13.107.6.152","13.107.9.152","23.102.135.246"); Port=443} ) foreach ($rule in $fwRules) { foreach ($ip in $rule.RemoteAddress) { $ruleName = "$($rule.Name)_$ip" Remove-NetFirewallRule -DisplayName $ruleName -ErrorAction SilentlyContinue New-NetFirewallRule -DisplayName $ruleName -Direction Outbound -RemoteAddress $ip ` -RemotePort $rule.Port -Protocol TCP -Action Block -Profile Any -ErrorAction SilentlyContinue | Out-Null } } Write-Host " ? 防火墙阻断规则已添加" -ForegroundColor Green Write-Host ">>> [5/5] 验证状态..." -ForegroundColor Cyan $wuaStatus = Get-Service wuauserv | Select-Object -ExpandProperty StartType Write-Host " wuauserv 启动类型: $wuaStatus" -ForegroundColor $(if($wuaStatus -eq 'Disabled'){'Green'}else{'Red'}) Write-Host "`n========================================" -ForegroundColor Yellow Write-Host " ? Windows Update 已彻底关闭!" -ForegroundColor Green Write-Host " ? 重启后生效,部分设置立即生效" -ForegroundColor Yellow Write-Host "========================================`n" -ForegroundColor Yellow