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)?
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.
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.
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^(^);
)
This will pop-up another Command Prompt window:
START CMD /C "ECHO My Popup Message && PAUSE"