Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 859
Cheers and hth. - Alf Avatar asked Jan 16 '14 15:01

Cheers and hth. - Alf


People also ask

How do you show messages in CMD?

To display a message that is several lines long without displaying any commands, you can include several echo <message> commands after the echo off command in your batch program. After echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt, type echo on.

What is Windows timeout command?

You can use Timeout command in Windows to stop the execution for some time and then continue. you can specify the number of seconds to wait, it would wait till the time elapses or until user presses any key. For example: C:\>Timeout 10. Windows will pause the execution for 10 seconds, you may press a key to continue.

What does MSG * Do in Command Prompt?

The msg command is a Command Prompt command that's used to send a message to one or more users on the network using the Command Prompt.


2 Answers

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.

like image 78
Cheers and hth. - Alf Avatar answered Oct 01 '22 19:10

Cheers and hth. - Alf


on command prompt:

msg %username% Message

interesting parameters are:

/w        (wait for user) 
/time:<seconds>
like image 35
Stephan Avatar answered Oct 01 '22 18:10

Stephan