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

Cheers and hth. - Alf picture Cheers and hth. - Alf · Jan 16, 2014 · Viewed 63.3k times · Source

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, e.g. in the Run dialog from the Start menu, or in the [cmd.exe] command interpreter?

Answer

Cheers and hth. - Alf picture Cheers and hth. - Alf · Jan 16, 2014

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.