显示Windows批处理文件中的弹出窗口/消息框
是否有一种方法可以显示批处理文件中的消息框(类似于在Linux中从bash脚本中使用显示Windows批处理文件中的弹出窗口/消息框,windows,batch-file,command-line,messagebox,Windows,Batch File,Command Line,Messagebox,是否有一种方法可以显示批处理文件中的消息框(类似于在Linux中从bash脚本中使用xmessage)为此,您需要一个显示消息框的小程序,并从批处理文件中运行该程序 您可以打开一个显示提示的控制台窗口,但不可能仅使用cmd.exe和friends获取GUI消息框。好吧。我将创建一个非常简单的VBScript文件,并使用CScript调用它来解析命令行参数 类似于以下内容的内容保存在MessageBox.vbs中: Set objArgs = WScript.Arguments messageTe
xmessage
)为此,您需要一个显示消息框的小程序,并从批处理文件中运行该程序
您可以打开一个显示提示的控制台窗口,但不可能仅使用cmd.exe和friends获取GUI消息框。好吧。我将创建一个非常简单的VBScript文件,并使用CScript调用它来解析命令行参数 类似于以下内容的内容保存在
MessageBox.vbs
中:
Set objArgs = WScript.Arguments
messageText = objArgs(0)
MsgBox messageText
你会称之为:
cscript MessageBox.vbs "This will be shown in a popup."
如果您有兴趣走这条路。首先,DOS与此无关,您可能需要Windows命令行解决方案(同样:没有DOS,纯Windows,只是不是一个窗口,而是一个控制台) 您可以使用boflynn提供的VBScript方法,也可以错误使用
net send
或msg
<代码>网络发送仅适用于旧版本的windows:
net send localhost Some message to display
不过,这也取决于Messenger服务的运行
对于较新版本(显然是XP及更高版本):
需要注意的是,使用
msg.exe
发送的消息框仅持续60秒。但是,这可以用/time:xx
开关覆盖。这将弹出另一个命令提示窗口:
START CMD /C "ECHO My Popup Message && PAUSE"
尝试:
如果您使用的是Windows XP的command.com,这将打开一个消息框
我想,打开一个新的cmd窗口并不是你想要的。
您还可以使用,并将其与.bat文件一起使用。您可以使用以下命令从bat文件中打开它:
cd C:\"location of vbscript"
这将更改目录command.com将从中搜索文件,然后在下一行:
"insert name of your vbscript here".vbs
然后创建一个新文档,键入
<script type="text/vbscript">
MsgBox "your text here"
</script>
MsgBox“您的文本在此”
然后将其另存为.vbs文件(将“.vbs”放在文件名末尾),在文件名下方的下拉框中另存为“所有文件”(因此它不会另存为.txt),然后单击“保存” 我在这里使用名为msgbox.exe的实用程序: Msg*“在此处插入您的信息”
工作正常,只需在记事本中另存为.bat文件,或确保格式设置为“所有文件”这样,批处理文件将创建VBS脚本并显示弹出窗口。运行后,批处理文件将删除该中间文件 使用MSGBOX的优点是它确实是可定制的(更改标题、图标等),而MSG.exe则没有那么多
echo MSGBOX "YOUR MESSAGE" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q
可能会显示一点闪光,但不需要临时文件。应该可以追溯到(IIRC)IE5时代的某个地方 如果您正在使用
if
,请不要忘记:
if 1 == 1 (
mshta javascript:alert^("1 is equal to 1, amazing."^);close^(^);
)
你可以用。Zenity允许在命令行和shell脚本中执行对话框。有关更多信息,请访问
它是跨平台的:可以找到Windows的Windows安装程序。msg*/server:127.0.0.1在此处键入消息
echo X=MsgBox("Message Description",0+16,"Title") >msg.vbs
–您可以写0,1,2,3,4中的任何数字,而不是0(在“+”符号之前)&以下是每个数字的含义:
0 = Ok Button
1 = Ok/Cancel Button
2 = Abort/Retry/Ignore button
3 = Yes/No/Cancel
4 = Yes/No
16 – Critical Icon
32 – Warning Icon
48 – Warning Message Icon
64 – Information Icon
–您可以写16,32,48,64中的任意数字,而不是16(在“+”符号之后)&以下是每个数字的含义:
0 = Ok Button
1 = Ok/Cancel Button
2 = Abort/Retry/Ignore button
3 = Yes/No/Cancel
4 = Yes/No
16 – Critical Icon
32 – Warning Icon
48 – Warning Message Icon
64 – Information Icon
没有别的办法了
1)最极客、最黑的——它使用IEXPRESS创建小型exe,只需一个按钮即可创建弹出窗口()。适用于XP及以上版本的所有windows:
;@echo off
;setlocal
;set ppopup_executable=popupe.exe
;set "message2=click OK to continue"
;
;del /q /f %tmp%\yes >nul 2>&1
;
;copy /y "%~f0" "%temp%\popup.sed" >nul 2>&1
;(echo(FinishMessage=%message2%)>>"%temp%\popup.sed";
;(echo(TargetName=%cd%\%ppopup_executable%)>>"%temp%\popup.sed";
;(echo(FriendlyName=%message1_title%)>>"%temp%\popup.sed"
;
;iexpress /n /q /m %temp%\popup.sed
;%ppopup_executable%
;rem del /q /f %ppopup_executable% >nul 2>&1
;pause
;endlocal
;exit /b 0
[Version]
Class=IEXPRESS
SEDVersion=3
[Options]
PackagePurpose=InstallApp
ShowInstallProgramWindow=1
HideExtractAnimation=1
UseLongFileName=0
InsideCompressed=0
CAB_FixedSize=0
CAB_ResvCodeSigning=0
RebootMode=N
InstallPrompt=%InstallPrompt%
DisplayLicense=%DisplayLicense%
FinishMessage=%FinishMessage%
TargetName=%TargetName%
FriendlyName=%FriendlyName%
AppLaunched=%AppLaunched%
PostInstallCmd=%PostInstallCmd%
AdminQuietInstCmd=%AdminQuietInstCmd%
UserQuietInstCmd=%UserQuietInstCmd%
SourceFiles=SourceFiles
[SourceFiles]
SourceFiles0=C:\Windows\System32\
[SourceFiles0]
%FILE0%=
[Strings]
AppLaunched=subst.exe
PostInstallCmd=<None>
AdminQuietInstCmd=
UserQuietInstCmd=
FILE0="subst.exe"
DisplayLicense=
InstallPrompt=
或者在一行中:
mshta "about:<script>alert('Hello, world!');close()</script>"
或
3)这里是参数化的.bat/jscript
混合(应另存为bat
)。尽管有OP请求,但它仍然使用JavaScript,但由于它是一个bat,因此可以将其作为bat文件调用,而无需担心。它使用的是比更流行的更容易控制的。它使用WSH,但不像上面的示例中那样使用MSHTA
@if (@x)==(@y) @end /***** jscript comment ******
@echo off
cscript //E:JScript //nologo "%~f0" "%~nx0" %*
exit /b 0
@if (@x)==(@y) @end ****** end comment *********/
var wshShell = WScript.CreateObject("WScript.Shell");
var args=WScript.Arguments;
var title=args.Item(0);
var timeout=-1;
var pressed_message="button pressed";
var timeout_message="timed out";
var message="";
function printHelp() {
WScript.Echo(title + "[-title Title] [-timeout m] [-tom \"Time-out message\"] [-pbm \"Pressed button message\"] [-message \"pop-up message\"]");
}
if (WScript.Arguments.Length==1){
runPopup();
WScript.Quit(0);
}
if (args.Item(1).toLowerCase() == "-help" || args.Item(1).toLowerCase() == "-h" ) {
printHelp();
WScript.Quit(0);
}
if (WScript.Arguments.Length % 2 == 0 ) {
WScript.Echo("Illegal arguments ");
printHelp();
WScript.Quit(1);
}
for (var arg = 1 ; arg<args.Length;arg=arg+2) {
if (args.Item(arg).toLowerCase() == "-title") {
title = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-timeout") {
timeout = parseInt(args.Item(arg+1));
if (isNaN(timeout)) {
timeout=-1;
}
}
if (args.Item(arg).toLowerCase() == "-tom") {
timeout_message = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-pbm") {
pressed_message = args.Item(arg+1);
}
if (args.Item(arg).toLowerCase() == "-message") {
message = args.Item(arg+1);
}
}
function runPopup(){
var btn = wshShell.Popup(message, timeout, title, 0x0 + 0x10);
switch(btn) {
// button pressed.
case 1:
WScript.Echo(pressed_message);
break;
// Timed out.
case -1:
WScript.Echo(timeout_message);
break;
}
}
runPopup();
5)最后,对powershell进行一次调用,创建一个弹出窗口(如果安装了powershell,可以从命令行或批处理调用):
6)和德本汉姆的方法
7)对于系统托盘通知,您可以尝试:
它只需要在vm中弹出,因此从技术上讲,应该有一些代码,如:
if %machine_type% == virtual_machine then
echo message box code
else
continue normal installation code
如果将批处理文件转换(包装)为可执行文件,则可以执行此操作。%extd% /messagebox Title Text
%extd% /messagebox Error "Error message" 16
%extd% /messagebox Title "Try again or Cancel" 5
%extd% /messageboxcheck Title Message 0 {73E8105A-7AD2-4335-B694-94F837A38E79}
%extd% /messagebox Title Text
%extd% /messagebox Error "Error message" 16
%extd% /messagebox Title "Try again or Cancel" 5
%extd% /messageboxcheck Title Message 0 {73E8105A-7AD2-4335-B694-94F837A38E79}
%extd% /messagebox Title Text
%extd% /messagebox Error "Error message" 16
%extd% /messagebox Title "Try again or Cancel" 5
%extd% /messageboxcheck Title Message 0 {73E8105A-7AD2-4335-B694-94F837A38E79}
4)“永远不要再问我”消息框
%extd% /messagebox Title Text
%extd% /messagebox Error "Error message" 16
%extd% /messagebox Title "Try again or Cancel" 5
%extd% /messageboxcheck Title Message 0 {73E8105A-7AD2-4335-B694-94F837A38E79}
我想您可以从user32.dll调用dll函数 差不多 Rundll32.exe user32.dll,MessageBox(0,“text”,“titleText”,{最上面的MessageBox e.t.c类似的额外标志}) 在我的手机上输入,不要评判我。。。否则我会链接额外的标志
msg * /time:0 /w Hello everybody!
此消息将永远等待,直到单击“确定”(默认情况下仅持续一分钟),并在Windows 8.1中正常工作,这是一个更好的选项
设置my_message=Hello world
和&start cmd/c“@echo off&mode con cols=15行=2&echo%my_message%&pause>nul”
说明:
行数=
行数加1
cols=
消息中的字符数,加上3(但最小值必须为15
)
自动计算的cols
版本:
设置my_message=Hello world
&(echo%my_message%>EMPTY_FILE123&&FOR%?在(EMPTY_FILE123)中设置strlength=%~z?&&del EMPTY_FILE123)和启动cmd/c“@echo off&&mode con lines=2列=%strlength%&&echo%my_message%&&pause>nul”这里有一个PowerShell变体,在创建窗口之前不需要加载程序集,但是它的运行速度明显低于@npocmaka在此处发布的PowerShell MessageBox命令(~+50%):
powershell (New-Object -ComObject Wscript.Shell).Popup("""Operation Completed""",0,"""Done""",0x0)
Y