Windows 10 Home edition pulled msg.exe.
I need a sub that I can use to pop up message to the local user, NOT THE NETWORK, from a batch script.
Many thanks, -T
You can do this with a VBS script, something like:
set wshell = wscript.createobject("wscript.shell")
msg = "<No message provided>"
title = "Information"
timeout = 0
if wscript.arguments.count > 0 then
msg = wscript.arguments.item(0)
if wscript.arguments.count > 1 then
title = wscript.arguments.item(1)
if wscript.arguments.count > 2 then
timeout = wscript.arguments.item(2)
end if
end if
end if
wscript.quit(wshell.popup(msg, timeout, title, 0))
Just put that into paxmsg.vbs
and call it with:
cscript /nologo paxmsg.vbs "My text"
or:
cscript /nologo paxmsg.vbs "Text with 5s timeout" "My Title" 5
The basic usage is (a):
cscript /nologo paxmsg.vbs <optionalText> <optionalTitle> <optionalTimeout>
and you can discern the default values for each parameter from the first few lines of the script itself.
ERRORLEVEL
can be used in your batch script to detect whether OK
was pressed or it timed out (assuming non-zero timeout value, of course).
By way, of example, the following invocation:
cscript /nologo paxmsg.vbs "Dialog box with sample text" "Pax's dialog box"
results in:
(a) Note that using cscript
is most likely the behaviour you want, in that it will wait until the dialog box closes before continuing on with your batch script. If you want it to continue immediately, you can use wscript
instead.