检查计算机从休眠状态恢复的原因 [英] Check the reason the computer resumed from hibernation

查看:87
本文介绍了检查计算机从休眠状态恢复的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,使计算机休眠几个小时甚至一整周(使用WaitableTimer和WaitForSingleObject).

I am creating an application that puts the computer in hibernation for a few hours or even a full week (Using a WaitableTimer and WaitForSingleObject).

计算机可以唤醒的三个原因

There are three reasons why the computer could wake-up

  1. 可等待的计时器到期,并且计算机按计划恢复.
  2. 用户按下电源按钮以恢复计算机.
  3. 计算机意外打开.

前两个原因是完全可以接受的,它们是系统设计的目的.第三个原因当然不是很好.

The first two reasons are perfectly acceptable, they are what the system is designed for. The third reason is of course not so nice.

我希望能够区分这三个打开电源的原因.有什么办法吗?似乎在这里,在第一种情况下, WaitForSingleObject 方法应返回 WAIT_OBJECT_0

I would like to be able to differentiate between these three reasons for turning on. Is there any way to do this? It seems here that in the first scenario the WaitForSingleObject method should return WAIT_OBJECT_0 (source). If this is not the case it is either scenario 2 or 3 but I'm not sure how to differentiate between the two. Is there an API to check the reason for resuming from standby?

另一个(更好)的选项是禁止其他设备/软件唤醒计算机(例如,消除方案3).我不允许运行 powercfg -devicequery -wake_armed 时看到的所有设备的唤醒功能(当我现在运行命令时,它将返回NONE).是否可以通过类似的方式查看已安排计算机唤醒的所有(活动)软件?

Another (better) option is to prohibit other devices/software to wake up the computer (e.g. eliminating scenario 3). I have disallowed wake-up capabilities of all devices I see when I run powercfg -devicequery -wake_armed (when I run the command now the it returns NONE). Is there a similar way to see all (active) software that has scheduled the computer to wake up?

(如果对该软件设计的计算机有帮助,请使用Surface 3 Pro,并安装了随附的(和更新的)Windows 8.1 OS)

推荐答案

1/您可以查询Windows事件日志以查看导致计算机唤醒的原因:

1/ You can query the Windows Event Log to see what caused the computer to wake up:

  var log = new EventLog("System");
  var wakeUpEntry = (from entry in log.Entries.Cast<EventLogEntry>()
    where entry.Source == "Microsoft-Windows-Power-Troubleshooter"
          && entry.InstanceId == 1
    orderby entry.TimeWritten descending
    select entry).First();

  Console.WriteLine("{0}", wakeUpEntry.Message);

消息中有一个唤醒源"条目(例如"4USB Root Hub"),如果您确实想通过编程方式进行处理,则可以对其进行解析.

The message has a "Wake Source" entry ("4USB Root Hub" for instance) that you can parse if you really want to do it programmatically.

2/您可以使用以下命令检查是否有Windows或外部程序在系统上设置了唤醒计时器:

2/ You can check if any Windows or external program has set a wake timer on the system with this command:

powercfg -waketimers

如果命令(您或本命令)均未显示任何内容,则大多数可能的原因已消除.

If neither command (yours nor this one) shows anything, most of the possible causes have been eliminated.

3/您甚至可以在本机上完全禁用唤醒定时器.在Windows 电源选项计划设置高级计划设置中,禁用睡眠下的允许唤醒计时器部分.我不确定Windows Scheduled Maintenance是否受此影响,但是您当然也可以将其关闭.

3/ You can even disable wake timers completely on this machine. In Windows Power Options, Plan Settings, Advanced Plan Settings, Disable Allow wake timers under the Sleep section. I'm not sure if Windows Scheduled Maintenance is affected by this, but you can also turn it off, of course.

4/另一安全措施:确保在BIOS设置中没有设备可配置的任何时间将其唤醒.

4/ Another safety: make sure no devices in the BIOS settings are allowed to wake the PC up, whenever it's configurable.

这篇关于检查计算机从休眠状态恢复的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆