Capturing Physical Power Button Event in Windows XP Embedded

Your best bet is to write a kmdf filter driver that filters the acpi power button device stack (typically the hw id is ACPI\PNPOCOC, but can be others in the case of a fixed feature power button, check device maanger on the machines you are interested in). you want to set a completion routine for the IOCTL IOCTL_GET_SYS_BUTTON_EVENT. In that completion routine, if SYS_BUTTON_POWER is set in the output buffer, the power button has been pressed (as compared to the sleep or wake button, SYS_BUTTON_SLEEP and _WAKE). What you do in the completion routine is up to you. Given what you describe you want to do I would

a) Have your notification application send an IOCTL WDFREQUEST to stack to be completed when a power button event occurs.

a. You put this pended IOCTL in manual WDFQUEUE (queue 1)

b. This will require you to register a custom device interface guid, you should probably use a ReferenceString to differentiate between your interface and the device interface used to register the buttons

b) When IOCTL_GET_SYS_BUTTON_EVENT comes to your driver, set a completion routine and send it down the stack. Send all other unknown IOCTLs down the stack too.

c) Pend the completed request in a different manual WDFQUEUE (queue 2) and complete the pended request in manual queue 1

d) The app sees the completed request, does whatever you want to do to notify the user, etc etc

e) The app sends another IOCTL down to tell the filter what to do with the pended system power event IOCTL. No matter what, you need to complete the IOCTL_GET_SYS_BUTTON_EVENT because the OS needs to process its completion so that it can send another one to get the next event.

a. You can complete it unmodified and let the OS see event and process it normally (Which is fine b/c the user has seen your notification)

b. You can remove the SYS_BUTTON_POWER flag from the output buffer and complete the request, allowing the OS to process “nothing” and resend the IOCTL

These IOCTLs and SYS_BUTTON values are not documented, the best you are going to get is http://blogs.msdn.com/b/doronh/archive/2006/09/08/746961.aspx

thx
d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Shuodan Chen
Sent: Tuesday, August 20, 2013 3:11 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Capturing Physical Power Button Event in Windows XP Embedded

Thanks for your feedback. Yes, if the users want an intentional shutdown, power button press for 4 seconds will do it. The software implementation is meant to be a preventive measure to minimize accidental shutdown.

Scheduled automatic power on will not work since it requires altering the BIOS, which is one of the constraints.

Shuodan

On Tue, Aug 20, 2013 at 2:56 PM, Jan Bottorff > wrote:
>Purpose: Prevent the users from accidentally shutting down the system when they press the power button because the systems, which are in the >field, are used for communication and therefore need to remain ON.

And what’s to prevent a user from holding down the power button for typically 4 seconds when they notice the system is not shutting down. That’s not something you can control from software. On most motherboards, holding the power button will force a power off.

Perhaps you would be better off setting an automatic power on at a scheduled time.

Jan


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev OSR is HIRING!! See http://www.osr.com/careers For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer