-1

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

Todd
  • 976
  • 4
  • 10

1 Answers1

0

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:

enter image description here


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

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Anything that is not a vbs script? – Todd Oct 16 '19 at 03:35
  • 1
    @Todd: yes, I could write a C++ program which does the same thing. But, since VBScript has been a core part of Windows for quite a while now, it's probably easier just to use that. – paxdiablo Oct 16 '19 at 03:42
  • Todd, yes, an executable would be the best format but I *wasn't* offering to write it since it would give you nothing that the already-existing `cscript` executable (which comes with Windows) gives you with the script I provided. You asked a question on how to do something, I provided an easy way. If you want to go off and do it in a *harder* way, that's fine, but I'm not keen on assisting in that :-) – paxdiablo Oct 16 '19 at 07:59
  • I just wanted to stay away from VBS Scripts – Todd Oct 16 '19 at 08:22
  • I was hoping to find someone that had already written collection of exe's for such. I also do not like the security issues with VBS – Todd Oct 16 '19 at 08:32
  • @Todd, that would probably have been instantly closed: "Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. " – paxdiablo Oct 16 '19 at 08:33
  • Is there a way to get this forum to eMail you when someone responds? – Todd Oct 16 '19 at 08:33
  • Not easily, since it's *not* meant to be a forum/conversation-board. You'll be notified by virtue of the fact I'm referencing your name (@Todd) in messages but, since the intent is a Q&A for *everyone* in the future rather than just the asker, I don't believe that's high priority. You can ask over at meta if you wish. – paxdiablo Oct 16 '19 at 08:36