From: Alexis on
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." <df2705(a)community.nospam> wrote in message
news:DA5B621A-368A-4A5C-89A2-58A0F26A8995(a)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." <df2705(a)community.nospam> wrote in message
news:DA5B621A-368A-4A5C-89A2-58A0F26A8995(a)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
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 (jialge(a)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:
msdnmg(a)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.

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.

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