|
-
Dec 27th, 2007, 02:29 AM
#6
Addicted Member
Re: Detecting Shutdown, Logoff, Restart, Sleep
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
Jesse Bunch
www.getbunch.com/
If I have helped you, please rate my posts!
Unless otherwise indicated, I am using the following Products:
Visual Studio .NET 2010
.NET Framework 4.0
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|