Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect whether a Windows reboot was due to Windows updates

A few applications on my PC have been doing a detection wether a restart was done by Windows Update or not. This is observable due to them restarting after the automatic Windows Update reboot.

This is very helpful since those applications reload changes, even unsaved changes or restore tabs (in case of a browser). Examples of applications that do this:

  • Google Chrome
  • Microsoft Visual Studio
  • Microsoft Paint

In all cases the applications save the state they were in before the reboot.

(My PC actually woke up from a standby state automatically, and rebooted itself while instaling updates. Too bad it didnt go back to standby after doing this.)

My question is: How do I programmatically detect this kind of reboot? It seems to be reliably detectable before the reboot.

The question How can I get the Windows last reboot reason might seem like a duplicate, but no answer said anything about updates.

I code in C#, so an answer in C# would be helpful, though I can read C and C++ too, for example.

like image 956
sinni800 Avatar asked Mar 10 '12 15:03

sinni800


People also ask

How do I find out what caused a Windows reboot?

To check the Event Viewer logs and determine why the device was shut down or restarted on Windows 10, use these steps: Open Start. Search for Event Viewer and click the top result to open the app. Browse the following path: Event Viewer > Windows Logs > System.

How can I tell if a system has been rebooted?

Just enter eventvwr in the run dialog (which can be called by pressing Win + R ). Under Windows Logs > System look for events from the "Kernel-Power". This will also show if the system unexpectedly restarted by a blue screen and show events prior to it.

How do I find out what caused a server reboot?

View Shutdown and Restart Log from Event ViewerOpen Event Viewer (press Win + R[Run] and type eventvwr). In the left pane, open “Windows Logs >> System.” In the middle pane, you will get a list of events that occurred while Windows was running. You can sort the event log with the Event ID.

How do I check for pending reboots?

Testing for a a Pending Reboot (The Easy Way) Simply open up your PowerShell console and type Install-Script Test-PendingReboot . Install-Script will download my PowerShell script from the PowerShell Gallery to C:\Program Files\WindowsPowerShell\Scripts.


1 Answers

See Application Restart:

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

and:

or if the computer needs to restart as the result of an update.

The applications aren't detecting the restart reason after the fact - they've been architected to use this API. There isn't (so far as I'm aware) a managed API for this.


A couple of clicks away is Saving data and application state when application is being closed due to a software update. Again, no managed API.

like image 86
Damien_The_Unbeliever Avatar answered Sep 19 '22 05:09

Damien_The_Unbeliever