8

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.

Community
  • 1
  • 1
sinni800
  • 1,451
  • 14
  • 29
  • You might also try asking at ServerFault. I saw some questions about rebooting Windows there. Try http://serverfault.com/search?q=windows+reboot – DOK Mar 10 '12 at 15:56
  • I want to programmatically (using a programming language) detect the reboot... Asking at ServerFault probably isn't right then – sinni800 Mar 10 '12 at 15:59
  • I think they could provide some information that you could use to write some code. Like you say, you "just need to know where to look and for what state". If you are really looking for an answer, I wouldn't be so quick to reject a potentially useful answer. – DOK Mar 10 '12 at 16:01
  • Which would be almost a clear answer that you could post down there :). So I have to look into the event log when receiving the shutdown event? @DOK Alright. It did seem a little rude there, I'll just edit it out – sinni800 Mar 10 '12 at 16:02
  • Do these applications actually behave any differently if you restart the computer in some other way, e.g., using shutdown /r at the command line? – Harry Johnston Mar 11 '12 at 21:47
  • @HarryJohnston For some strange reason: Yeah, they do. – sinni800 Mar 12 '12 at 21:44

2 Answers2

4

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.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
0

Normally when Windows Reboots, it performs a restart by using shutdown.exe and the /g flag which saves the state of all registered running programs before restart. What you want to do is to Register your application for restart. There is a good sample with documentation for this by MSDN. It is available in C# and C++.

Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65