68

I run Matlab simulations that sometimes take weeks to finish and when Windows restarts I lose all my work so I really need a way to stop auto restarts.

Windows 11 seems to have disabled all ways to get around Auto Update Restarts. Is there a still a workaround?

It used to be possible to set NoAutoRebootWithLoggedOnUsers in:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU

if you also set AUOptions to 4 in the same location but this does not work for me now.

4 Answers4

30

Windows will not reboot during working hours. My solution is to run a scheduled task that changes the working hours in the registry, say every hour or two, so that it is always a working hour. I coded up this 4 line cmd command batch file program:

for /f %%i in ('powershell "((get-date).Hour+18) %% 24"') do set startHour=%%i
for /f %%i in ('powershell "((get-date).Hour+12) %% 24"') do set endHour=%%i

reg add HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings /v ActiveHoursStart /t REG_DWORD /d %startHour% /f reg add HKLM\SOFTWARE\Microsoft\WindowsUpdate\UX\Settings /v ActiveHoursEnd /t REG_DWORD /d %endHour% /f

I then used Windows Task Scheduler to make this .bat script run every hour for 1 day and repeat daily.

To stop pop-ups of the command windows, make task scheduler start the program/script "cmd.exe"

and put as its arguments:

/c start /min C:\work\disableautoupdate.bat ^& exit

(Substitute your own filename above for C:\work\disableautoupdate.bat)

This will minimise the window your script runs in.

Task Schedule View

Tested: It works! I installed an update requiring a restart on 31-May. I am informed that this restart will happen outside of working hours. As of 20-June, 22 days later, no restart had taken place.

I figured out how to incorporate @Jonathan's feedback. It is easier to do modulo maths (and to get the hour independent of locale/region/format preferences) with powershell commands. It's still a cmd batch file, but it calls powershell. Reduces to 4 lines and should work everywhere.

David Fox
  • 481
18

Windows actually has an API that enables a process that has a window to block a system shutdown indefinitely until the user manually chooses what to do next. (possibly, as @josh3736 pointed out, Windows Update may break this eventually. But I personally have not experienced a concrete case of it. At least it should be safe to block a shutdown when you sleep until you wake up, and then you just click cancel to cancel the shutdown)

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-shutdownblockreasoncreate

ShutdownBlockReasonCreate function (winuser.h)

Indicates that the system cannot be shut down and sets a reason string to be displayed to the user if system shutdown is initiated.

Note that calling this alone cannot block a shutdown/restart successfully. You also need your application to handle the WM_QUERYENDSESSION and WM_ENDSESSION messages. I will discuss them at the end.

If you are not a developer and do not know how to use Windows API, you can use a small program that I have written years ago for exactly the same purpose: https://github.com/guanyuming-he/ShutdownBlocker

Either way, when you have successfully created a shutdown block reason, Windows will pause when a shutdown (including an update restart) is issued, and display this to you, where you can click Cancel to cancel the shutdown. enter image description here

Note: If you have no control over your Matlab simulations program (I do not use Matlab so I do not know if it is possible), then it might or might not work, depending on how Matlab handles the situation. According to Microsoft (https://learn.microsoft.com/en-us/windows/win32/shutdown/shutting-down),

Applications with a window and message queue receive shutdown notifications through the WM_QUERYENDSESSION and WM_ENDSESSION messages. These applications should return TRUE to indicate that they can be terminated.

If Matlab chooses to return TRUE on receiving this message, it will close, even if the shutdown is blocked this way. (And if you call the API without returning FALSE on receiving WM_QUERYENDSESSION, then it will not succeed as your app would close as a result of it)

Guanyuming He
  • 413
  • 4
  • 10
15

The Group Policy Configure Automatic Updates allows you to prevent automatic installation of updates.

  1. Open gpedit.msc
  2. Computer -> Administrative Templates -> Windows Components -> Windows Update -> Manage end user experience -> Configure Automatic Updates (Alternatively go through "all settings" if you use English and you know the name from here)
  3. Enable, Set to (2) notify only

Specifies whether this computer will receive security updates and other important downloads through the Windows automatic updating service.

This setting lets you specify whether automatic updates are enabled on this computer. If the service is enabled, you must select one of the four options in the Group Policy Setting:

2 = Notify before downloading and installing any updates.

When Windows finds updates that apply to this computer, users will be notified that updates are ready to be downloaded. After going to Windows Update, users can download and install any available updates.

Kissaki
  • 773
0

Hello Windows 10 and 11 users,

After doing my own research on the Microsoft "Manage device restarts after updates" Documents and before finding this question I have came up with my own practical solution to this problem.


To solve this problem, lets get a basic understanding of how the restarts work. The document mentions being able to delay the update restart:

Delay automatic restart When you enable Configure Automatic Updates in group policy, you can also enable one of the following policies to delay an automatic restart after update installation:

Turn off auto-restart for updates during active hours prevents automatic restart during active hours.

No auto-restart with logged on users for scheduled automatic updates installations prevents automatic restart when a user is signed in. If a user schedules the restart in the update notification, the device restarts at the time the user specifies even if a user is signed in at the time. This policy only applies when Configure Automatic Updates is set to option 4 - Auto download and schedule the install.

According the the Microsoft Documents, under the policy "Turn off auto-restart for updates during active hours" it specifically states:

Use this policy to configure active hours, during which the device won't restart. This policy has no effect if the No auto-restart with logged on users for scheduled automatic updates installations or Always automatically restart at the scheduled time policies are enabled.

This information tells us that if we have "Turn off auto-restart for updates during active hours" enabled or if your computer is set up to restart automatically every day, it won't restart if your computer is within the active hours. It will wait for your computer to be outside of the active hours or it will wait for that scheduled shutdown.

My solution is simple. Always be within the Active Hours.


For this, I created a comprehensive batch file that can automatically configure the necessary registry keys and scheduled task required to keep a Windows computer within the Active Hours. The .bat file can be placed anywhere as it will automatically install and uninstall itself as you enable or disable the scheduled task.

Always Active Hours

Always Active Hours Menu


Please use the latest version from GitHub. I previously included the source but it now exceeds the length allowed by superuser.

Brogan
  • 101