检测在Windows重新启动是否是由于Windows更新重新启动、是由于、Windows

2023-09-04 02:11:15 作者:忽冷忽热//°

我的电脑上的一些应用程序已经做了检测阉重新启动被Windows Update或没有这样做。这是可观的,由于他们自动的Windows Update重启后重新启动。

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:

在谷歌浏览器 在微软的Visual Studio Microsoft画图

在所有情况下,应用程序保存在状态他们在重新启动之前。

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

(我的电脑居然醒了从待机状态自动,并重新启动本身,而instaling更新。太糟糕了,这样做后,它没有返回到待机状态。)

(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.

问题我如何获得Windows最后重新启动的原因看起来像一个重复的,但没有回答说,有关更新的东西。

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

我code在C#中,所以在C#的答案将是有益的,但​​我可以读C和C ++也一样,例如。

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

推荐答案

见的应用程序重新启动:

应用程序可以使用应用程序恢复和重启(ARR)来保存应用程序退出之前,数据和状态信息,由于未处理的异常,或当应用程序停止响应

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

或者如果计算机需要重新启动作为更新的结果。

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

该应用程序未检测出事后重启的原因 - 他们已经被设计为可使用此API。没有(至今我所知)一个托管API这一点。

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.

点几下路程的保存数据和应用程序状态,当应用程序被关闭,由于软件更新。再次,没有管理的API。

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.