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:
  1. 'constants needed, form level
  2.     Private Const WM_QUERYENDSESSION As System.Int32 = &H11
  3.     Private Const WM_CANCELMODE As System.Int32 = &H1F
  4.  
  5.     'the sub to intercept the windows messages
  6.     Protected Overrides Sub WndProc(ByRef ex As Message)
  7.         If ex.Msg = WM_QUERYENDSESSION Then
  8.             'cancel the message
  9.             Dim MyMsg As New Message
  10.             MyMsg.Msg = WM_CANCELMODE
  11.             MyBase.WndProc(MyMsg)
  12.         Else
  13.             'send the message as normal
  14.             MyBase.WndProc(ex)
  15.         End If
  16.     End Sub