|
-
Dec 25th, 2007, 02:29 AM
#1
Thread Starter
Member
Detecting Shutdown, Logoff, Restart, Sleep
Hello,
What i wish to find is a message or the like that I can use to detect between specific 'shutdown' like events, ie: I wish to be able to find the difference between a shutdown, restart, logoff and sleep initiation.
The problem i have found (as displayed below) is using oClosingEvent.CloseReason the return types provide no further information other then the WindowsShutDown constant (the others are obviously irrelevant in this case).
Code:
Private Sub frmMain_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim oClosingEvent As System.Windows.Forms.FormClosingEventArgs
oClosingEvent = e
oClosingEvent.CloseReason
End Sub
The alternative i have found (as displayed below) is using the Override wndproc and catching the message WM_ENDSESSION or WM_QUERYENDSESSION however the problem with these is that they only seem to provide information for a logoff .
Thanks in advance.
Code:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Dim oMessage As System.Windows.Forms.Message
oMessage = m
Select Case oMessage.Msg
Case WM_ENDSESSION
If oMessage.LParam = ENDSESSION_LOGOFF Then
'system is logging off
End If
Case WM_QUERYENDSESSION
If oMessage.LParam = ENDSESSION_LOGOFF Then
End If
End Select
MyBase.WndProc(m)
End Sub
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
|