How to show a comfirmation dialog when a batch file window is closed

5,234


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!!!

Share:
5,234

Related videos on Youtube

Nuach
Author by

Nuach

Updated on September 18, 2022

Comments

  • Nuach
    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
      Nuach about 9 years
      @EBGreen I meant when the user clicks the "X" button
    • DrMoishe Pippik
      DrMoishe Pippik about 9 years
      See pause and choice for the CMD prompt.
    • Nuach
      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
      DavidPostill about 9 years
    • Karan
      Karan about 9 years
      Not possible. See the SO post linked to above.
  • Karan
    Karan about 9 years
    How will this help if the user closes the cmd window by clicking the 'X' button?
  • mustangDC
    mustangDC about 9 years
    This 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
    Karan about 9 years
    I know, but that's not the OP's requirement so this clearly won't help.
  • mustangDC
    mustangDC about 9 years
    Ya, 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
    mustangDC about 9 years
    mistakenly posted as an aswer from the android app. Will delete it soon Sorry
  • Karan
    Karan about 9 years
    If you know of an actual solution, do share it with all of us.
  • mustangDC
    mustangDC about 9 years
    definitely will do.. Working on it