I was working with this very same thing the other day and here is how I accomplished it:

Add system power mode event handlers to the load event on your app:
Code:
        'add the handlers for the system standby, resume, and shutdown
        AddHandler Microsoft.Win32.SystemEvents.PowerModeChanged, AddressOf PowerModeChanged
        AddHandler Microsoft.Win32.SystemEvents.SessionEnding, AddressOf SessionEnding
Then simply set up events to match:
Code:
    Private Sub PowerModeChanged(ByVal sender As System.Object, _
     ByVal e As Microsoft.Win32.PowerModeChangedEventArgs)
        Select Case e.Mode
            Case Microsoft.Win32.PowerModes.Resume
                'windows is resuming from sleep
            Case Microsoft.Win32.PowerModes.Suspend
                'goodnite windows
        End Select
    End Sub
    Private Sub SessionEnding(ByVal sender As System.Object, _
ByVal e As Microsoft.Win32.SessionEndingEventArgs)
        Select Case e.Reason
            Case Microsoft.Win32.SessionEndReasons.Logoff
                'logoff
            Case Microsoft.Win32.SessionEndReasons.SystemShutdown
               'shutdown
        End Select
    End Sub