Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Detect Hibernation from User Mode

3,331 views
Skip to first unread message

David F.

unread,
Mar 13, 2009, 7:00:03 PM3/13/09
to
Hello,

I couldn't find any other group that seemed appropriate to ask this ...

How do I detect when the system is going to hibernate so I can perform an
action that needs to occur to ensure proper startup from hibernation? I
don't care about anything else (sleep, suspend, etc..), just hibernate?

TIA!!

Mike Collins

unread,
Mar 13, 2009, 8:36:10 PM3/13/09
to
Do you specifically want to differenciate between Hibernation and Stand-By?

Have you looked at the WM_POWERBROADCAST message?

HTH Mike C

"David F." <df2...@community.nospam> wrote in message
news:000B4949-56C8-4F66...@microsoft.com...
> Hello,
>


Remy Lebeau

unread,
Mar 13, 2009, 8:27:39 PM3/13/09
to

"David F." <df2...@community.nospam> wrote in message
news:000B4949-56C8-4F66...@microsoft.com...

> How do I detect when the system is going to hibernate so I can perform


> an action that needs to occur to ensure proper startup from hibernation?
> I don't care about anything else (sleep, suspend, etc..), just hibernate?

Look at the WM_POWERBROADCAST window message.

--
Remy Lebeau (TeamB)


David F.

unread,
Mar 13, 2009, 10:58:38 PM3/13/09
to
> Do you specifically want to differenciate between Hibernation and
> Stand-By?

Yes. Need to know that it's going to hibernate and not just stand-by or
suspend.

Mike Collins

unread,
Mar 14, 2009, 10:12:53 AM3/14/09
to
Hay David,

This seems like an interesting problem. On the surface there doesn't seem
to be (AFAIK) and system for differentiating between Hibernation & stand-by.
However, I was looking on MSDN and there is the following information:

http://msdn.microsoft.com/en-us/library/aa373229(VS.85).aspx

This discusses the ACPI states which appear to vary from Sleep (S1, 2, 3),
Hibernation (S4) and Soft Off (S5). You can retrieve the SYSTEM_POWER_STATE
using the GetSystemPowerStatus() API. The problem is, I'm not sure how you
would use this. If the system is in hibernation then effectively nothing is
running so how you can call an API to retrieve that information I don't no.

HTH

Mike C


"David F." <df2...@community.nospam> wrote in message

news:DA5B621A-368A-4A5C...@microsoft.com...

Pavel A.

unread,
Mar 14, 2009, 8:52:00 PM3/14/09
to

AFAIK you can get the target state of power transition only in kernel mode.
Note that with the "hybrid sleep" the system does suspend first,
and then may hibernate, without letting usermode code know.

- pa

Jialiang Ge [MSFT]

unread,
Mar 16, 2009, 5:12:32 AM3/16/09
to
Good morning David

I once dealt with a similar case about how to distinguish standby vs
hibernation in user-mode. The product group's comment on that case was that
it is by-design that user-mode cannot tell the difference between the
different sleep states. We therefore researched and managed to work around
the issue based on the underlying business needs, i.e. why does the
customer need to hook the hibernation event? Is there any methods to
achieve the same result without the event? David, you mentioned that you
need to perform an action that is required to occur to ensure proper
startup from hibernation. May I suggest that you provide with us more info
of the action? I will perform the researches from this angle.

WM_POWERBROADCAST / PBT_APMSUSPEND events are sent for both Stand-by and
Hibernation cases. Before Windows Vista, when the system is suspended
(either Standby or Hibernate), the sequence of events is

WM_POWERBROADCAST / PBT_APMQUERYSUSPEND
WM_POWERBROADCAST / PBT_APMSUSPEND

When the system is resumed:

WM_POWERBROADCAST / PBT_APMRESUMEAUTOMATIC

The sequence of events for Standby and Hibernation is identical, thus, the
events cannot distinguish the two sleep modes. One difference between the
two cases is that, if it is "StandBy", you may get the event
PBT_APMRESUMESUSPEND after PBT_APMRESUMEAUTOMATIC. PBT_APMRESUMESUSPEND
indicates that the resume is triggered by user input, such as pressing a
key.

There was an event named PBT_APMSTANDBY that was sent for stand-by cases,
but it only works for mobile PC.
http://msdn.microsoft.com/en-us/library/ms704147.aspx

The SYSTEM_POWER_STATE enumeration mentioned by Mike is actually a kernel
mode data structure:
http://msdn.microsoft.com/en-us/library/bb264568.aspx
So it does not help in your user-mode code, either.

Here is a relevant codeproject article about the OS events like Sleep,
Stand-by, Hibernate, Power Status Changed, Low Battery, Critial Suspend, AC
Power, Battery Power, Battery Life.
http://www.codeproject.com/KB/system/OSEvents.aspx

Regards,
Jialiang Ge (jia...@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msd...@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

MSDN Managed Newsgroup support offering is for non-urgent issues where an
initial response from the community or a Microsoft Support Engineer within
2 business day is acceptable. Please note that each follow up response may
take approximately 2 business days as the support professional working with
you may need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations that require urgent,
real-time or phone-based interactions. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

David F.

unread,
Mar 18, 2009, 2:14:29 AM3/18/09
to
I guess I'll have to just do what needs to be done with both then on resume
notification undo any setup that may still exist.

""Jialiang Ge [MSFT]"" <jia...@online.microsoft.com> wrote in message
news:kqwyddhp...@TK2MSFTNGHUB02.phx.gbl...

firasmansouri

unread,
Jan 15, 2010, 9:25:21 AM1/15/10
to
Hi,
I am having the same issue making the difference between a stand by and a hibernation except that I can not work around the problem because that's what I need to monitor.
So,how can I get the target state of a power transition in kernel mode since that can't be done in user mode.

Pavel A. wrote:

David F.
14-Mar-09

David F. wrote:

AFAIK you can get the target state of power transition only in kernel mode.
Note that with the "hybrid sleep" the system does suspend first,
and then may hibernate, without letting usermode code know.

- pa

Previous Posts In This Thread:

On Friday, March 13, 2009 7:00 PM
David F. wrote:

Detect Hibernation from User Mode
Hello,

I couldn't find any other group that seemed appropriate to ask this ...

How do I detect when the system is going to hibernate so I can perform an
action that needs to occur to ensure proper startup from hibernation? I
don't care about anything else (sleep, suspend, etc..), just hibernate?

TIA!!

On Friday, March 13, 2009 8:27 PM
Remy Lebeau wrote:

Re: Detect Hibernation from User Mode


Look at the WM_POWERBROADCAST window message.

--
Remy Lebeau (TeamB)

On Friday, March 13, 2009 8:36 PM
Mike Collins wrote:

Do you specifically want to differenciate between Hibernation and Stand-By?
Do you specifically want to differenciate between Hibernation and Stand-By?

Have you looked at the WM_POWERBROADCAST message?

HTH Mike C

On Friday, March 13, 2009 10:58 PM
David F. wrote:

Yes.
Yes. Need to know that it is going to hibernate and not just stand-by or
suspend.

On Saturday, March 14, 2009 10:12 AM
Mike Collins wrote:

Hay David,This seems like an interesting problem.
Hay David,

This seems like an interesting problem. On the surface there doesn't seem
to be (AFAIK) and system for differentiating between Hibernation & stand-by.
However, I was looking on MSDN and there is the following information:

http://msdn.microsoft.com/en-us/library/aa373229(VS.85).aspx

This discusses the ACPI states which appear to vary from Sleep (S1, 2, 3),
Hibernation (S4) and Soft Off (S5). You can retrieve the SYSTEM_POWER_STATE
using the GetSystemPowerStatus() API. The problem is, I'm not sure how you
would use this. If the system is in hibernation then effectively nothing is
running so how you can call an API to retrieve that information I don't no.

HTH

Mike C


"David F." <df2...@community.nospam> wrote in message
news:DA5B621A-368A-4A5C...@microsoft.com...

On Saturday, March 14, 2009 8:52 PM
Pavel A. wrote:

David F.
David F. wrote:

AFAIK you can get the target state of power transition only in kernel mode.
Note that with the "hybrid sleep" the system does suspend first,
and then may hibernate, without letting usermode code know.

- pa

On Monday, March 16, 2009 5:12 AM
jialg wrote:

Good morning DavidI once dealt with a similar case about how to distinguish
Good morning David

I once dealt with a similar case about how to distinguish standby vs
hibernation in user-mode. The product group's comment on that case was that
it is by-design that user-mode cannot tell the difference between the
different sleep states. We therefore researched and managed to work around
the issue based on the underlying business needs, i.e. why does the
customer need to hook the hibernation event? Is there any methods to
achieve the same result without the event? David, you mentioned that you

need to perform an action that is required to occur to ensure proper

WM_POWERBROADCAST / PBT_APMRESUMEAUTOMATIC

On Wednesday, March 18, 2009 2:14 AM
David F. wrote:

I guess I'll have to just do what needs to be done with both then on resume

I guess I will have to just do what needs to be done with both then on resume


notification undo any setup that may still exist.


Submitted via EggHeadCafe - Software Developer Portal of Choice
Confirm Message Box before Deleting
http://www.eggheadcafe.com/tutorials/aspnet/4f445b0a-bb25-4030-8f9b-0ff1ac5655d4/confirm-message-box-befor.aspx

Pavel A.

unread,
Jan 15, 2010, 9:56:43 PM1/15/10
to

"Firas Mansouri" wrote in message
news:201011592528...@gmail.com...

> Hi,
> I am having the same issue making the difference between a stand by and a
> hibernation except that I can not work around the problem because that's
> what I need to monitor.
> So,how can I get the target state of a power transition in kernel mode
> since that can't be done in user mode.

Handle IRP_MN_QUERY_POWER and/or IRP_MN_SET_POWER
for System (Sx) states; the Parameters.Power.ShutdownType is the
system power action (shutdown, reset, hibernate).

Regards,
-- pa

alexisflores

unread,
Mar 24, 2010, 12:38:15 PM3/24/10
to
how i can do this in .net????
i need to know when system suspends and when hibernates.

Private Sub Suspende(ByVal sender As Object, ByVal e As PowerModeChangedEventArgs)

If e.Mode = PowerModes.Suspend Then
Me.TXTMENS.Text = "Suspendido: " + SystemInformation.ComputerName + " - " + Date.Now.ToString
Me.EVENTO = "Suspend"
End If

If e.Mode = PowerModes.Resume Then
Me.TXTMENS.Text = "Activate: " + SystemInformation.ComputerName + " - " + Date.Now.ToString
Me.EVENTO = "Activate"
End If

Me.EQUIPO = SystemInformation.ComputerName

Dim x As conexion = New conexion
x.CON()
x.InsertChange(Me.TXTMENS.Text, Me.EVENTO, Me.EQUIPO)
x.Descon()

End Sub

Mike Collins wrote:

Hay David,This seems like an interesting problem.
14-Mar-09

Hay David,

This seems like an interesting problem. On the surface there doesn't seem
to be (AFAIK) and system for differentiating between Hibernation & stand-by.
However, I was looking on MSDN and there is the following information:

http://msdn.microsoft.com/en-us/library/aa373229(VS.85).aspx

This discusses the ACPI states which appear to vary from Sleep (S1, 2, 3),
Hibernation (S4) and Soft Off (S5). You can retrieve the SYSTEM_POWER_STATE
using the GetSystemPowerStatus() API. The problem is, I'm not sure how you
would use this. If the system is in hibernation then effectively nothing is
running so how you can call an API to retrieve that information I don't no.

HTH

Mike C


"David F." <df2...@community.nospam> wrote in message
news:DA5B621A-368A-4A5C...@microsoft.com...

Previous Posts In This Thread:

On Friday, March 13, 2009 7:00 PM
David F. wrote:

Detect Hibernation from User Mode
Hello,

I couldn't find any other group that seemed appropriate to ask this ...

How do I detect when the system is going to hibernate so I can perform an
action that needs to occur to ensure proper startup from hibernation? I
don't care about anything else (sleep, suspend, etc..), just hibernate?

TIA!!

On Friday, March 13, 2009 8:27 PM
Remy Lebeau wrote:

Re: Detect Hibernation from User Mode
Look at the WM_POWERBROADCAST window message.

--
Remy Lebeau (TeamB)

On Friday, March 13, 2009 8:36 PM
Mike Collins wrote:

Do you specifically want to differenciate between Hibernation and Stand-By?
Do you specifically want to differenciate between Hibernation and Stand-By?

Have you looked at the WM_POWERBROADCAST message?

HTH Mike C

On Friday, March 13, 2009 10:58 PM
David F. wrote:

Yes.
Yes. Need to know that it is going to hibernate and not just stand-by or
suspend.

On Saturday, March 14, 2009 10:12 AM
Mike Collins wrote:

Hay David,This seems like an interesting problem.
Hay David,

This seems like an interesting problem. On the surface there doesn't seem
to be (AFAIK) and system for differentiating between Hibernation & stand-by.
However, I was looking on MSDN and there is the following information:

http://msdn.microsoft.com/en-us/library/aa373229(VS.85).aspx

This discusses the ACPI states which appear to vary from Sleep (S1, 2, 3),
Hibernation (S4) and Soft Off (S5). You can retrieve the SYSTEM_POWER_STATE
using the GetSystemPowerStatus() API. The problem is, I'm not sure how you
would use this. If the system is in hibernation then effectively nothing is
running so how you can call an API to retrieve that information I don't no.

HTH

Mike C


"David F." <df2...@community.nospam> wrote in message
news:DA5B621A-368A-4A5C...@microsoft.com...

On Saturday, March 14, 2009 8:52 PM
Pavel A. wrote:

- pa

WM_POWERBROADCAST / PBT_APMRESUMEAUTOMATIC

On Friday, January 15, 2010 9:25 AM
Firas Mansouri wrote:

How to get the target state of a power transition in kernel mode


Hi,
I am having the same issue making the difference between a stand by and a hibernation except that I can not work around the problem because that's what I need to monitor.
So,how can I get the target state of a power transition in kernel mode since that can't be done in user mode.

Submitted via EggHeadCafe - Software Developer Portal of Choice

BizTalk Custom Pipeline for Splitting Messages
http://www.eggheadcafe.com/tutorials/aspnet/a0786aaf-c159-40ff-9cf6-241d5e325f42/biztalk-custom-pipeline-f.aspx

0 new messages