Determine if Windows Restarted Due to Windows Updates

Several applications on my PC have detected whether the restart was performed by Windows Update or not. This can be observed due to a restart after an automatic restart of Windows Update.

This is very useful because these applications reload changes, even unsaved changes or recovery tabs (in the case of a browser). Examples of applications that do this:

  • Google chrome
  • Microsoft Visual Studio
  • Microsoft paint

In all cases, applications retain state which they were before rebooting.

(My computer really woke up from the standby state automatically and rebooted when updates were installed. Too bad that after that it did not return to standby mode.)

My question is: how do I programmatically detect such a reboot? It seems to be reliably detected before rebooting.

Question How can I get the last reason for restarting Windows, a duplicate may seem, but not a single answer said anything about the updates.

I am code in C #, so the answer to C # would be useful, although I could, for example, read C and C ++.

+7
source share
2 answers

See restarting the application :

An application can use Application Recovery and Restart (ARR) to save data and status information until the application exits due to an unhandled exception or when the application stops responding

and

or if the computer must restart as a result of the update.

Applications do not detect the reason for the restart after the fact - they were designed to use this API. There is no (as far as I know) managed API for this.


A few clicks Save data and application status when the application closes due to a software update . Again, no managed API.

+4
source

Usually, when Windows restarts, it restarts using shutdown.exe and the / g flag, which saves the state of all registered running programs before rebooting. You want to register your application to reboot. There is a good sample with documentation for this on MSDN. It is available in C # and C ++.

0
source

All Articles