Windows [cmd.exe] 命令显示超时的消息框?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21165565/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:16:33  来源:igfitidea点击:

Windows [cmd.exe] command to display a messagebox with timeout?

windowscmdcommandmessageboxwindows-shell

提问by Cheers and hth. - Alf

Note: This is a question-with-answerin order to document a technique that others might find useful, and in order to perhaps become aware of others’ even better solutions. Do feel free to add critique or questions as comments. Also do feel free to add additional answers. :)

注意:这是一个有问必答的问题,目的是记录其他人可能会发现有用的技术,并可能了解其他人的更好解决方案。请随意添加批评或问题作为评论。也可以随意添加其他答案。:)



How can I display a messageboxby typing a single Windows command, e.g. in the Rundialog from the Start menu, or in the [cmd.exe] command interpreter?

如何通过键入单个 Windows 命令来显示消息框,例如在开始”菜单的“运行”对话框中,或在 [cmd.exe] 命令解释器中?

回答by Cheers and hth. - Alf

One way is to use apparently undocumented functionality, namely that [mshta.exe], the runtime engine for Windows .hta HTML applications, accepts a general URL as command line argument, including a javascript:protocol URL:

一种方法是使用明显未公开的功能,即 [mshta.exe],Windows .hta HTML 应用程序的运行时引擎,接受通用 URL 作为命令行参数,包括javascript:协议 URL:

mshta "javascript:var sh=new ActiveXObject( 'WScript.Shell' ); sh.Popup( 'Message!', 10, 'Title!', 64 );close()"

            The resulting messagebox

            结果消息框

This command can be issued in e.g. [cmd.exe]], or e.g. in the Rundialog from the Start menu, perhaps combined with the schtaskscommand to create a tea-timer…

这个命令可以在例如 [cmd.exe]] 中发出,或者在开始菜单的运行对话框中发出,也许结合schtasks命令来创建一个茶计时器......

The above messagebox times out after 10 seconds, but specifying a 0 second timeout means “don’t time out”, producing a more ordinary persistent messagebox.

上述消息框在 10 秒后超时,但指定 0 秒超时意味着“不超时”,生成更普通的持久消息框。

For a simpler messagebox you can instead use the alertfunction provided by the MSHTA host.

对于更简单的消息框,您可以改用alertMSHTA 主机提供的功能。

回答by Stephan

on command prompt:

在命令提示符下:

msg %username% Message

interesting parameters are:

有趣的参数是:

/w        (wait for user) 
/time:<seconds>

回答by user4641788

Found that if you copy msg.exe from a Win7 Pro machine to a Win7 Home machine it works. Copy msg.exe to and from the C:\Windows\System32 folder.

发现如果您将 msg.exe 从 Win7 Pro 机器复制到 Win7 Home 机器,它可以工作。将 msg.exe 复制到 C:\Windows\System32 文件夹或从 C:\Windows\System32 文件夹复制。

回答by Panayotis

What if you create a small VBScript with the message you want to display? I.e. create e file, named "Message.vbs" with the content:

如果您使用要显示的消息创建一个小的 VBScript 怎么办?即创建 e 文件,命名为“Message.vbs”,内容如下:

MsgBox "Some info here", 0, "Message Title"

MsgBox "Some info here", 0, "Message Title"

and call it like this:

并这样称呼它:

cscript.exe PATH\Message.vbs

cscript.exe PATH\Message.vbs