Detecting Logoff, Shutdown, or restart from tray icon app in VB.net
Posted on 2009-03-31
Can anyone help?
I have tried:
AddHandler SystemEvents.SessionEnding, AddressOf ShutdownApp
Private Sub ShutdownApp()
Private Shared WM_QUERYENDSESSION As Integer = &H11
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_QUERYENDSESSION Then
systemShutdown = True
The first method works fine if i have a form open on the screen, but does not work if my application is minimised to tray.
The second method will shut down my application, but only if there is a form open. It aslo somehow cancels the Windows shutdown forcing the user to shutdown again.
How can I make my application shutdown gracefully from the system tray without interfering with the Windows shutdown?
Note: Vista compatability is preferred (Though I am currentlt testing on XP SP3) - I recall reading that Vista might have issues with the second method?