mirror of
git://code.qt.io/qt/qt5.git
synced 2026-04-04 20:56:46 +08:00
Fix failing to disable windows update service
Sometimes when trying to stop windows update service it fails. Will now retry disabling wuauserv Task-number: QTQAINFRA-2632 Change-Id: I5b6bf40aa15bb1f5225dc51e2f7212a01a13e9a6 Reviewed-by: Heikki Halmet <heikki.halmet@qt.io>
This commit is contained in:
committed by
Aapo Keskimolo
parent
ab438507e9
commit
ce91433364
@@ -33,6 +33,8 @@
|
||||
|
||||
# This script disables the automatic Windows updates
|
||||
|
||||
. "$PSScriptRoot\helpers.ps1"
|
||||
|
||||
$service = get-service wuauserv
|
||||
if (-not $service) {
|
||||
Write-Host "Windows Update service not found."
|
||||
@@ -43,7 +45,7 @@ if ($service.Status -eq "Stopped") {
|
||||
Write-Host "Windows Update service already stopped."
|
||||
} else {
|
||||
Write-Host "Stopping Windows Update service."
|
||||
Stop-Service -Name "wuauserv" -Force
|
||||
Retry {Stop-Service -Name "wuauserv" -Force} 20 5
|
||||
}
|
||||
|
||||
$startup = Get-WmiObject Win32_Service | Where-Object {$_.Name -eq "wuauserv"} | Select -ExpandProperty "StartMode"
|
||||
|
||||
@@ -159,3 +159,35 @@ function IsProxyEnabled {
|
||||
function Get-Proxy {
|
||||
return (Get-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings').proxyServer
|
||||
}
|
||||
|
||||
function Retry{
|
||||
<#
|
||||
usage:
|
||||
Retry{CODE}
|
||||
Retry{CODE} <num of retries> <delay_s>
|
||||
#delay is in seconds
|
||||
#>
|
||||
Param(
|
||||
[Parameter(mandatory=$true)]
|
||||
[scriptblock]$command,
|
||||
[int][ValidateRange(1, 20)]$retry = 5,
|
||||
[int][ValidateRange(1, 60)]$delay_s = 5
|
||||
)
|
||||
$success=$false
|
||||
$retry_count=0
|
||||
do{
|
||||
try {
|
||||
Invoke-Command -ScriptBlock $command
|
||||
$success=$true
|
||||
}
|
||||
catch {
|
||||
$retry_count++
|
||||
Write-Host "Error: $_, try: $retry_count, retrying in $delay_s seconds"
|
||||
Start-Sleep -Seconds $delay_s
|
||||
}
|
||||
} until ($success -or $retry+1 -le $retry_count)
|
||||
|
||||
if (-not $success) {
|
||||
Throw("Failed to run command successfully in $retry_count tries")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user