bil*_*lyy 144 windows command-line batch-file messagebox
有没有办法从批处理文件中显示消息框(类似于如何xmessage在Linux中使用bash-scripts)?
Joe*_*oey 124
首先,DOS与它无关,你可能想要一个Windows命令行解决方案(再次:没有DOS,纯Windows,不是一个窗口,而是一个控制台).
您可以使用boflynn提供的VBScript方法,也可以使用错误net send或msg.  net send仅适用于旧版本的Windows:
net send localhost Some message to display
这也取决于要运行的Messenger服务.
对于较新的版本(XP及以后,显然):
msg "%username%" Some message to display
应该注意的是,使用发送的消息框msg.exe仅持续60秒.但是,这可以通过/time:xx开关覆盖.
bof*_*ynn 115
我会创建一个非常简单的VBScript文件,并使用CScript调用它来解析命令行参数.
保存的内容如下MessageBox.vbs:
Set objArgs = WScript.Arguments
messageText = objArgs(0)
MsgBox messageText
您可以这样称呼:
cscript MessageBox.vbs "This will be shown in a popup."
Fow*_*owl 83
可能会显示一点闪存,但不需要临时文件.应该一直回到(IIRC)IE5时代的某个地方.
mshta javascript:alert("Message\n\nMultiple\nLines\ntoo!");close();
if 1 == 1 (
   mshta javascript:alert^("1 is equal to 1, amazing."^);close^(^);
)
Dav*_*ebb 72
这将弹出另一个命令提示符窗口:
START CMD /C "ECHO My Popup Message && PAUSE"
小智 33
试试:
Msg * "insert your message here" 
如果您使用的是Windows XP的command.com,则会打开一个消息框.
我收集的是,打开一个新的cmd窗口并不是你要求的.您也可以使用VBScript,并将其与.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>
然后,您将其保存为.vbs文件(通过在文件名的末尾添加".vbs"),在文件名下方的下拉框中另存为"所有文件"(因此它不会另存为.txt ),然后单击"保存"!
小智 27
这样您的批处理文件将创建一个VBS脚本并显示一个弹出窗口.运行后,批处理文件将删除该中间文件.
使用MSGBOX的优点是它确实可以使用(更改标题,图标等),而MSG.exe则没有那么多.
echo MSGBOX "YOUR MESSAGE" > %temp%\TEMPmessage.vbs
call %temp%\TEMPmessage.vbs
del %temp%\TEMPmessage.vbs /f /q
npo*_*aka 27
有更多的方法.
1)最怪异和最讨厌的 - 它使用IEXPRESS创建小exe,它将创建一个带有单个按钮的弹出窗口(它可以创建另外两种类型的弹出消息).适用于XP及以上版本的每个窗口:
;@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=
2)使用MSHTA.也适用于XP及以上版本的每台Windows机器(尽管OP不需要"外部"语言,这里的JavaScript最小化).应保存为.bat:
@if (true == false) @end /*!
@echo off
mshta "about:<script src='file://%~f0'></script><script>close()</script>" %*
goto :EOF */
alert("Hello, world!");
或者在一行中:
mshta "about:<script>alert('Hello, world!');close()</script>"
要么
mshta "javascript:alert('message');close()"
要么
mshta.exe vbscript:Execute("msgbox ""message"",0,""title"":close")
3)这是参数.bat/jscript化混合(应该保存为bat).尽管OP请求它再次使用JavaScript,但因为它是一个bat,它可以被称为bat文件而不用担心.它使用POPUP,比较流行的MSGBOX允许更多的控制.它使用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();
4)和一个   jscript.net/.bat混合(应该保存为.bat).这次它使用.NET并编译一个.exe可以删除的小文件:
@if (@X)==(@Y) @end /****** silent jscript comment ******
@echo off
::::::::::::::::::::::::::::::::::::
:::       compile the script    ::::
::::::::::::::::::::::::::::::::::::
setlocal
::if exist "%~n0.exe" goto :skip_compilation
:: searching the latest installed .net framework
for /f "tokens=* delims=" %%v in ('dir /b /s /a:d /o:-n "%SystemRoot%\Microsoft.NET\Framework\v*"') do (
    if exist "%%v\jsc.exe" (
        rem :: the javascript.net compiler
        set "jsc=%%~dpsnfxv\jsc.exe"
        goto :break_loop
    )
)
echo jsc.exe not found && exit /b 0
:break_loop
call %jsc% /nologo /out:"%~n0.exe" "%~f0" 
::::::::::::::::::::::::::::::::::::
:::       end of compilation    ::::
::::::::::::::::::::::::::::::::::::
:skip_compilation
::
::::::::::
"%~n0.exe" %*
::::::::
::
endlocal
exit /b 0
****** end of jscript comment ******/
import System;
import System.Windows;
import System.Windows.Forms
var arguments:String[] = Environment.GetCommandLineArgs();
MessageBox.Show(arguments[1],arguments[0]);
5)最后一次调用powershell创建一个弹出窗口(如果安装了powershell,可以从命令行调用或从批处理调用):
powershell [Reflection.Assembly]::LoadWithPartialName("""System.Windows.Forms""");[Windows.Forms.MessageBox]::show("""Hello World""", """My PopUp Message Box""")
6)这里看到了dbenham的方法
start "" cmd /c "echo(&echo(&echo              Hello world!     &echo(&pause>nul"
7)对于系统托盘通知,您可以尝试这样做:
call SystemTrayNotification.bat  -tooltip warning -time 3000 -title "Woow" -text "Boom" -icon question
Use*_*910 12
这是一个PowerShell变体,它不需要在创建窗口之前加载程序集,但是它运行速度明显慢于(〜+ 50%)@npocmaka发布的PowerShell MessageBox命令:
powershell (New-Object -ComObject Wscript.Shell).Popup("""Operation Completed""",0,"""Done""",0x0)
您可以将最后一个参数从"0x0"更改为下面的值,以在对话框中显示图标(有关进一步参考,请参阅弹出方法):
         0x10停止
 0x10停止
         0x20问号
 0x20问号
         0x30感叹号
 0x30感叹号
         0x40信息标记
 0x40信息标记
改编自Microsoft TechNet文章PowerTip:使用PowerShell显示弹出窗口.
p20*_*013 10
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,32,48,64而不是16(在'+'符号后面)的任何数字,这里是每个数字的含义:
16 – Critical Icon  
32 – Warning Icon  
48 – Warning Message Icon   
64 – Information Icon  
msg * /time:0 /w Hello everybody!
此消息将永远等待,直到单击“确定”(默认情况下仅持续一分钟)并且在 Windows 8.1 中正常工作
| 归档时间: | 
 | 
| 查看次数: | 538710 次 | 
| 最近记录: |