Windows 7服务可以接收电源状态通知吗? [英] Can a Windows 7 Service receive Power State notifications?

查看:131
本文介绍了Windows 7服务可以接收电源状态通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Windows 7编写服务,由于要与之交互的设备,我需要了解电源状态的变化.我在MSDN上发现的有关这些事件的唯一通知是通过WM_POWERBROADCAST发出的.

现在,我已经知道我无法在服务中接收Windows消息.还有其他方法可以了解这种状态变化吗?我需要知道一台机器是否正在休眠,睡眠,正在做什么,以便避免意外行为.

I am writing a service for Windows 7, and because of the devices I''m interacting with, I need be aware of power state changes. The only notifications I''ve found on MSDN for these events come through WM_POWERBROADCAST.

Now, I already know I can''t recieve Windows messages in a service. Is there there any other way to become aware of this state change? I need to know if a machine is hibernating, sleeping, what-have-you, so I can avoid unexpected behavior.

推荐答案

您需要使用 RegisterServiceCtrlHandlerEx [ HandlerEx [ WM_POWERBROADCAST [
You need to use the RegisterServiceCtrlHandlerEx[^] when you register your HandlerEx[^] function.

When dwControl is SERVICE_CONTROL_POWEREVENT dwEventType provide the various PBT_ values you would receive in the wParam of a WM_POWERBROADCAST[^] event.

Best regards
Espen Harlinn


这篇关于Windows 7服务可以接收电源状态通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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