

InterviewSolution
Saved Bookmarks
1. |
Solve : Cancel Exit Application? |
Answer» <html><body><p>Hi <br/><br/>I'm looking for cmd code that will cancel the x button that a user clicks to exit an application.<br/><br/>Any help will be very much appreciated!<br/><br/>Amram Chayim Eirinberg<br/>You mean you want a code which will prevent a user from closing the window? Not going to work. Why not? I'm not <a href="https://interviewquestions.tuteehub.com/tag/trying-3234509" style="font-weight:bold;" target="_blank" title="Click to know more about TRYING">TRYING</a> to make something cheeky <br/><br/>What I'm really to do is <a href="https://interviewquestions.tuteehub.com/tag/display-25607" style="font-weight:bold;" target="_blank" title="Click to know more about DISPLAY">DISPLAY</a> 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().<br/><br/>If you want to disable the Exit button, you'll probably need to write your "batch file" as an actual program.<br/><br/>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 <a href="https://interviewquestions.tuteehub.com/tag/option-25810" style="font-weight:bold;" target="_blank" title="Click to know more about OPTION">OPTION</a> (which also disables the X button).<br/><br/>After the program does this, it exits, and you are back at the <a href="https://interviewquestions.tuteehub.com/tag/prompt-592976" style="font-weight:bold;" target="_blank" title="Click to know more about PROMPT">PROMPT</a> or the batch continues.<br/><br/>however, a utility cannot easily be run that will do what you require.<br/><br/>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. <br/><br/>Summary:<br/><br/>1. AbortRetryIgnore and YesNo disable the X.<br/>2. If a Cancel button is provided (all other combinations except vbOkOnly) then X is enabled<br/>3. If only one button is displayed then X is enabled<br/><br/>Here's what happens when the above scenarios are displayed and user hits X instead of clicking on a button<br/><br/>1. N/A. X button not enabled<br/>2. MsgBox returns Cancel<br/>3. MsgBox returns value of only button<br/><br/>This really makes it almost pointless to disable the button once you are aware of these things. <br/><br/>By the way, it is not just clicking X. When X is enabled, <a href="https://interviewquestions.tuteehub.com/tag/esc-446582" style="font-weight:bold;" target="_blank" title="Click to know more about ESC">ESC</a> will trigger same results. <br/>Thanks Salmon! For some reason I thought they were talking about batch files, and the close button of the console window.</p></body></html> | |