From dbb16df8e1b0bfeb8783d4af70603e9f4da9fdc0 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Mon, 12 Aug 2024 01:23:42 +0200 Subject: [PATCH] Add methods for managing auto restart feature --- scripts/Windows/Scripts/Registry.ps1 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scripts/Windows/Scripts/Registry.ps1 b/scripts/Windows/Scripts/Registry.ps1 index 2ce9b9e6..2d63e659 100644 --- a/scripts/Windows/Scripts/Registry.ps1 +++ b/scripts/Windows/Scripts/Registry.ps1 @@ -1,6 +1,8 @@ using namespace Microsoft.Win32; $null = New-Module { + $wuPolicyPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate"; + function Edit-DefaultUserKey { param( [scriptblock] $Action @@ -53,4 +55,22 @@ $null = New-Module { function Disable-BootMessage { Set-BootMessage; } + + <# + .SYNOPSIS + Disables automatic reboots by Windows Update. + #> + function Disable-WindowsUpdateAutoRestart { + Set-ItemProperty "$wuPolicyPath\AU" ` + -Name NoAutoRebootWithLoggedOnUsers ` + -Value $Value; + } + + <# + .SYNOPSIS + Resets the automatic reboot state. + #> + function Reset-WindowsUpdateAutoRestart { + Remove-Item -Recurse "$wuPolicyPath"; + } }