2

I have a batch file. After opening it, I want to warn the user for closing it, by a warning dialog box with a custom message. Or if the above is not possible, the atleast some Message inside the batch file.

Is there any way to do so?

2 Answers 2

2

Or if the above is not possible, the atleast some Message inside the batch file.

One way to do this is to add a bunch of REM lines and include echo on. You can then put a banner message in like:

REM ************************
REM DO NOT CLOSE THIS WINDOW
REM *************************

Refer here for more information on REM

If that doesn't work as you expect, then have a look at the example on https://ss64.com/nt/rem.html

Multi-Line Comments One approach to adding a large multi-line block of comment test is to use plain text and a goto command to jump execution past the comments:

@Echo OFF Goto :START Description can go here which can even include - | > characters

:START

The technique above will not work in the middle of a bracketed expression such as a FOR... DO(...) loop. This is because a Goto command cannot be used inside brackets - it would break their context.

Such cases can be handled by also putting the comment text within brackets, as below:

( Echo the lines below are commented Rem/||( some comment text that will work within brackets. The REM command always evaluates to TRUE so these lines will never be executed. ) )

2

enter image description here


@Goto %:^)

         ***   This text is your message to editor in your code   ***

%:^)
@echo off && mode 50,4 && title <nul && set "_yn=" <nul
setlocal & color 0A & title .\%~nx0 & >"%temp%\_vbs.vbs" ^
set /p "'=yn=msgbox("Hey!, Close %~nx0 Now!",4,"Warnning!!."):wsh.echo yn" <nul

%__AppDir__%cscript.exe "%temp%\_vbs.vbs" //nologo | find "6" >nul && set "_yn=y"
if "%_yn%"=="y" (endlocal && echo\Thank you, %~nx0 stopped by user!.. && goto :EOF)

set "_yn=" & rem :: if user answer is "No" do more below here ::

for %%i in (            "OK button only.  0.Simple Ok",
                 "OK and Cancel buttons.  1.Simple OK or Cancel",
            "Abort Retry Ignore buttons.  2.Simple Abort Retry or Ignore",
             "Yes No and Cancel buttons.  3.Yes No Cancel",
                        "Yes No buttons.  4.Yes or No",
                  "Retry Cancel buttons.  5.Retry Cancel",
                 "Critical Message icon. 16.Critical Error Retry Cancel",
                    "Warning Query icon. 32.Warnning and Simple Ok",
                  "Warning Message icon. 48.Warnning ans Simple Ok",
              "Information Message icon. 64.Warnning and Simple Ok",
           )do call %:^] "%%~i"  

%:^]
if "%~1" == "" %__AppDir__%timeout.exe -1 | <nul ^
echo\Press any key any time... & endlocal & goto :EOF

for /f tokens^=1-3delims^=. %%i in ('echo\%~1
')do echo\msgbox"%%~i",%%~j,"%%~k" >"%temp%\_vbs.vbs" 
%__AppDir__%wscript.exe "%temp%\_vbs.vbs" //nologo & exit /b

You can use VBS in your bat file and ask your user to close or not...

:: Create you VBS dialog box file: 
echo\Msgbox"You text msg", int_id,"Window Title" >"%temp%\_vbs.vbs"

run your VBS file:
%__AppDir__%cscript.exe "%temp%\_vbs.vbs" //nologo 

  • Get click by user to variable in cmd:
:: set user answer click :: 
=yn=msgbox("Hey!, Close %~nx0 Now!",4,"Warnning!!."):wsh.echo yn"

:: set user answer click value/id Yes and No :: 
Yes == 6 
 No == 7

:: Command line run VBS |redirect output | find "answer_Number" ::
%__AppDir__%cscript.exe "%temp%\_vbs.vbs" //nologo |find "6" 

:: With operator && and set if find "6" ::
%__AppDir__%cscript.exe "%temp%\_vbs.vbs" //nologo |find "6" >nul && set "_yn=y"

:: VBS ID click returns:
        Ok = 1
    Cancel = 2
     Abort = 3
     Retry = 4
    Ignore = 5
       Yes = 6
        No = 7

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.