【问题标题】:How to programmatically bring a laptop into Sleep mode如何以编程方式使笔记本电脑进入睡眠模式
【发布时间】:2010-09-28 17:19:31
【问题描述】:

我可以使用哪些 API 或工具来查询系统的功能并选择最适合将 PC 置于睡眠、休眠或关机模式的模式?

感谢您的任何指点。

【问题讨论】:

    标签: .net api shutdown sleep-mode hibernate-mode


    【解决方案1】:

    您可以使用 API:

    Declare Function SetSuspendState Lib "PowrProf" (ByVal Hibernate As Integer, ByVal ForceCritical As Integer, ByVal DisableWakeEvent As Integer) As Integer
    
    SetSuspendState(0, 0, 0) 'Sleep without forcing and ?no? wake events
    SetSuspendState(1, 0, 0) 'Hibernate without forcing and ?no? wake events
    

    将 Hibernate 设置为 1(True) 以休眠或 0(False) 以休眠。

    请参阅 API here

    【讨论】:

      【解决方案2】:

      查看 SystemInformation.PowerStatus,然后您可以调用 Application.SetSuspendState 使 PC 进入睡眠或休眠状态,例如:

      Application.SetSuspendState(PowerState.Hibernate, true, true);
      

      【讨论】:

      • 完整方法签名:Application.SetSuspendState([PowerState.Hibernate | PowerState.Suspend], bool force, bool disableWakeEvent)
      • 根据应用需求,我建议仔细考虑真实、真实的参数。为 'force' 参数发送 true 可能会导致某些应用程序或驱动程序问题恢复,因为它们不会被发送暂停请求。如果您在醒来时遇到问题,请尝试切换 true、true 到 false、true 或 false、false
      • 注意:这是在 System.Windows.Forms 命名空间中,因此如果您使用的是 WPF 应用程序,您需要添加对 System.Windows.Forms DLL 的引用并使用 System 调用它.Windows.Forms.Application.SetSuspendState(PowerState.Suspend, true, true)
      猜你喜欢
      • 2020-10-24
      • 2022-08-23
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2011-09-08
      • 1970-01-01
      • 2015-06-09
      • 2016-12-27
      相关资源
      最近更新 更多