how to detect windows hibernation

I need to detect when windows is initializing a hibernation, is it posible?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think you need to listen to the WM_POWERBROADCAST message and see if its value is PBT_APMQUERYSUSPENDFAILED

I am not sure if you can distinguish between a sleep and hibernate request. Anyway, I hope this helps.
sorry, mistyped that last one.

I think you need to listen to the WM_POWERBROADCAST message and see if its value is PBT_APMQUERYSUSPEND

I am not sure if you can distinguish between a sleep and hibernate request. Anyway, I hope this helps.
SuperDude1984Author Commented:
i'm gonna need a code sample (
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Ok. Here it is. Create a Windows Form. and paste this code into it. The code will intercept and halt Sleep" and "Hibernate".

Since this is a broadcast, you will see as many msgbox as you have open Windows.

I was not able to distinguish between "Sleep" and "Hibernate" as I told you.

<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    Protected Overrides Sub WndProc(ByRef m As Message)

        Dim WM_POWERBROADCAST As Integer = &H218         ' 0x0218
        Dim PBT_APMQUERYSUSPEND As Integer = &H0         ' 0x0000
        Dim PBT_APMQUERYSTANDBY As Integer = &H1         ' 0x0001
        Dim BROADCAST_QUERY_DENY As Integer = &H424D5144 ' 0x424D5144
        ' Listen for WM_POWERBROADCAST message
        Select Case m.Msg
            Case WM_POWERBROADCAST
                ' Intercept the message
                MsgBox("WM_POWERBROADCAST Received")
                Select Case m.WParam.ToInt32
                    Case PBT_APMQUERYSUSPEND
                        MsgBox("PBT_APMQUERYSUSPEND Received")

                    Case PBT_APMQUERYSTANDBY
                        MsgBox("PBT_APMQUERYSTANDBY Received")
                End Select

                MsgBox("Cancelling the WM_POWERBROADCAST message")
                Dim pResult As New IntPtr(BROADCAST_QUERY_DENY)
                m.Result = pResult
            Case Else
                ' Pass the message to base class
        End Select

    End Sub

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SuperDude1984Author Commented:
Thanks for the help dude...

Just wondering...
the constants that you use, like this one:
Dim WM_POWERBROADCAST As Integer = &H218

Where do you get them from?  how can you know the value? (&H218)
When you browse the MSDN, you will see a table like this at the end of the file:

Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0, Windows Me, Windows 98, and Windows 95.
Server: Included in Windows Server 2003, Windows 2000 Server, and Windows NT Server 4.0.
Header: Declared in Winuser.h; include Windows.h.

This tells that constants are declared in the Winuser.h file. This C++ header file is part of the Platform SDK. It comes with VS and you should find all files under:

C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\ *

Whenever, you need to know the value of a constant, search through that folder or the entire "C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7" folder. Then copy the values and declare it in you VB app.

* assuming that is your installation folder.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.