Prevent Windows Update from shutting down Matlab session

5 次查看(过去 30 天)
I run Matlab simulations that sometimes take weeks to finish and, when Windows restarts due to an auto update, I lose all my work so I really need a way to stop auto restarts from interrupting my Matlab simulation.
Windows 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. Applications like Matlab receive shutdown notifications through the WM_QUERYENDSESSION and WM_ENDSESSION messages.
How can I use this to stop my simulations from shutting down and trashing all my work?
Sometimes my sims are straightforward and easy to start up again where I left off but often they are very complex simulations with lots of complex states using vast amounts of memory that it would be very difficult to get back to without running from the start again.

回答(2 个)

the cyclist
the cyclist 2024-5-28
When you say "stop my simulations from shutting down", do you mean "Have MATLAB pause the Windows update?"
As a Mac user, I don't know about that, but here are a couple other thoughts (that perhaps you have already had).
First, is there any to make your MATLAB simulation more robust against unexpected termination? I'm guessing that any code that's running that long is doing iterations of some kind. Can you save your workspace after each iteration (or every 10 or 100, if saving takes too long)? That's just good programming practice, and guards against any failure.
Second, have you looked at Windows settings, to prevent fully automated updates? I know that on a Mac, one has decent control over this.
  2 个评论
Michael
Michael 2024-5-28
Windows 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. Applications like Matlab receive shutdown notifications through the WM_QUERYENDSESSION and WM_ENDSESSION messages.
Sometimes my sims are straightforward and easy to start up again where I left off but often they are very complex simulations with lots of complex states using vast amounts of memory and that it would be very difficult to get back to without running from the start again.
Michael
Michael 2024-5-29
Also, Windows have been progressively making it more and more difficult to stop auto restarts by taking away or ignoring settings that used to allow this.

请先登录,再进行评论。


Michael
Michael 2024-5-29
编辑:Michael 2024-6-2
Matlab seems to ignore the shutdown messages. It could use them to delay the shutdown until the user is ready.
(Anyone with any clout at The Mathworks, please get them to act on the messages)
While we wait for this feature, I wrote a windows CMD batch file to stop Windows restarting:
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
you save this as a batch file (.bat) and use Task Scheduler to make it a Daily task, to run once an hour it will change your Active Hours so that Windows never restarts until you want it to.

类别

Help CenterFile Exchange 中查找有关 Application Deployment 的更多信息

产品


版本

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by