Show a popup/message box from a Windows batch file

2019-01-03 07:40发布

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)?

20条回答
▲ chillily
2楼-- · 2019-01-03 08:14

In order to do this, you need to have a small program that displays a messagebox and run that from your batch file.

You could open a console window that displays a prompt though, but getting a GUI message box using cmd.exe and friends only is not possible, AFAIK.

查看更多
forever°为你锁心
3楼-- · 2019-01-03 08:16

msg * /server:127.0.0.1 Type your message here

查看更多
Melony?
4楼-- · 2019-01-03 08:18

This will pop-up another Command Prompt window:

START CMD /C "ECHO My Popup Message && PAUSE"
查看更多
手持菜刀,她持情操
5楼-- · 2019-01-03 08:22

A better option

set my_message=Hello world&& start cmd /c "@echo off & mode con cols=15 lines=2 & echo %my_message% & pause>nul"


Description:
lines= amount of lines,plus 1
cols= amount of characters in the message, plus 3 (However, minimum must be 15)

Auto-calculated cols version:

set my_message=Hello world&& (echo %my_message%>EMPTY_FILE123 && FOR %? IN (EMPTY_FILE123 ) DO SET strlength=%~z? && del EMPTY_FILE123 ) && start cmd /c "@echo off && mode con lines=2 cols=%strlength% && echo %my_message% && pause>nul"

查看更多
闹够了就滚
6楼-- · 2019-01-03 08:24
msg * /time:0 /w Hello everybody!

This message waits forever until OK is clicked (it lasts only one minute by default) and works fine in Windows 8.1

查看更多
我想做一个坏孩纸
7楼-- · 2019-01-03 08:25

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.

查看更多
登录 后发表回答