|
Answer» Hi
I'm looking for cmd code that will cancel the x button that a user clicks to exit an application.
Any help will be very much appreciated!
Amram Chayim Eirinberg You mean you want a code which will prevent a user from closing the window? Not going to work. Why not? I'm not TRYING to make something cheeky
What I'm really to do is DISPLAY a Msg asking for confirmation (this part I can do), and if the user clicks cancel, I will run a bat file to cancel the exit.It's not possible. you cannot create a ConsoleCtrlHandler() nor can you programmatically call SetConsoleCtrlHandler().
If you want to disable the Exit button, you'll probably need to write your "batch file" as an actual program.
Some utilities can be used to disable the exit button, but this is different- they do this by acquiring the window handle of the console window, calling GetSystemMenu() on that handle, and then disabling the Close menu OPTION (which also disables the X button).
After the program does this, it exits, and you are back at the PROMPT or the batch continues.
however, a utility cannot easily be run that will do what you require.
First: the SetConsoleCtrlHandler() accepts the address of a callback function. by definition, it has to be in the address space of the caller (the "utility" program. however, you cannot get back to the prompt or resume the batch file until that utility exits, and once it exits, there is no valid hook function to call.Is it possible to cancel out the exit through VBScript?In VB and VBScript, the behaviour of the window close button (the 'x') varies in Windows messageboxes depending on which buttons are specified. It is visible but greyed out and disabled for a YesNo or a AbortRetryIgnore message box.
Summary:
1. AbortRetryIgnore and YesNo disable the X. 2. If a Cancel button is provided (all other combinations except vbOkOnly) then X is enabled 3. If only one button is displayed then X is enabled
Here's what happens when the above scenarios are displayed and user hits X instead of clicking on a button
1. N/A. X button not enabled 2. MsgBox returns Cancel 3. MsgBox returns value of only button
This really makes it almost pointless to disable the button once you are aware of these things.
By the way, it is not just clicking X. When X is enabled, ESC will trigger same results. Thanks Salmon! For some reason I thought they were talking about batch files, and the close button of the console window.
|