简体   繁体   English

如何控制电源键按下关机?

[英]How to control power button press shutdown?

I'm working on a kiosk style application where I need to control the shutdown/restart of the PC when the power button is pressed.我正在开发一个自助服务终端风格的应用程序,我需要在按下电源按钮时控制 PC 的关机/重启。 Thanks to this post , I'm about 90% of the way there.多亏了这篇文章,我已经完成了大约 90% 的工作。

  1. In control panel set the acpi power button press action to shutdown.在控制面板中将 acpi 电源按钮按下动作设置为关机。
  2. Listen for the WndProc message WM_QUERYENDSESSION监听 WndProc 消息 WM_QUERYENDSESSION
  3. When received issue the completely undocumented:收到问题时,完全没有记录:

     [DllImport("user32.dll", SetLastError = true)] static extern int CancelShutdown();
  4. Return from the WndProc and bring up my own message box asking the user to Shutdown / Restart or Cancel, and respond to their action.从 WndProc 返回并显示我自己的消息框,要求用户关闭/重新启动或取消,并响应他们的操作。

Everything works well if I do a start / shutdown from the task bar (I can issue theses as fast as I want).如果我从任务栏开始/关闭,一切都会很好(我可以按我想要的速度发布论文)。 Everything also works well the first time I press the power button.我第一次按下电源按钮时,一切都运行良好。 On subsequent power button presses though I see a minute or so delay before I receive the WM_QUERYENDSESSION message.在随后按下电源按钮时,虽然在收到 WM_QUERYENDSESSION 消息之前我看到了大约一分钟左右的延迟。

Is there a setting or registry entry about how often windows will issue an ACPI event?是否有关于 Windows 多久发出一次 ACPI 事件的设置或注册表项? I know it's not the hardware because under linux the same machine will fire the ACPI event as fast as I can press the button.我知道这不是硬件,因为在 linux 下,同一台机器会以我按下按钮的速度触发 ACPI 事件。

Thanks.谢谢。

Calling in some favors at work, I was able to take this question directly to Microsoft support.在工作中寻求帮助,我能够将这个问题直接提交给 Microsoft 支持。 On my third support engineer, I was essentially told this is not possible at an application level .在我的第三个支持工程师那里,我基本上被告知这在应用程序级别是不可能 It was his belief that calling the undocumented CancelShutdown() "confuses" the power manager or acpi driver which leads to the WM_QUERYENDSESSION message delay.他认为调用未记录的CancelShutdown() “混淆”电源管理器或 acpi 驱动程序,从而导致WM_QUERYENDSESSION消息延迟。 Since the CancelShutdown() is undocumented, MS is not willing investigate further.由于CancelShutdown()没有记录,MS 不愿意进一步调查。

So, how do you hook power button presses?那么,你如何挂钩电源按钮按下? You need to write a device driver, specifically an ACPI Filter Driver .您需要编写一个设备驱动程序,特别是ACPI Filter Driver We are investigating this now.我们现在正在调查此事。

I don't think it is possible unless you speak with your hardware manufacturer or hardwire the start-button so that it doesn't send a signal to the hardware which handles this.我认为这是不可能的,除非您与硬件制造商交谈或硬连线启动按钮,以便它不会向处理此问题的硬件发送信号。 You can only delay it but even that would not give you 100% guarantee I guess.你只能延迟它,但我猜即使那样也不能给你 100% 的保证。

Windows 8.1 will (maybe) bring a Kiosk Mode. Windows 8.1 将(可能)带来 Kiosk 模式。 Maybe that is what you are looking for ;-)也许这就是你要找的 ;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM