31

I have a Windows box I would like to manage remotely. When I logged in this morning, the Start menu shows a ! next to the Shutdown button, notifying me there are updates to install. But the only option it gives me to install the updates is to then shutdown. Is there not a way to tell it to "install updates and restart" ?

CoolUserName
  • 513
  • 2
  • 5
  • 9
  • 2
    What version of Windows? – Andy Shinn Jun 04 '12 at 17:20
  • Don't forget to mark answers on your questions - even the ones that you've ended up answering yourself. – mfinni Jun 05 '12 at 19:42
  • 1
    In case you wind up wanting to script the process, this may serve as a useful starting point: http://www.scms.waikato.ac.nz/~harry/wsusupdate.vbs – Harry Johnston Jun 06 '12 at 03:10
  • This is by design, Microsoft assume you don't care generally don't care how long a shutdown takes (unless it's due to power failure, then a shutdown -s -t 00 would avoid updates) but you would care about how long a restart takes, seeing as restarting implies you want the services hosted on the box up and running. – Alex Berry Nov 07 '12 at 16:40
  • I disagree. I might want to restart _in order to_ install updates that require a restart. Moreover, where I work, there's a weird restriction whereby we can't install updates via Windows Update, and so have to install them by shutting down. I would like to be able to install them and restart, just the same. – Stewart Sep 25 '17 at 09:01
  • Just realised that since this is on serverfault, the asker is presumably wanting to do it on a server, so the middle sentence of my last comment probably wouldn't be applicable. But an update might still require a restart, and in this scenario one would want to keep the downtime to a minimum, so installing and restarting would be most sensible. – Stewart Sep 25 '17 at 09:32

5 Answers5

15

Yes. You can install all of the updates available - via either Windows Update in your Control Panel, or the yellow WU shield in the system tray near the clock. Then, when that's done, you can do a reboot from the Start Menu (or calling shutdown /r from the command line.)

The only other ways to automate it all in one step is via writing your own code (not just a simple script), or using add-on tools, free or commercial, from either MS or 3rd parties.

mfinni
  • 35,711
  • 3
  • 50
  • 86
15

I see this is an older question, but it's now possible to install updates and then reboot using Powershell. Specifically, you need to download and install the Windows Update PowerShell Module. Then, you can run the command Get-WUInstall -AcceptAll -AutoReboot (there are other switches and arguments to control what updates get installed). This will cause Windows to download updates, install them, and then reboot when finished. In my opinion, this is great for servers, because you can run one command and then walk away.

jgstew
  • 86
  • 9
Charles Burge
  • 758
  • 6
  • 16
12

There are certain benefits to installing updates during rebooting/shut-down:

  • The installation is not slowed down, or tampered with by other running software, AVP, etc.

  • There's no UI to deal with, click through, etc. It goes through faster. When it's done, in case of a reboot, the computer is ready to go.

Unfortunately there seems to be no way to do it with Microsoft provided tools. I use this free utility that will do it for you. I created a shortcut with the following parameters and placed it into my Start button menu:

ShutdownWithUpdates /r /f

From what I see it can also reboot and install updates on a remote workstation in an active directory setup.

Read more here.

ndemou
  • 1,215
  • 2
  • 16
  • 27
ahmd0
  • 221
  • 2
  • 3
3

This shows up high on the "Install and Restart not Install and Shutdown" Google search. Hence, I thought I should add a solution that I ended up writing for this exact annoying problem (people tell me that Win10 has this by default, but I am not on Win10).

This works using two batch files. The first one is called "rebootAfterUpdates.bat"

@echo OFF
@setlocal ENABLEEXTENSIONS
@set REBOOT_KEY="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired"
@SET REGDWORD=REG_DWORD
@SET VALUEVAL=0x1

@REM skip=4 may be required on some versions of Windows
@FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`reg query %REBOOT_KEY% /s 2^>nul`) DO (
    @IF %%B EQU %REGDWORD% (
        @IF %%C EQU %VALUEVAL% (
            call :REBOOT
        )
    )
)

:NOREBOOT
@Echo No reboot required
exit /b 36877
REM 36877 is 0x900D (i.e. Good, no reboot required)
:REBOOT
@ECHO Here We REBOOT
SHUTDOWN -r -f -t 10
exit /b 3059719
REM 3059719 is 0x2EB007 (i.e. REBOOT was triggered)

The second one is called "scheduleRebootAfterUpdates.bat":

@schtasks /query /TN RebootAfterUpdates > doh
@findstr /B /I "RebootAfterUpdates" doh >nul
@if %errorlevel%==0  goto :update
@goto :create

:update
@del doh
@SCHTASKS /Change /TN RebootAfterUpdates /SD %DATE%
@echo Task updated to execute today
@goto :exitBat

:create
@del doh
@SCHTASKS /Create /SC ONCE  /TN RebootAfterUpdates /TR "C:\tmp\Scripts\rebootAfterUpdates.bat" /ST 23:55 /sd %DATE%  /ru SYSTEM /f
@echo Task created. Set the "Wake to Execute Flag" through Task Scheduler GUI

:exitBat
@exit /b

Both files are assumed to be in C:\tmp\Scripts\ When Windows nags you to "Install Updates", let it start installing updates. While it installs updates, run "scheduleRebootAfterUpdates.bat".

Background of operation:

If the updates require a reboot, some registry keys (under the WindowsUpdate reg key) are set with value 0x1.

We check if these keys exist in the first bat file. If they do, reboot right away.

Normally, I trigger updates when about to leave work (and about 4-5 hours before midnight).

The second bat creates a scheduled task (or updates an existing task to run 5 min before midnight) and this scheduled task executes the first bat.

So... while not the most elegant solution, in two steps (1. trigger 'Install Updates' and 2. run the second bat file), your machine will reboot near midnight assuming that installation of updates succeeded.

Additionally, you can set the 'Wake machine to execute task' from the Task Scheduler GUI as well as check the execution return code to see what happened last time.

P.S. Tested on Win7 64bit.

2

There is no way to initate a "Install Updates and Restart" manually. You could set a time for the updates to install, and then specify that the machine can reboot after Automatic Updates, either via the Automatic Updates (or Windows Update) control panel, directly via the registry, or via Group Policy:

http://support.microsoft.com/kb/328010

But as far as a one-click "Install updates and reboot" option, there is none.

Glenn Sullivan
  • 1,368
  • 9
  • 17