Here is a little code snippet that prevents the windows from shutting down if your app is running, it intercepts the WM_QUERYENDSESSION message that is sent to the open windows on a system shutdown, and cancels the message.
VB Code:
'constants needed, form level Private Const WM_QUERYENDSESSION As System.Int32 = &H11 Private Const WM_CANCELMODE As System.Int32 = &H1F 'the sub to intercept the windows messages Protected Overrides Sub WndProc(ByRef ex As Message) If ex.Msg = WM_QUERYENDSESSION Then 'cancel the message Dim MyMsg As New Message MyMsg.Msg = WM_CANCELMODE MyBase.WndProc(MyMsg) Else 'send the message as normal MyBase.WndProc(ex) End If End Sub




Reply With Quote