I'm writing Windows service application using WinAPIs and C++, and I'm curious if it's possible to detect when a user pushes the physical power button on the laptop/notebook?
Asked
Active
Viewed 1,036 times
0
-
http://stackoverflow.com/questions/4095517/how-can-i-execute-a-function-when-windows-shut-down and http://stackoverflow.com/questions/18392653/hook-system-power-button-in-windows – chris Jan 08 '14 at 03:52
-
@chris: The power button may be set to send computer to sleep, or hibernate, or "Do nothing" in that matter. As for the second link, what GUID do I need to use for `RegisterPowerSettingNotification`? – c00000fd Jan 08 '14 at 03:54
-
There seems to be a list here: http://www.pinvoke.net/default.aspx/user32/registerpowersettingnotification.html – chris Jan 08 '14 at 03:59
-
@chris: Thanks, but I don't see how that would apply to my request... am I missing something? – c00000fd Jan 08 '14 at 04:15
-
Both of them ask about the power button. I figured you might find something useful. – chris Jan 08 '14 at 04:36
-
Possible duplicate of [How to detect power button event and deny it on windows 7 from laptop](https://stackoverflow.com/questions/14433874/how-to-detect-power-button-event-and-deny-it-on-windows-7-from-laptop) – phuclv Jul 06 '18 at 03:23
-
[Hook system power button in Windows](https://stackoverflow.com/q/18392653/995714) – phuclv Jul 06 '18 at 03:24
1 Answers
-1
Not really. You can change the action to None
but you won’t get any notification.

Fredrik Wahlgren
- 107
- 1
- 4