I want to handle power off button pressing on my notebook with Windows 7. I've configured power management options to do nothing on this event, so it will not turn off immediately, but i want to catch the moment when user presses power button. How it can be done in C++?
Asked
Active
Viewed 871 times
5
-
I doubt this is possible without writing vendor-specific code. From a quick glance there is no virtual key code for power-off, and there is no message/callback that tells you Windows 'was almost shut down'. – pezcode Feb 24 '12 at 13:47
-
2I think there should be some WMI (Windows Management Instrumentation) events for this. Hope this helps: http://msdn.microsoft.com/en-us/library/aa394101%28v=VS.85%29.aspx This is not specific to notebooks, nor is it specific to the power button alone. This applies to any means used to shutdown the machine. – Agnel Kurian Feb 24 '12 at 13:51
-
Thanks, I'll look this through this link. Also, seems like i can write code on C#, which is better, then I've expected. – madhead Feb 24 '12 at 13:58
-
A similar question has already been answered, have a look: http://stackoverflow.com/questions/4095517/how-can-i-execute-a-function-when-windows-shut-down – vissi2 Feb 24 '12 at 14:45
-
@AgnelKurian, make that an answer. – Ben Feb 24 '12 at 17:38
1 Answers
3
I think there should be some WMI (Windows Management Instrumentation) events for this. Hope this helps: http://msdn.microsoft.com/en-us/library/aa394101%28v=VS.85%29.aspx
This is not specific to notebooks, nor is it specific to the power button alone. This applies to any means used to shutdown the machine.

Agnel Kurian
- 57,975
- 43
- 146
- 217