简体   繁体   English

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

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

Note: This is a question-with-answer in 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 messagebox by typing a single Windows command, eg in the Run dialog from the Start menu, or in the [cmd.exe] command interpreter? 如何通过键入单个Windows命令来显示消息框 ,例如在开始”菜单的“运行”对话框中,或在[cmd.exe]命令解释器中?

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()"

结果消息框

This command can be issued in eg [cmd.exe]], or eg in the Run dialog from the Start menu, perhaps combined with the schtasks command 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 alert function provided by the MSHTA host. 对于更简单的消息框,您可以使用MSHTA主机提供的alert功能。

on command prompt: 在命令提示符下:

msg %username% Message

interesting parameters are: 有趣的参数是:

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

Found that if you copy msg.exe from a Win7 Pro machine to a Win7 Home machine it works. 发现如果将msg.exe从Win7 Pro计算机复制到Win7 Home计算机,则可以正常工作。 Copy msg.exe to and from the C:\\Windows\\System32 folder. 将msg.exe复制到C:\\ Windows \\ System32文件夹并从其中复制。

What if you create a small VBScript with the message you want to display? 如果使用要显示的消息创建一个小的VBScript,该怎么办? Ie create e file, named "Message.vbs" with the content: 即创建一个名为“ Message.vbs”的文件,其内容为:

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

and call it like this: 并这样称呼它:

cscript.exe PATH\\Message.vbs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM