

while not the most elegant solution, in two steps (1. 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. Normally, I trigger updates when about to leave work (and about 4-5 hours before midnight). We check if these keys exist in the first bat file. If the updates require a reboot, some registry keys (under the WindowsUpdate reg key) are set with value 0x1. While it installs updates, run "scheduleRebootAfterUpdates.bat".

When Windows nags you to "Install Updates", let it start installing updates. Set the "Wake to Execute Flag" through Task Scheduler /bīoth files are assumed to be in C:\tmp\Scripts\ The second one is called "scheduleRebootAfterUpdates.bat": /query /TN RebootAfterUpdates > /B /I "RebootAfterUpdates" doh %errorlevel%=0 goto /Change /TN RebootAfterUpdates /SD Task updated to execute /Create /SC ONCE /TN RebootAfterUpdates /TR "C:\tmp\Scripts\rebootAfterUpdates.bat" /ST 23:55 /sd %DATE% /ru SYSTEM Task created. The first one is called "rebootAfterUpdates.bat" REBOOT_KEY="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto skip=4 may be required on some versions of /F "usebackq skip=2 tokens=1-3" %%A IN (`reg query %REBOOT_KEY% /s 2^>nul`) DO %%B EQU %REGDWORD% %%C EQU %VALUEVAL% ( 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 shows up high on the "Install and Restart not Install and Shutdown" Google search.
