How to show a comfirmation dialog when a batch file window is closed
There are other great options than using a batch file for your purpose, but since you want it that way, here is the code
@echo off
Call :YesNoBox "Are you sure you want to do that?"
if "%YesNo%"=="7" (
Call :MessageBox "You answered NO" "Heading"
exit /b
)
Code for invoking the message box
exit /b
:YesNoBox
REM returns 6 = Yes, 7 = No. Type=4 = Yes/No
set YesNo=
set MsgType=4
set heading=%~2
set message=%~1
echo wscript.echo msgbox(WScript.Arguments(0),%MsgType%,WScript.Arguments(1)) >"%temp%\input.vbs"
for /f "tokens=* delims=" %%a in ('cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"') do set YesNo=%%a
exit /b
The above code is for programming the YesNo Options
:MessageBox
set heading=%~2
set message=%~1
echo msgbox WScript.Arguments(0),0,WScript.Arguments(1) >"%temp%\input.vbs"
cscript //nologo "%temp%\input.vbs" "%message%" "%heading%"
exit /b
The above code is for setting up and programming the Message Window
Hope it helps, but if you further want to refer for your purpose you should visit these links : 1st Link, 2nd Link
Thanks!!!
Related videos on Youtube
Nuach
Updated on September 18, 2022Comments
-
Nuach over 1 year
When users click the close (X) button of a batch file window, I want it to show a confirmation dialog asking "Are you sure want to close this batch file?" with Yes/No options. How can I do this?
-
Nuach about 9 years@EBGreen I meant when the user clicks the "X" button
-
DrMoishe Pippik about 9 yearsSee pause and choice for the CMD prompt.
-
Nuach about 9 years@DrMoishePippik You when the user presses the red "X" button on the top right corner of the batch file, I want the batch file to comfirm the closing of the batch file.
-
DavidPostill about 9 years
-
Karan about 9 yearsNot possible. See the SO post linked to above.
-
-
Karan about 9 yearsHow will this help if the user closes the cmd window by clicking the 'X' button?
-
mustangDC about 9 yearsThis is definitely not the idea in the code.. The code is solely aimed at creating a window which prompts the user for the option for closing the batch operation
-
Karan about 9 yearsI know, but that's not the OP's requirement so this clearly won't help.
-
mustangDC about 9 yearsYa, you are right. Thats why I have provided a similar code not the exact working one and backed them up with references so that if the links die the code will be there for reference. Although I am working on the exact solution, will be posting it soon.
-
mustangDC about 9 yearsmistakenly posted as an aswer from the android app. Will delete it soon Sorry
-
Karan about 9 yearsIf you know of an actual solution, do share it with all of us.
-
mustangDC about 9 yearsdefinitely will do.. Working on it