How to Add Message Boxes in Batch Programming

965

19

2

Posted

Introduction: How to Add Message Boxes in Batch Programming

Have you ever wanted to add a graphical interface for your batch files like you can in VBScript? I sure have. But now you can with this awesome program called MessageBox.

Step 1: Installation

You can download the program here-------->LINK

After you have downloaded and extracted the file, move the file called MSGBOX.EXE to your system32 folder, usually it is in C:\windows\system32.

Step 2: Test

Now, open up cmd and type msgbox and you should see it's syntax. You can also run the example.bat to test it out as well. So in case you did not understand how to use it, I have an example below:

Msgbox "Hello\n\nDo you want to continue ?" "This is a Message Box" YESNO

-

So first the "Hello\n\nDo you want to continue ?". This is the body message. The "\n\n" is a carriage return.

-

Second the "This is a Message Box". This is the Title in the Message Box.

-

Third the "YESNO". This are the buttons that would show on the Message Box. The following combinations are:

YESNO, YESNOCANCEL, OKCANCEL and if left blank then it would just display OK.

-

So now that you know how the MsgBox function works, you can now add functions when a button is clicked.

Example in a batch script:

@echo off

Msgbox "Hello\n\nDo you want to continue ?" "This is a Message Box" YESNOCANCEL

if %errorlevel%==6 GOTO yes

if %errorlevel%==7 GOTO no

if %errorlevel%==2 GOTO cancel

::OK would be: if %errorlevel%==1 goto OK

:yes

echo You clicked Yes

pause >NUL

exit

:no

echo You clicked No

pause >NUL
exit

:cancel

echo You Clicked on Cancel

pause >NUL
exit

Step 3: Enjoy!

Now you can enjoy that Message Box Function!

If you have any questions or concerns please write a comment or PM me.

Share

    Recommendations

    • Science of Cooking

      Science of Cooking
    • Microcontroller Contest

      Microcontroller Contest
    • Spotless Contest

      Spotless Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments

    um, it works for me on win 7. Maybe not on later versions of windows, but to test it out, the easiest way is just download and extract the zip file and run EXAMPLE.bat. If messagesboxes come up, it works.