Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show a popup/message box from a Windows batch file

Is there a way to display a message box from a batch file (similar to how xmessage can be used from bash-scripts in Linux)?

like image 413
billyy Avatar asked Apr 21 '09 19:04

billyy


People also ask

How do you show messages in CMD?

To display a message that is several lines long without displaying any commands, you can include several echo <message> commands after the echo off command in your batch program. After echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt, type echo on.

What is @echo off in batch?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

What is %% A in batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


4 Answers

First of all, DOS has nothing to do with it, you probably want a Windows command line solution (again: no DOS, pure Windows, just not a Window, but a Console).

You can either use the VBScript method provided by boflynn or you can mis-use net send or msg. net send works only on older versions of windows:

net send localhost Some message to display

This also depends on the Messenger service to run, though.

For newer versions (XP and onward, apparently):

msg "%username%" Some message to display

It should be noted that a message box sent using msg.exe will only last for 60 seconds. This can however be overridden with the /time:xx switch.

like image 98
Joey Avatar answered Sep 17 '22 01:09

Joey


I would make a very simple VBScript file and call it using CScript to parse the command line parameters.

Something like the following saved in MessageBox.vbs:

Set objArgs = WScript.Arguments
messageText = objArgs(0)
MsgBox messageText

Which you would call like:

cscript MessageBox.vbs "This will be shown in a popup."

MsgBox reference if you are interested in going this route.

like image 40
boflynn Avatar answered Sep 20 '22 01:09

boflynn


Might display a little flash, but no temp files required. Should work all the way back to somewhere in the (IIRC) IE5 era.

mshta javascript:alert("Message\n\nMultiple\nLines\ntoo!");close();

Don't forget to escape your parentheses if you're using if:

if 1 == 1 (
   mshta javascript:alert^("1 is equal to 1, amazing."^);close^(^);
)
like image 27
Fowl Avatar answered Sep 19 '22 01:09

Fowl


This will pop-up another Command Prompt window:

START CMD /C "ECHO My Popup Message && PAUSE"
like image 39
Dave Webb Avatar answered Sep 17 '22 01:09

Dave Webb