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

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?

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

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. Copy msg.exe to and from the C:\Windows\System32 folder.

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

Related

Alternative to cmd and powershell for stdout output only

My use case:
I kick-off a Python script from a button within Excel to do some data aggregation. The setup currently works nicely, but I would like:
Cmd to never accidentally pause - it's a known feature of the command prompt to pause on any text selection: Avoid pausing tasks when select something on PowerShell and Command Prompt
To let the cmd prompt look more like a pop-up
I have noticed NSIS installers outputs it's commands in a little logging box:
Question:
I would like to know if there are any programs out there that does most of what I want already. E.g. something like RunLikePopup.exe c:\path\to\script.bat, with output like:
Not sure what you are really after. I 'll give it a try.
In case you build an application as 'console'-only than that results in a 'command-line-interface [CLI]' Look-and-feel. Plane and simple. The output of a NSIS script (.nsi file) can not be paused as it is simply the output of the compiler executing the script code. 'Pausing' that would instantly mean pausing the compiler to do its work. I see no reason why you would want that.
Example Unix 'more' command (sending text oriented content to stdout. CLI...)
https://en.wikipedia.org/wiki/More_(command)
In case you need to 'catch' the output from the NSIS compiler here is what you need to do:
run NSIS from (Windows) CLI:
makensis [ option | script.nsi | - ] [...] > compiler_log.txt
What you appear to want is typically named 'output redirect'. (https://ss64.com/nt/syntax-redirection.html). In case you need to 'catch' the outpout from a NSIS script at compile time, please use NSIS ' CLI and redirect the (compilers) output to any text file (e.g. compiler_output.txt)
PS. In order to ensure receiving good quality answers, try to be as specific as you can in your questions.
I have written a Freeware editor ME "Martins Editor" where you can send text via inpipe:
[C:\]dir /s | me in
"in" always shows the first page (does not scroll), "ins" scrolls and "inp" scrolls page by page. In this context, "me in" is a substitute for "more".
Then you will see the output in the editor. ME is a simple editor with the focus on multiplatform text (different EOL encodings, codepages). It has additional Wordstar ("IDE classic") key setting and HTML/XML highlightning. It is available for Windows, OS/2, Linux and MacOS.
http://www.hypermake.com/english/betatest.html#hd117
The 2016 version is still current. In the next weeks, I publish a new version.
I am working on a cmd.exe window replacement (commandline frontend) "MeShell" based on ME with look-and-feel of a normal commandline window. Because on the lack of a modern comfortable commandline window on the old OS/2 platform which is still alive (http://www.arcanoae.com), I will publish an OS/2 version first. If this version works fine, I will publish a Windows version later. In the context of MeShell, I improve the inpipe functionality of ME which is still buggy and does not support colors in the 2016 version.

How to comfortably monitor variables in a VBscript during development process? (e.g. in a continuously opened command window)

I need to write a huge VBscript to automatically run an application and I'm looking for a way to comfortably monitor what I'm actually doing, in other words, to display the values of some/all variables involved in my script.
I'm used to work with Matlab, where I have a comfortable workspace browser. When I run a Matlab script, all variables, their types and their values are accessible in that workspace and can be checked.
The VBscript I write with Notepad++ (it needs to be a free editor) and the only way I found to display variables was echoing them via wscript and cscript.
I set up the shortcuts.xml with the following line to run my script directly from Notepad++:
<Command name="Run with CScript" Ctrl="yes" Alt="no" Shift="yes" Key="116">cmd /K %windir%\system32\cscript.exe "$(FULL_CURRENT_PATH)"</Command>
In case I include commands in my script like
Wscript.Echo myVar
Wscript.Echo "Hello World!"
and run it with the newly introduced shortcut, a cmd window pops up and displays the value of myVar and "Hello World!".
But the next time I run the script a new window pops up. So my question is:
Is it possible get a continuously opened output window, displaying all echoed values everytime I run a script? I actually want to put the window on a second screen and keep the values from previous runs. So I can enter a line Wscript.Echo something, run, check, enter something else and so on, without fiddling around with a bunch of opened windows.
Alternatively, is there any open-source/free editor which offers an accessible workspace like the one in Matlab?
The open-source editor SciTE offers what I was looking for.
The default settings in vb.properties enable a similar behavior like in Notepad++
command.build.$(file.patterns.wscript)=cscript "$(FilePath)"
command.build.subsystem.$(file.patterns.wscript)=1
One can change it as follows to get the output into the integrated console.
command.go.$(file.patterns.wscript)=cscript.exe //nologo "$(FilePath)"
command.go.subsystem.$(file.patterns.wscript)=0
F5 runs the script and Shift+F5 cleans the output.
Another option is the NppExec Plugin for Notepad++ suggested by #Ansgar Wiechers, which adds a console. The script can be run with cscript.exe /nologo "$(FULL_CURRENT_PATH)" then.
Use a debugger. Start your script with the (meta)option //X. If you are lucky, you already have installed software (MS Office, Visual Studio (Express)) that provides a debugger for VBScript. If not do a bit of research to find an Express version suitable to your OS.
You can almost write native VBScript in the VBA editor, so if you have Excel or whatever you can use this to debug, then go through some steps to convert back to VBScript. That's what I usually do.

how do i get console to notify me when it is finished running a script

I am using nant, but this can apply to any thing, I just want to know if there is a way to set windows cmd or console2 or some kind of shell to give me a popup or make a noise when it is "finished" (i.e. when it is waiting and the screen says >C:\User\Random_FILE_PATH>_)
I'm using windows 7.
Valentine
sorry, to clarify, I am not running a script that I created, this is just when running anything in the console. I would like it to be that anytime my console is waiting for me it creates a pop up or a noise. This would ideally be some kind of setting
You may open a message box in the end of your batch file, using WSH with a simple VBScript or JScript. See Show a popup/message box from a Windows batch file for an example.
c:\> my_command & mshta.exe vbscript:Execute("msgbox ""finished"",0,""finished"":close")
this here uses conditional execution - when my_command is finished the mshta.exe will be executed with arguments in the brackets.As the parameter passing here is not so easy the string given to msgbox will not be displayed.
you can add a beep to your prompt:
set prompt=%prompt%^G
Don't type ^G. To get it, keep your alt-key pressed while entering 0 0 7 on your numeric keyboard.

General Question about a GUI to execute a batch file

I'm new to programming and have taken some classes in it so I'm not sure if this is possible. I want to use a COTS software called 010 Hex Editor and write a script for the program to automate a couple tasks. These tasks can be run from a batch file according to their documentation.
Then I want to instruct the user to eject the device and reinsert it to clear the cache. (This I want done just with a simple pop-up window.
Then I also want to format the device which I assume can be done in a batch file as it can be done through dos on Windows.
My question is, with these 3 steps, can I build a simple GUI that has a button that says, "Start" or something like that, then the pop up window comes up to eject and reinsert, and then another button to format, and another button to exit. I'm not really familiar with what language this could be done in, and how to do this as the C++/Java classes I've taken have been more about syntax and OOP. Thanks!
You can use the windows messenger service to put up an alert - but on newer windows (vista/7) it's a pain to set all the permissions to allow this.
There are lots of free utilities that will popup a dialog from the command line, with a given message and wait for a response.
They are generally called messagebox or msgbox - sorry can't recommend any in particular

How to show a popup without a browser

I need an "alert" type feature to troubleshoot an error. I am not using a browser and using javascript as windows administaration purposes. So is their a way to view a varibales value if I am not using a browser?
JScript is a scripting language based on the ECMAScript standard.
JScript is implemented as a Windows Script engine. This means that it can be plugged in to any application that supports the Windows Script host, such as Internet Explorer, Active Server Pages, etc. It also means that any application supporting Windows Script can use multiple languages — JScript, VBScript, Perl, and others.
For reasons that I am not sure about, but I believe it to be related to the fact the the DOM is not available outside the browser, the alert function is also not available outside the browser. In order to popup a dialog box to the user in this case you can use the following code:
WScript.Echo('The quick brown fox jumped over the lazy dog');
If you want a windows GUI popup, then:
var timeout = 0;
var buttons = 0; // OK
var icon = 48; // Exclamation
var shell = new ActiveXObject("WScript.Shell");
shell.Popup("text ...", timeout, "window title", buttons + icon);
and run your jscript program with the wscript command.
Microsoft JScript language reference.
Popup documentation.
On windows, you can use Windows Script Host to execute your javascript. It has a built in ability to do output, using Echo. There are some nuances though, since WSH uses jscript, not javascript, though the languages are similar.
A summary of the differences between WScript.Echo and WshShell.Popup:
Windows scripts (vbs, js, wsf etc.) can be run under one of two hosts: cscript.exe (command-line), and wscript.exe (graphical). Under cscript, WScript.Echo will produce a line of text in the console window. WshShell.Popup will always produce a message window, even under cscript.
WshShell.Popup lets you specify the buttons, title and icon type, like the VB/VBS MessageBox function. It also lets you specify how long the message should remain open.
WScript.Echo lets you pass multiple string arguments to output, and will print them separated with spaces.
You can create a simple file that will alert text that is passed to it, for example in python. I don't think there is any way to do this in Javascript though without a browser.
No with javascript. You can, using Visual Basic Script and MsgBox function. No need to install anything.
'In Hello.vbs. Comments starts with '
MsgBox "Hello there"
Look at HTA files. These file types allow you to run typical HTML/VBScript/JS code without the need for a browser specifically. Just rename your HTML file to an HTA extension and run it. IT will show your "page" and execute any JS necessary. This type of file will give you access to other WScript functions as well like creating Files or accessing AD if required.

Resources