• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 121
  • Last Modified:

Determine s Shutdown|Close All Programs

I have a little program that runs in the system tray.  In the Form_Unload event I have a confirmation message box, which asks the user if they really want to exit.  However, if the User does a shutdown, restart, or "Close All Programs and Login in as another user" it still gives the confirmation msgbox.  I don't want this to happen.  So how do I tell if the user or the system is trying to shut the programs down?

:) dapperry
0
dapperry
Asked:
dapperry
1 Solution
 
VbmasterCommented:
You can use the QueryUnload event instead of the Unload event. In there you can change the value of the variable Cancel to stop the program from quitting. The helpfile will tell you how to change it, it's all there. ;)
0
 
Erick37Commented:
You can tell how the unload was invoked by looking at the UnloadMode parameter in QueryUnload.  In your case, you want to confirm exit in vbFormControlMenu and vbFormCode, but not in vbAppWindows.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Select Case UnloadMode
    Case vbFormControlMenu
        'The user chose the Close command from the Control menu on the form.
    Case vbFormCode
        'The Unload statement is invoked from code.
    Case vbAppWindows
        'The current Microsoft Windows operating environment session is ending.
    Case vbAppTaskManager
        'The Microsoft Windows Task Manager is closing the application.
    Case vbFormMDIForm
        'An MDI child form is closing
    End Select
End Sub
0
 
dapperryAuthor Commented:
Thanks,  I guess thats one form event I just never got around to looking at!  

:) dapperry
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now