Disable Automatic Reboot After Update

by May 1, 2015

Are you tired of Windows unexpectedly rebooting, just because some newly installed updates required a reboot?

Like most things, you can control the reboots via policy settings, and most policy settings are just registry keys. Here is a sample script that sets the policy value controlling the reboot after update installation:

$code = 
{
  $key = 'HKLM:\Software\Policies\Microsoft\Windows\WindowsUpdate\AU'
  $name = 'NoAutoRebootWithLoggedOnUsers'
  $type = 'DWord'
  $value = 1

  if (!(Test-Path -Path $key))
  {
    $null = New-Item -Path $key -Force
  }
  Set-ItemProperty -Path $key -Name $name -Value $value -Type $type
}

Start-Process -FilePath powershell.exe -ArgumentList $code -Verb runas -WorkingDirectory c:\

Note how the script performs the registry access: it is actually delegating the control to another instance of PowerShell. This second instance is launched via Start-Process, and "-verb Runas" makes sure the code runs with Administrator privileges.

If you do not currently have Administrator privileges, the elevation dialog opens and gives you the chance to either activate your Administrator privileges, or specify an authorized account if your account has no such rights.

Twitter This Tip! ReTweet this Tip!