Capturing Physical Power Button Event in Windows XP Embedded

Hello,
I would like to capture the physical power button event in Window XP
Embedded system when the user presses it during OS so our software can
perform an action in response. Please let me know your recommendations for
implementing this sequence. I appreciate your guidance and details you can
offer.
Thanks for your help,
Shuodan

Shuodan Chen wrote:

I would like to capture the physical power button event in
Window XP Embedded system when the user presses it during OS so our
software can perform an action in response. Please let me know your
recommendations for implementing this sequence. I appreciate your
guidance and details you can offer.

If you mean a simple press-and-release, that should initiate a normal
system shutdown, and you can use the WM_SHUTDOWN message to get that
notification.

If you mean the 5-second-press-and-hold, that’s handled by power supply
hardware and cannot be trapped.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Hi Tim,
Thank you for your response.

  1. Would you mind give me a detailed rundown of the series of calls and
    events that occur in OS before and after WM_SHUTDOWN?
  2. Does the implementation require creating device drivers in user mode
    and/or kernel mode?
    Thanks,
    Shuodan

On Mon, Aug 19, 2013 at 1:57 PM, Tim Roberts wrote:

> Shuodan Chen wrote:
> >
> > I would like to capture the physical power button event in
> > Window XP Embedded system when the user presses it during OS so our
> > software can perform an action in response. Please let me know your
> > recommendations for implementing this sequence. I appreciate your
> > guidance and details you can offer.
>
> If you mean a simple press-and-release, that should initiate a normal
> system shutdown, and you can use the WM_SHUTDOWN message to get that
> notification.
>
> If you mean the 5-second-press-and-hold, that’s handled by power supply
> hardware and cannot be trapped.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> 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
>

Shuodan Chen wrote:

  1. Would you mind give me a detailed rundown of the series of calls
    and events that occur in OS before and after WM_SHUTDOWN?

I’m not sure what you mean, and I’m not sure what good it would do you
to know this. If your application needs to do something when the system
shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
message in your app’s message loop. There are no promises about the
ordering of those messages. Kernel services will still be active, so
you can save things to disk, although an intelligent app will save its
state periodically, because not all shutdowns are clean.

  1. Does the implementation require creating device drivers in user
    mode and/or kernel mode?

No. The system sends this message when it is ordered to shut down,
probably by the ACPI driver in response to a notice from the BIOS.
There are ways to catch this message in a GUI app, in a console app, or
in a service.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Hi Tim,
Thanks for the detailed info. Basically, I want to customize the power
button functionality. Let’s say I write a quick standalone .cpp test
program, int main (), to have notepad open after the user presses the *
physical* power button, what would be the best way to implement that?
Thanks,
Shuodan

On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts wrote:

> Shuodan Chen wrote:
> >
> > 1) Would you mind give me a detailed rundown of the series of calls
> > and events that occur in OS before and after WM_SHUTDOWN?
>
> I’m not sure what you mean, and I’m not sure what good it would do you
> to know this. If your application needs to do something when the system
> shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
> message in your app’s message loop. There are no promises about the
> ordering of those messages. Kernel services will still be active, so
> you can save things to disk, although an intelligent app will save its
> state periodically, because not all shutdowns are clean.
>
>
> > 3) Does the implementation require creating device drivers in user
> > mode and/or kernel mode?
>
> No. The system sends this message when it is ordered to shut down,
> probably by the ACPI driver in response to a notice from the BIOS.
> There are ways to catch this message in a GUI app, in a console app, or
> in a service.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
>
> —
> 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
>

The best way to implement that would be to know a lot about your BIOS and to customize it to expose a custom device to the OS for which you would write a custom driver that would communicate with a user mode service that would interact with multiple sessions and decide to CreateProcessAsUser some number of instances of Notepad in response to a hardware event that happened to by physically wired to the power button on your altered bios and perhaps take some further action like ExitWindowsEx

If what you really want to do is display something to a user when the system is about to shutdown, then skip all of the BIOS and KM components and either wait for WM_SHUTOWN or write a service and listen for the shutdown notifications and than do your thing (cognizant that the user may ignore and override your program)

if you want to repurpose the physical power button, then BIOS alterations are in your future and don’t expect your solution to be portable across anything

“Shuodan Chen” wrote in message news:xxxxx@ntdev…
Hi Tim,
Thanks for the detailed info. Basically, I want to customize the power button functionality. Let’s say I write a quick standalone .cpp test program, int main (), to have notepad open after the user presses the physical power button, what would be the best way to implement that?
Thanks,
Shuodan

On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts wrote:

Shuodan Chen wrote:
>
> 1) Would you mind give me a detailed rundown of the series of calls
> and events that occur in OS before and after WM_SHUTDOWN?

I’m not sure what you mean, and I’m not sure what good it would do you
to know this. If your application needs to do something when the system
shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
message in your app’s message loop. There are no promises about the
ordering of those messages. Kernel services will still be active, so
you can save things to disk, although an intelligent app will save its
state periodically, because not all shutdowns are clean.

> 3) Does the implementation require creating device drivers in user
> mode and/or kernel mode?

No. The system sends this message when it is ordered to shut down,
probably by the ACPI driver in response to a notice from the BIOS.
There are ways to catch this message in a GUI app, in a console app, or
in a service.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.


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

What specifically do you want to happen when the button is pressed? Overriding it to custom actions is not a good design

d

Bent from my phone


From: Shuodan Chenmailto:xxxxx
Sent: ?8/?19/?2013 5:21 PM
To: Windows System Software Devs Interest Listmailto:xxxxx
Subject: Re: [ntdev] Capturing Physical Power Button Event in Windows XP Embedded

Hi Tim,
Thanks for the detailed info. Basically, I want to customize the power button functionality. Let’s say I write a quick standalone .cpp test program, int main (), to have notepad open after the user presses the physical power button, what would be the best way to implement that?
Thanks,
Shuodan

On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts > wrote:
Shuodan Chen wrote:
>
> 1) Would you mind give me a detailed rundown of the series of calls
> and events that occur in OS before and after WM_SHUTDOWN?

I’m not sure what you mean, and I’m not sure what good it would do you
to know this. If your application needs to do something when the system
shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
message in your app’s message loop. There are no promises about the
ordering of those messages. Kernel services will still be active, so
you can save things to disk, although an intelligent app will save its
state periodically, because not all shutdowns are clean.

> 3) Does the implementation require creating device drivers in user
> mode and/or kernel mode?

No. The system sends this message when it is ordered to shut down,
probably by the ACPI driver in response to a notice from the BIOS.
There are ways to catch this message in a GUI app, in a console app, or
in a service.


Tim Roberts, xxxxx@probo.commailto:xxxxx
Providenza & Boekelheide, Inc.


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</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

Thanks for all the great suggestions! Here is the scenario. When the
power button is pressed, the OS or an app will respond with an action
(other than shutting down) so that the user knows the button event
occurred. The action can be anything from system restart to screensaver.
What I would like to find out are the file types required (ie. .exe, .inf,
.dll), the sequence of key API methods, class objects, and enumerations I
need for the implementation to capture the button event in XP.

Regarding BIOS, I did look into it, but we prefer a programmable solution
or modifying a setting in OS.

Thanks for your help,
Shuodan

On Mon, Aug 19, 2013 at 5:46 PM, Doron Holan wrote:

> What specifically do you want to happen when the button is pressed?
> Overriding it to custom actions is not a good design
>
> d
>
> Bent from my phone
> ------------------------------
> From: Shuodan Chen
> Sent: 8/19/2013 5:21 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] Capturing Physical Power Button Event in Windows XP
> Embedded
>
> Hi Tim,
> Thanks for the detailed info. Basically, I want to customize the
> power button functionality. Let’s say I write a quick standalone .cpp test
> program, int main (), to have notepad open after the user presses the
> physical
power button, what would be the best way to implement that?
> Thanks,
> Shuodan
>
>
>
>
>
> On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts wrote:
>
>> Shuodan Chen wrote:
>> >
>> > 1) Would you mind give me a detailed rundown of the series of calls
>> > and events that occur in OS before and after WM_SHUTDOWN?
>>
>> I’m not sure what you mean, and I’m not sure what good it would do you
>> to know this. If your application needs to do something when the system
>> shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
>> message in your app’s message loop. There are no promises about the
>> ordering of those messages. Kernel services will still be active, so
>> you can save things to disk, although an intelligent app will save its
>> state periodically, because not all shutdowns are clean.
>>
>>
>> > 3) Does the implementation require creating device drivers in user
>> > mode and/or kernel mode?
>>
>> No. The system sends this message when it is ordered to shut down,
>> probably by the ACPI driver in response to a notice from the BIOS.
>> There are ways to catch this message in a GUI app, in a console app, or
>> in a service.
>>
>> –
>> Tim Roberts, xxxxx@probo.com
>> Providenza & Boekelheide, Inc.
>>
>>
>> —
>> 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
>
> —
> 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
>

WM_ENDSESSION is sent when the current session is terminating, such as via
a logoff. WM_SHUTDOWN is sent when the system is shutting down, for
whatever reasons the kernel as chosen. These include a user-initiated
shutdown sequence, a low-power condition for a portable, or a low-voltage
notification from an Uninterruptible Power Supply during a power outage.
An earlier message seemed to indicate that the order of these two messages
is not guaranteed.

Therefore, if you are responding to a shutdown, there are already
mechanisms in place to handle this. But your scenario of bringing up
Notepad doesn’t make much sense during a shutdown. This sounds like a
desire to make the “power off” button do something other than turning off
the power. As already pointed out, this requires BIOS changes and would
be a Really Bad Idea. If you intercept the messages in app space and try
to start another app, this likewise makes no sense, because you are in the
middle of a shutdown, which may proceed independent of any opinion you may
be offering to the contrary (like a low-battery shutdown). These messages
are intended to notify you to save state, and that is expected to take
place, ideally, in a very short time (the exact time allowed may be
documented). Bringing up Notepad, or any other app that requires user
interaction, would certainly violate this window.

As usual, this question is more along the lines of asking about the best
glue, without a clear statement of purpose about why a flying pig solves
the problem.

Note that if the purpose is to have some button that can send a
notification to a program, and the only currently-available button is the
power button, then the design of the hardware is wrong. I’ve seen various
USB keypads with one, two, three,or some small value of N buttons, which
would serve the purpose. So why do you care about the power button?
joe

Thanks for all the great suggestions! Here is the scenario. When the
power button is pressed, the OS or an app will respond with an action
(other than shutting down) so that the user knows the button event
occurred. The action can be anything from system restart to screensaver.
What I would like to find out are the file types required (ie. .exe, .inf,
.dll), the sequence of key API methods, class objects, and enumerations I
need for the implementation to capture the button event in XP.

Regarding BIOS, I did look into it, but we prefer a programmable solution
or modifying a setting in OS.

Thanks for your help,
Shuodan

On Mon, Aug 19, 2013 at 5:46 PM, Doron Holan
wrote:
>
>> What specifically do you want to happen when the button is pressed?
>> Overriding it to custom actions is not a good design
>>
>> d
>>
>> Bent from my phone
>> ------------------------------
>> From: Shuodan Chen
>> Sent: 8/19/2013 5:21 PM
>> To: Windows System Software Devs Interest List
>> Subject: Re: [ntdev] Capturing Physical Power Button Event in Windows XP
>> Embedded
>>
>> Hi Tim,
>> Thanks for the detailed info. Basically, I want to customize the
>> power button functionality. Let’s say I write a quick standalone .cpp
>> test
>> program, int main (), to have notepad open after the user presses the
>> physical
power button, what would be the best way to implement that?
>> Thanks,
>> Shuodan
>>
>>
>>
>>
>>
>> On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts wrote:
>>
>>> Shuodan Chen wrote:
>>> >
>>> > 1) Would you mind give me a detailed rundown of the series of
>>> calls
>>> > and events that occur in OS before and after WM_SHUTDOWN?
>>>
>>> I’m not sure what you mean, and I’m not sure what good it would do you
>>> to know this. If your application needs to do something when the
>>> system
>>> shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
>>> message in your app’s message loop. There are no promises about the
>>> ordering of those messages. Kernel services will still be active, so
>>> you can save things to disk, although an intelligent app will save its
>>> state periodically, because not all shutdowns are clean.
>>>
>>>
>>> > 3) Does the implementation require creating device drivers in user
>>> > mode and/or kernel mode?
>>>
>>> No. The system sends this message when it is ordered to shut down,
>>> probably by the ACPI driver in response to a notice from the BIOS.
>>> There are ways to catch this message in a GUI app, in a console app, or
>>> in a service.
>>>
>>> –
>>> Tim Roberts, xxxxx@probo.com
>>> Providenza & Boekelheide, Inc.
>>>
>>>
>>> —
>>> 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
>>
>> —
>> 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

Thanks to everyone for your helpful inputs!! They are much appreciated.

The purpose, goal, constraints, and possible solutions are listed below for
additional clarity:

*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*.

*Goal:** *Software implementation to *listen for the power button
event*and perform some action as feedback to the user that the power
button event
occurred.

*Constraints:*

  • Hardware solution would be very difficult and costly to scale
  • BIOS solution is not feasible for the same reason as Hardware solution

*Possible Software Solutions Open for Discussion:*

Thanks for your guidance,
Shuodan

On Mon, Aug 19, 2013 at 10:06 PM, wrote:

> WM_ENDSESSION is sent when the current session is terminating, such as via
> a logoff. WM_SHUTDOWN is sent when the system is shutting down, for
> whatever reasons the kernel as chosen. These include a user-initiated
> shutdown sequence, a low-power condition for a portable, or a low-voltage
> notification from an Uninterruptible Power Supply during a power outage.
> An earlier message seemed to indicate that the order of these two messages
> is not guaranteed.
>
> Therefore, if you are responding to a shutdown, there are already
> mechanisms in place to handle this. But your scenario of bringing up
> Notepad doesn’t make much sense during a shutdown. This sounds like a
> desire to make the “power off” button do something other than turning off
> the power. As already pointed out, this requires BIOS changes and would
> be a Really Bad Idea. If you intercept the messages in app space and try
> to start another app, this likewise makes no sense, because you are in the
> middle of a shutdown, which may proceed independent of any opinion you may
> be offering to the contrary (like a low-battery shutdown). These messages
> are intended to notify you to save state, and that is expected to take
> place, ideally, in a very short time (the exact time allowed may be
> documented). Bringing up Notepad, or any other app that requires user
> interaction, would certainly violate this window.
>
> As usual, this question is more along the lines of asking about the best
> glue, without a clear statement of purpose about why a flying pig solves
> the problem.
>
> Note that if the purpose is to have some button that can send a
> notification to a program, and the only currently-available button is the
> power button, then the design of the hardware is wrong. I’ve seen various
> USB keypads with one, two, three,or some small value of N buttons, which
> would serve the purpose. So why do you care about the power button?
> joe
>
> > Thanks for all the great suggestions! Here is the scenario. When the
> > power button is pressed, the OS or an app will respond with an action
> > (other than shutting down) so that the user knows the button event
> > occurred. The action can be anything from system restart to screensaver.
> > What I would like to find out are the file types required (ie. .exe,
> .inf,
> > .dll), the sequence of key API methods, class objects, and enumerations I
> > need for the implementation to capture the button event in XP.
> >
> > Regarding BIOS, I did look into it, but we prefer a programmable solution
> > or modifying a setting in OS.
> >
> > Thanks for your help,
> > Shuodan
> >
> >
> > On Mon, Aug 19, 2013 at 5:46 PM, Doron Holan
> > wrote:
> >
> >> What specifically do you want to happen when the button is pressed?
> >> Overriding it to custom actions is not a good design
> >>
> >> d
> >>
> >> Bent from my phone
> >> ------------------------------
> >> From: Shuodan Chen
> >> Sent: 8/19/2013 5:21 PM
> >> To: Windows System Software Devs Interest List
> >> Subject: Re: [ntdev] Capturing Physical Power Button Event in Windows XP
> >> Embedded
> >>
> >> Hi Tim,
> >> Thanks for the detailed info. Basically, I want to customize the
> >> power button functionality. Let’s say I write a quick standalone .cpp
> >> test
> >> program, int main (), to have notepad open after the user presses the
> >> physical
power button, what would be the best way to implement that?
> >> Thanks,
> >> Shuodan
> >>
> >>
> >>
> >>
> >>
> >> On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts wrote:
> >>
> >>> Shuodan Chen wrote:
> >>> >
> >>> > 1) Would you mind give me a detailed rundown of the series of
> >>> calls
> >>> > and events that occur in OS before and after WM_SHUTDOWN?
> >>>
> >>> I’m not sure what you mean, and I’m not sure what good it would do you
> >>> to know this. If your application needs to do something when the
> >>> system
> >>> shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
> >>> message in your app’s message loop. There are no promises about the
> >>> ordering of those messages. Kernel services will still be active, so
> >>> you can save things to disk, although an intelligent app will save its
> >>> state periodically, because not all shutdowns are clean.
> >>>
> >>>
> >>> > 3) Does the implementation require creating device drivers in user
> >>> > mode and/or kernel mode?
> >>>
> >>> No. The system sends this message when it is ordered to shut down,
> >>> probably by the ACPI driver in response to a notice from the BIOS.
> >>> There are ways to catch this message in a GUI app, in a console app, or
> >>> in a service.
> >>>
> >>> –
> >>> Tim Roberts, xxxxx@probo.com
> >>> Providenza & Boekelheide, Inc.
> >>>
> >>>
> >>> —
> >>> 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
> >>
> >> —
> >> 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
>
>
>
> —
> 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
>

Under Possible Software Solutions, I would like to replace the 3rd bullet
point with the following:

Thanks,
Shuodan

On Tue, Aug 20, 2013 at 12:04 PM, Shuodan Chen wrote:

> Thanks to everyone for your helpful inputs!! They are much appreciated.
>
> The purpose, goal, constraints, and possible solutions are listed below
> for additional clarity:
>
> 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.
>
> Goal:* *Software implementation to listen for the power button eventand perform some action as feedback to the user that the power button event
> occurred.
>
> Constraints:
>
> - Hardware solution would be very difficult and costly to scale
> - BIOS solution is not feasible for the same reason as Hardware
> solution
>
> Possible Software Solutions Open for Discussion:
>
> - Add additional functionalities to “when I press the power button”
> in Power Options Advanced Panel
> - Implement a program involving IOCTL as described in
> http://blogs.msdn.com/b/doronh/archive/2006/09/08/746834.aspx
> - Implement a program relating to Win32_ShutdownEvent Class
> http://msdn.microsoft.com/en-us/library/aa394101(v=VS.85).aspx
> - Implement a program relating to the power_action_policy in system
> power policy structure
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa373225(v=vs.85).aspx
>
> - Other suggestions?
>
> Thanks for your guidance,
> Shuodan
>
>
>
> On Mon, Aug 19, 2013 at 10:06 PM, wrote:
>
>> WM_ENDSESSION is sent when the current session is terminating, such as via
>> a logoff. WM_SHUTDOWN is sent when the system is shutting down, for
>> whatever reasons the kernel as chosen. These include a user-initiated
>> shutdown sequence, a low-power condition for a portable, or a low-voltage
>> notification from an Uninterruptible Power Supply during a power outage.
>> An earlier message seemed to indicate that the order of these two messages
>> is not guaranteed.
>>
>> Therefore, if you are responding to a shutdown, there are already
>> mechanisms in place to handle this. But your scenario of bringing up
>> Notepad doesn’t make much sense during a shutdown. This sounds like a
>> desire to make the “power off” button do something other than turning off
>> the power. As already pointed out, this requires BIOS changes and would
>> be a Really Bad Idea. If you intercept the messages in app space and try
>> to start another app, this likewise makes no sense, because you are in the
>> middle of a shutdown, which may proceed independent of any opinion you may
>> be offering to the contrary (like a low-battery shutdown). These messages
>> are intended to notify you to save state, and that is expected to take
>> place, ideally, in a very short time (the exact time allowed may be
>> documented). Bringing up Notepad, or any other app that requires user
>> interaction, would certainly violate this window.
>>
>> As usual, this question is more along the lines of asking about the best
>> glue, without a clear statement of purpose about why a flying pig solves
>> the problem.
>>
>> Note that if the purpose is to have some button that can send a
>> notification to a program, and the only currently-available button is the
>> power button, then the design of the hardware is wrong. I’ve seen various
>> USB keypads with one, two, three,or some small value of N buttons, which
>> would serve the purpose. So why do you care about the power button?
>> joe
>>
>> > Thanks for all the great suggestions! Here is the scenario. When the
>> > power button is pressed, the OS or an app will respond with an action
>> > (other than shutting down) so that the user knows the button event
>> > occurred. The action can be anything from system restart to
>> screensaver.
>> > What I would like to find out are the file types required (ie. .exe,
>> .inf,
>> > .dll), the sequence of key API methods, class objects, and enumerations
>> I
>> > need for the implementation to capture the button event in XP.
>> >
>> > Regarding BIOS, I did look into it, but we prefer a programmable
>> solution
>> > or modifying a setting in OS.
>> >
>> > Thanks for your help,
>> > Shuodan
>> >
>> >
>> > On Mon, Aug 19, 2013 at 5:46 PM, Doron Holan
>> > wrote:
>> >
>> >> What specifically do you want to happen when the button is pressed?
>> >> Overriding it to custom actions is not a good design
>> >>
>> >> d
>> >>
>> >> Bent from my phone
>> >> ------------------------------
>> >> From: Shuodan Chen
>> >> Sent: 8/19/2013 5:21 PM
>> >> To: Windows System Software Devs Interest List
>> >> Subject: Re: [ntdev] Capturing Physical Power Button Event in Windows
>> XP
>> >> Embedded
>> >>
>> >> Hi Tim,
>> >> Thanks for the detailed info. Basically, I want to customize the
>> >> power button functionality. Let’s say I write a quick standalone .cpp
>> >> test
>> >> program, int main (), to have notepad open after the user presses the
>> >> physical
power button, what would be the best way to implement that?
>> >> Thanks,
>> >> Shuodan
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts wrote:
>> >>
>> >>> Shuodan Chen wrote:
>> >>> >
>> >>> > 1) Would you mind give me a detailed rundown of the series of
>> >>> calls
>> >>> > and events that occur in OS before and after WM_SHUTDOWN?
>> >>>
>> >>> I’m not sure what you mean, and I’m not sure what good it would do
>> you
>> >>> to know this. If your application needs to do something when the
>> >>> system
>> >>> shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
>> >>> message in your app’s message loop. There are no promises about the
>> >>> ordering of those messages. Kernel services will still be active, so
>> >>> you can save things to disk, although an intelligent app will save its
>> >>> state periodically, because not all shutdowns are clean.
>> >>>
>> >>>
>> >>> > 3) Does the implementation require creating device drivers in
>> user
>> >>> > mode and/or kernel mode?
>> >>>
>> >>> No. The system sends this message when it is ordered to shut down,
>> >>> probably by the ACPI driver in response to a notice from the BIOS.
>> >>> There are ways to catch this message in a GUI app, in a console app,
>> or
>> >>> in a service.
>> >>>
>> >>> –
>> >>> Tim Roberts, xxxxx@probo.com
>> >>> Providenza & Boekelheide, Inc.
>> >>>
>> >>>
>> >>> —
>> >>> 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
>> >>
>> >> —
>> >> 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
>>
>>
>>
>> —
>> 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
>>
>
>

If you don’t want the power button to do anything, go to powercfg.cpl and configure the power button action to “Nothing”. You can do this with group policy as well IIRC

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

Under Possible Software Solutions, I would like to replace the 3rd bullet point with the following:
* Implement a program relating to reboot method under Win32_OperatingSystem Class http://msdn.microsoft.com/en-us/library/windows/desktop/aa393010(v=vs.85).aspx
Thanks,
Shuodan

On Tue, Aug 20, 2013 at 12:04 PM, Shuodan Chen > wrote:
Thanks to everyone for your helpful inputs!! They are much appreciated.

The purpose, goal, constraints, and possible solutions are listed below for additional clarity:

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.

Goal: Software implementation to listen for the power button event and perform some action as feedback to the user that the power button event occurred.

Constraints:

* Hardware solution would be very difficult and costly to scale
* BIOS solution is not feasible for the same reason as Hardware solution
Possible Software Solutions Open for Discussion:

* Add additional functionalities to “when I press the power button” in Power Options Advanced Panel
* Implement a program involving IOCTL as described in http://blogs.msdn.com/b/doronh/archive/2006/09/08/746834.aspx
* Implement a program relating to Win32_ShutdownEvent Class http://msdn.microsoft.com/en-us/library/aa394101(v=VS.85).aspx
* Implement a program relating to the power_action_policy in system power policy structure http://msdn.microsoft.com/en-us/library/windows/desktop/aa373225(v=vs.85).aspx
* Other suggestions?
Thanks for your guidance,
Shuodan

On Mon, Aug 19, 2013 at 10:06 PM, > wrote:
WM_ENDSESSION is sent when the current session is terminating, such as via
a logoff. WM_SHUTDOWN is sent when the system is shutting down, for
whatever reasons the kernel as chosen. These include a user-initiated
shutdown sequence, a low-power condition for a portable, or a low-voltage
notification from an Uninterruptible Power Supply during a power outage.
An earlier message seemed to indicate that the order of these two messages
is not guaranteed.

Therefore, if you are responding to a shutdown, there are already
mechanisms in place to handle this. But your scenario of bringing up
Notepad doesn’t make much sense during a shutdown. This sounds like a
desire to make the “power off” button do something other than turning off
the power. As already pointed out, this requires BIOS changes and would
be a Really Bad Idea. If you intercept the messages in app space and try
to start another app, this likewise makes no sense, because you are in the
middle of a shutdown, which may proceed independent of any opinion you may
be offering to the contrary (like a low-battery shutdown). These messages
are intended to notify you to save state, and that is expected to take
place, ideally, in a very short time (the exact time allowed may be
documented). Bringing up Notepad, or any other app that requires user
interaction, would certainly violate this window.

As usual, this question is more along the lines of asking about the best
glue, without a clear statement of purpose about why a flying pig solves
the problem.

Note that if the purpose is to have some button that can send a
notification to a program, and the only currently-available button is the
power button, then the design of the hardware is wrong. I’ve seen various
USB keypads with one, two, three,or some small value of N buttons, which
would serve the purpose. So why do you care about the power button?
joe

> Thanks for all the great suggestions! Here is the scenario. When the
> power button is pressed, the OS or an app will respond with an action
> (other than shutting down) so that the user knows the button event
> occurred. The action can be anything from system restart to screensaver.
> What I would like to find out are the file types required (ie. .exe, .inf,
> .dll), the sequence of key API methods, class objects, and enumerations I
> need for the implementation to capture the button event in XP.
>
> Regarding BIOS, I did look into it, but we prefer a programmable solution
> or modifying a setting in OS.
>
> Thanks for your help,
> Shuodan
>
>
> On Mon, Aug 19, 2013 at 5:46 PM, Doron Holan
> >wrote:
>
>> What specifically do you want to happen when the button is pressed?
>> Overriding it to custom actions is not a good design
>>
>> d
>>
>> Bent from my phone
>> ------------------------------
>> From: Shuodan Chen >
>> Sent: 8/19/2013 5:21 PM
>> To: Windows System Software Devs Interest List >
>> Subject: Re: [ntdev] Capturing Physical Power Button Event in Windows XP
>> Embedded
>>
>> Hi Tim,
>> Thanks for the detailed info. Basically, I want to customize the
>> power button functionality. Let’s say I write a quick standalone .cpp
>> test
>> program, int main (), to have notepad open after the user presses the
>> physical
power button, what would be the best way to implement that?
>> Thanks,
>> Shuodan
>>
>>
>>
>>
>>
>> On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts > wrote:
>>
>>> Shuodan Chen wrote:
>>> >
>>> > 1) Would you mind give me a detailed rundown of the series of
>>> calls
>>> > and events that occur in OS before and after WM_SHUTDOWN?
>>>
>>> I’m not sure what you mean, and I’m not sure what good it would do you
>>> to know this. If your application needs to do something when the
>>> system
>>> shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
>>> message in your app’s message loop. There are no promises about the
>>> ordering of those messages. Kernel services will still be active, so
>>> you can save things to disk, although an intelligent app will save its
>>> state periodically, because not all shutdowns are clean.
>>>
>>>
>>> > 3) Does the implementation require creating device drivers in user
>>> > mode and/or kernel mode?
>>>
>>> No. The system sends this message when it is ordered to shut down,
>>> probably by the ACPI driver in response to a notice from the BIOS.
>>> There are ways to catch this message in a GUI app, in a console app, or
>>> in a service.
>>>
>>> –
>>> Tim Roberts, xxxxx@probo.commailto:xxxxx
>>> Providenza & Boekelheide, Inc.
>>>
>>>
>>> —
>>> 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
>>
>> —
>> 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


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</mailto:xxxxx>

Configuring the power button action to do “Nothing” does not give
a feedback that the power button event occurred. I would like to create a
program that *listens for the power button event* and *respond with an
action. *Is it possible to configure the *power button do perform other
actions besides the 4 listed* (do nothing, tell me what to do, hibernate,
and shutdown) under powercfg.cpl? If not, what are other software
implementations to achieve this goal? * *

On Tue, Aug 20, 2013 at 12:50 PM, Doron Holan wrote:

> If you don?t want the power button to do anything, go to powercfg.cpl
> and configure the power button action to ?Nothing?. You can do this with
> group policy as well IIRC
>
>

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

>
> ****
>
> Under Possible Software Solutions, I would like to replace the 3rd bullet
> point with the following:
>
>**? **Implement a program relating to reboot method under
> Win32_OperatingSystem Class
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa393010(v=vs.85).aspx
>

>
> Thanks,
>
> Shuodan

>
> ****
>
> On Tue, Aug 20, 2013 at 12:04 PM, Shuodan Chen wrote:
>
>
> Thanks to everyone for your helpful inputs!! They are much appreciated.
>

>
> ****
>
> The purpose, goal, constraints, and possible solutions are listed below
> for additional clarity:
>
>

>
> 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.

>
>
>

>
> Goal: Software implementation to listen for the power button eventand perform some action as feedback to the user that the power button event
> occurred.

>
> ****
>
> Constraints:
>
> - Hardware solution would be very difficult and costly to scale

> - BIOS solution is not feasible for the same reason as Hardware
> solution
>
> Possible Software Solutions Open for Discussion:

>
> - Add additional functionalities to “when I press the power button”
> in Power Options Advanced Panel
> - Implement a program involving IOCTL as described in
> http://blogs.msdn.com/b/doronh/archive/2006/09/08/746834.aspx

> - Implement a program relating to Win32_ShutdownEvent Class
> http://msdn.microsoft.com/en-us/library/aa394101(v=VS.85).aspx
> - Implement a program relating to the power_action_policy in system
> power policy structure
> http://msdn.microsoft.com/en-us/library/windows/desktop/aa373225(v=vs.85).aspx
>

> - Other suggestions?
>
> Thanks for your guidance,

>
> Shuodan
>
>

>
>

>
>

>
> On Mon, Aug 19, 2013 at 10:06 PM, wrote:

>
> WM_ENDSESSION is sent when the current session is terminating, such as via
> a logoff. WM_SHUTDOWN is sent when the system is shutting down, for
> whatever reasons the kernel as chosen. These include a user-initiated
> shutdown sequence, a low-power condition for a portable, or a low-voltage
> notification from an Uninterruptible Power Supply during a power outage.
> An earlier message seemed to indicate that the order of these two messages
> is not guaranteed.
>
> Therefore, if you are responding to a shutdown, there are already
> mechanisms in place to handle this. But your scenario of bringing up
> Notepad doesn’t make much sense during a shutdown. This sounds like a
> desire to make the “power off” button do something other than turning off
> the power. As already pointed out, this requires BIOS changes and would
> be a Really Bad Idea. If you intercept the messages in app space and try
> to start another app, this likewise makes no sense, because you are in the
> middle of a shutdown, which may proceed independent of any opinion you may
> be offering to the contrary (like a low-battery shutdown). These messages
> are intended to notify you to save state, and that is expected to take
> place, ideally, in a very short time (the exact time allowed may be
> documented). Bringing up Notepad, or any other app that requires user
> interaction, would certainly violate this window.
>
> As usual, this question is more along the lines of asking about the best
> glue, without a clear statement of purpose about why a flying pig solves
> the problem.
>
> Note that if the purpose is to have some button that can send a
> notification to a program, and the only currently-available button is the
> power button, then the design of the hardware is wrong. I’ve seen various
> USB keypads with one, two, three,or some small value of N buttons, which
> would serve the purpose. So why do you care about the power button?
> joe

>
>
> > Thanks for all the great suggestions! Here is the scenario. When the
> > power button is pressed, the OS or an app will respond with an action
> > (other than shutting down) so that the user knows the button event
> > occurred. The action can be anything from system restart to screensaver.
> > What I would like to find out are the file types required (ie. .exe,
> .inf,
> > .dll), the sequence of key API methods, class objects, and enumerations I
> > need for the implementation to capture the button event in XP.
> >
> > Regarding BIOS, I did look into it, but we prefer a programmable solution
> > or modifying a setting in OS.
> >
> > Thanks for your help,
> > Shuodan
> >
> >
> > On Mon, Aug 19, 2013 at 5:46 PM, Doron Holan
> > wrote:
> >
> >> What specifically do you want to happen when the button is pressed?
> >> Overriding it to custom actions is not a good design
> >>
> >> d
> >>
> >> Bent from my phone
**
>
> >> ------------------------------
> >> From: Shuodan Chen
>
> >> Sent: 8/19/2013 5:21 PM

>
> >> To: Windows System Software Devs Interest List
>
>
> >> Subject: Re: [ntdev] Capturing Physical Power Button Event in Windows XP
> >> Embedded
> >>
> >> Hi Tim,
> >> Thanks for the detailed info. Basically, I want to customize the
> >> power button functionality. Let’s say I write a quick standalone .cpp
> >> test

>
> >> program, int main (), to have notepad open after the user presses the
> >> physical
power button, what would be the best way to implement that?
>

>
> >> Thanks,
> >> Shuodan
> >>
> >>
> >>
> >>
> >>
> >> On Mon, Aug 19, 2013 at 4:50 PM, Tim Roberts wrote:
> >>
> >>> Shuodan Chen wrote:
> >>> >
> >>> > 1) Would you mind give me a detailed rundown of the series of
> >>> calls
> >>> > and events that occur in OS before and after WM_SHUTDOWN?
> >>>
> >>> I’m not sure what you mean, and I’m not sure what good it would do you
> >>> to know this. If your application needs to do something when the
> >>> system
> >>> shuts down, then you watch for the WM_SHUTDOWN (or WM_ENDSESSION)
> >>> message in your app’s message loop. There are no promises about the
> >>> ordering of those messages. Kernel services will still be active, so
> >>> you can save things to disk, although an intelligent app will save its
> >>> state periodically, because not all shutdowns are clean.
> >>>
> >>>
> >>> > 3) Does the implementation require creating device drivers in user
> >>> > mode and/or kernel mode?
> >>>
> >>> No. The system sends this message when it is ordered to shut down,
> >>> probably by the ACPI driver in response to a notice from the BIOS.
> >>> There are ways to catch this message in a GUI app, in a console app, or
> >>> in a service.
> >>>
> >>> –
> >>> Tim Roberts, xxxxx@probo.com
> >>> Providenza & Boekelheide, Inc.
> >>>
> >>>
> >>> —
> >>> 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
> >>
> >> —
> >> 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
>
>
>
> —
> 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

>
> —
> 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
>

>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

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
>

If you don’t want accidental shutdown, you can set the power button action as “do nothing”. See power profile editor and powercfg command line utility.

Thanks for your input. “Do nothing” which gives no feedback may prompt the
user to hold down the button for shutdown after 4 seconds. I much prefer a
software implementation to capture the power button event listener and
respond with an action such as monitor off or restart.

On Tue, Aug 20, 2013 at 3:44 PM, wrote:

> If you don’t want accidental shutdown, you can set the power button action
> as “do nothing”. See power profile editor and powercfg command line utility.
>
> —
> 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
>

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

When we had a similar situation, we used a solution that required no
changes in the BIOS, no drivers, and no apps. It was a simple hardware
mod: we placed a piece of duct tape over the power button and used a
Sharpie pen to write NO! on it. We had a similar mod on the power cord
where it plugged into the UPS.

Of course, you could try another hardware mod: remove the power button
entirely. This has the advantage of solving the “hold-for-N-seconds”
forced shutdown. You can force a shutdown in such cases by using a pencil,
inserted eraser-first, to reach the “real” button behind the normal
user-visible interface hardware button.
joe

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

I think this is called ACPI Event. You can try catching it via WMI.

But, if you want to filter it and alter its functionality, you will need to do lots of reverse engineering and using undocumented stuff between acpi.sys and win32k.sys
“Shuodan Chen” wrote in message news:xxxxx@ntdev…
Hello,
I would like to capture the physical power button event in Window XP Embedded system when the user presses it during OS so our software can perform an action in response. Please let me know your recommendations for implementing this sequence. I appreciate your guidance and details you can offer.
Thanks for your help,
Shuodan