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

前端 未结 4 1295
刺人心
刺人心 2021-02-05 14:35

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’

相关标签:
4条回答
  • 2021-02-05 15:16

    on command prompt:

    msg %username% Message
    

    interesting parameters are:

    /w        (wait for user) 
    /time:<seconds>
    
    0 讨论(0)
  • 2021-02-05 15:19

    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:

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

    and call it like this:

    cscript.exe PATH\Message.vbs

    0 讨论(0)
  • 2021-02-05 15:28

    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 "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 Run dialog from the Start menu, perhaps combined with the schtasks command to create a tea-timer…

    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.

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

    0 讨论(0)
  • 2021-02-05 15:35

    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.

    0 讨论(0)
提交回复
热议问题