How to create a password entry dialog on app close?

Hello all,

I need to create a dialog where if the user attempts to exit the application, the dialog comes up, and a password must be entered and verified. What is the best way to do this?


That’s interesting . . . why on exiting the application?

The Window has a CancelClose method.
You can show the dialog from there. If you want to avoid the close, return true.

There is also an App.CancelClose event. You can use a flag to trigger the password window and cancel the close. Basically, only that password window will be able to truly quit the app.

Nothing will keep the user from force-quitting, of course.

Hi all!

These are all great - I was going to use a menu selection to implement the password window.

The reason for on exit, is I want an authorized user to be able to quit the app - properly. When done so, it quits elegantly. Since this is a LAN app, the connections need to know - quitting properly appears to work the best. Further, most users will not know how to use task manager to kill the app, and would be intimidated to do so. Since this is the case, I think this is the best solution.

What is really getting me - is that I cannot remember what the “proper” name of the dialog is so I can find and program it! Sorry, must be a middle aged moment - errr… hour:(


I would use the close or cancelclose event and handle the cleanup and/or things you need to do so it quits elegantly there.

As for dialog, show a modal or sheet window and let the user fill in the password there?

Tim you should consider User Experience vs. your maintaining properly connections. Not knowing about your further intentions (internal app etc.) such a password protected app would be very annoying to me and this behavoir woulnd’t pass any App Store Review.

I would spend more thoughts on robust network connections than on bullying the user with passwords - even if this is intentional.

Thanks again guys.
The reason for the bulling, is that only a tech should ever be killing this app. If it is even causually shut down, so do many other things that should not be. In a controlled tech environment, a tech knows that it is being closed, and will need to be started again, following whatever procedure is to be performed.

The app as it is now, has no method to close it - other than windows task manager, which is less than elegant. Previously I had, as part of the menu, a close/quit method. However, the operator would, on occasion, click this inadvertently. Hence the reason for the changes.


A simple “Are you sure?” dialog would do, no?

You’re looking for the MessageDialog class, I think. Something like this in App.CancelClose:

  dim dlg as new MessageDialog
  dlg.Message = "Are you sure you want to quit?"
  dlg.Explanation = "Quitting this app can lead to BAD things!"
  // Switch the buttons
  dlg.ActionButton.Caption = "Cancel"
  dlg.CancelButton.Caption = "Quit"
  dlg.CancelButton.Visible = true
  dim btn as MessageDialogButton = dlg.ShowModal
  return btn = dlg.ActionButton

@Tim as alternative for such an persistant app you may also replace the default explorer.exe as windows shell

Just place your EXE filename into
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell

Domain policies or local policies can help to limit usage of ctrl+alt+del and task-manager so even a tech cannot close this app (or the whole pc will shutdown).

I am using this technique on Win7 machines for a customer of mine.

Thanks guys.
@Kem - That one I knew how to do. I really want to lock it down. Is there a standard dialog, or do I need to create a window?
@Thomas - I had not ever done that. Will give that a look.

Thanks again all!

You’ll need to roll your own.

Yea Kem, that is what I figured.
I think for the moment, I’ll take the easy way out. See how it goes.

Thanks again,