How to automatically call sequences of 1) windows update and 2) restart until no new update found?

5,792

Solution 1

Schedule the following command to be run on startup:

  • wuauclt /detectnow

And go into Windows Udpate and change the settings to say Download and install updates automatically, then you should be able to start Windows Update manually and go away. After the update is completed it'll reboot, after the restart it'll go look for more updates.

If necessary, disable your account password until all of the updates have been applied, and then re-apply the password once you're all set.

Solution 2

I just put this together, it seems to work pretty well:

wuauclt /detectnow
wuauclt /updatenow

:CheckForRequiredRestart
    reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" > nul && shutdown -r -t 0
    ping 127.0.0.1 -n 61 > nul
goto CheckForRequiredRestart

Just throw it in a .cmd file and drop it in Startup folder and run it once.

(I'm not really clear on what OS's support the /updatenow parameter but it does seem to have an effect on Windows 7.)

I tested patching a Windows 7 VM and it went through the entire sequence (something like 10 restarts?). The only patches that remained were the Malicious Removal Tool (which requires user approval) and 4 updates that are unchecked by default. They are small though, after installing there was a restart and then a couple patches on top and it was done.

It doesn't install optional updates so there were a few of those, small. I installed them manually and there weren't even any patches on top, so all-in-all it was pretty effective for a simple script. When it finally finishes you simply delete the script. I don't know a simple way to detect a complete finish or I'd have it remove/unschedule itself.


I really don't like WuInstall or the VBS/PowerShell scripts floating around as they are all forced to deal with advanced categorical selection of updates that is too complex for this simple goal. There's no simplicity like "Important", "Recommended", and "Optional"; you have to explicitly exclude languages and/or include many different categories and even then it's not quite the same as what you achieve through the traditional install/restart cycle.

To patch more than just the odd system you should of course use a different method, such as deploying an image with WDS, using a slipstreamed install, WSUS, or WSUS Offline Update.

Solution 3

I found on our site this solution but that is not fully automatically - i.e. I call 1) Windows Updates, then 2) Restart, then 3) Log in, then do the boring loop 1-2-3 again and again manually.

You could also use the freeware tool Wuinstall. With that you can automate the updating process. For example you can configure wuinstall to install updates until a reboot is needed. Then the tool restarts the system and continues with installing further updates, if there are some left. So you get your system much more faster up to date than using the normal Windows update service.

One potential downside is that if an update fails each time it runs, it may keep trying to rerun that particular update over and over again, locking the computer in a loop.

To prevent getting stuck in an infinite reboot loop you can set the maximum number of reboots. For example after three times of rebooting, the tool will interrupt the updating process.

I used this tool to set up several fresh installed computers and it worked well.

Share:
5,792

Related videos on Youtube

Nam G VU
Author by

Nam G VU

Updated on September 18, 2022

Comments

  • Nam G VU
    Nam G VU almost 2 years

    I found on our site this solution but that is not fully automatically - i.e. I call 1) Windows Updates, then 2) Restart, then 3) Log in, then do the boring loop 1-2-3 again and again manually.

    I seek for automation this tendering process! Any ideas please share.

    Thank you

    • Admin
      Admin over 12 years
      Is there a reason the automatic update process will not work for you? Are you simply trying to do it more quickly than theautomated process?
    • Admin
      Admin over 12 years
      @DaveM I state it in my post above. I feel annoyed when the OS require me to restart in the middle of my work. I would rather wait it finish its updating loop than be interrupted while working
  • Jackson
    Jackson over 12 years
    One potential downside is that if an update fails each time it runs, it may keep trying to rerun that particular update over and over again, locking the computer in a loop.
  • SecurityMatt
    SecurityMatt over 12 years
    On the other hand, any other possible solution would stop trying to update the machine before all updates are installed. You can only have one or the other.
  • Nam G VU
    Nam G VU over 10 years
    @SecurityMatt My question is how can the system auto restart after it completes update? Is that because of the Download and install updates automatically setting?
  • Nam G VU
    Nam G VU over 10 years
    This is awesome ^^ I'll try Wuinstall and back with you later.
  • Nam G VU
    Nam G VU over 8 years
    Today I tried and get "Page not found" from wuinstall.com
  • Nam G VU
    Nam G VU over 8 years
    I tried on Windows 7 Ultimate 64 bit and received the error ERROR: The system was unable to find the specified registry key or value. I guess HKLM\Software\Microsoft\Windows\CurrentVersion\Wi ndowsUpdate\Auto Update\RebootRequired is not a valid registry path.
  • Jerome
    Jerome over 8 years
    @NamGVU I just double checked, the post contains the correct (quoted) path. I used this script quite a bit. The string you just gave has an extra space in "WindowsUpdate", perhaps that's it? Or maybe you're missing the quotation marks?
  • Nam G VU
    Nam G VU over 8 years
    I copy/paste your script. My report maybe a bit different via copy/paste from command line windows only. Retried with no space for WindowsUpdate and full quotes. Still the same error.