Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to tell if PC booted up from standby or hibernate 1

Status
Not open for further replies.

ColdPhreze

Programmer
Apr 15, 2002
93
Does anyone know if it is possible to tell if Windows was booted up into from a shutdown to Standby or Hibernate?

I'm having problems with the serial port and if the pc was shutdown to standby or hibernate, and then brought back up, my software doesn't know that anything happened so it doesn't know to reopen the serial port, so an error occurs. I need to avoid the error. I can't simply try to reopen the serial port on error as several other things could cause the error that all need to be detected and have an error thrown.

If I can simply detect that the system just rebooted from standby or hibernate, then I can resolve this in my software.

I'm using VB.net 2003 and it's running on Win XP SP2.

Thanks a LOT for any help!
 
Look up Microsoft.Win32.SystemEvents.

The .PowerModeChange can notify you when the system Suspend and Resume.

The .SessionEnding can notify you of system Logoff and Shutdown.

Somewhere in you code you add handlers for these events:
Code:
AddHandler Microsoft.Win32.SystemEvents.PowerModeChanged, AddressOf PowerModeChanged
AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf SessionEnding

Then of course you have 2 methods to handle the events.
Code:
 Private Sub [COLOR=blue]PowerModeChanged[/color](ByVal sender As System.Object, _
 ByVal e As Microsoft.Win32.PowerModeChangedEventArgs)
        Select Case e.Mode
            Case Microsoft.Win32.PowerModes.Resume
                ...
            Case Microsoft.Win32.PowerModes.Suspend
                ...
        End Select
 End Sub
Code:
 Private Sub [COLOR=blue]SessionEnding[/color](ByVal sender As System.Object, _
 ByVal e As Microsoft.Win32.SessionEndingEventArgs)
        Select Case e.Reason
            Case Microsoft.Win32.SessionEndReasons.Logoff
                ...
            Case Microsoft.Win32.SessionEndReasons.SystemShutdown
                ...
        End Select
    End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top