Provisioning: Fix disabling windows updates
authorOliver Wolff <oliver.wolff@qt.io>
Wed, 17 Jan 2018 14:57:27 +0000 (15:57 +0100)
committerTony Sarajärvi <tony.sarajarvi@qt.io>
Mon, 5 Feb 2018 14:13:18 +0000 (14:13 +0000)
On some machines the updates were already disabled, which lead
to the call to disable the service failing. Now we just move on without
error.

Change-Id: Ia48f7164c23dfe24e24548558d582cdc0190b7e3
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Reviewed-by: Tony Sarajärvi <tony.sarajarvi@qt.io>
(cherry picked from commit 99595f44f1b3a3c35d8decc671a8933f65220cf3)

coin/provisioning/common/windows/disable-windows-updates.ps1

index 1a01473..05215e2 100644 (file)
 
 # This script disables the automatic Windows updates
 
-stop-service wuauserv
-set-service wuauserv \96startup disabled
+$service = get-service wuauserv
+if (-not $service) {
+    Write-Host "Windows Update service not found."
+    exit 0
+}
+
+if ($service.Status -eq "Stopped") {
+    Write-Host "Windows Update service already stopped."
+} else {
+    Write-Host "Stopping Windows Update service."
+    stop-service wuauserv
+}
+
+$startup = Get-WmiObject Win32_Service | Where-Object {$_.Name -eq "wuauserv"} | Select -ExpandProperty "StartMode"
+if ($startup -ne "Disabled") {
+    set-service wuauserv -startup disabled
+} else {
+    Write-Host "Windows Update service startup already disabled."
+}