2

I have this VBS script to create a message box.

x=msgbox("The message" ,6, "Title")

But if i run another script with a different message it puts it on top. The vbs is been called from a batch file with this code:

@echo off & %temp%\message.vbs

My question is how do i make it so it replaces the message rather than putting it on top.

09stephenb
  • 9,358
  • 15
  • 53
  • 91

2 Answers2

3

VBScript allows replacing the text in the window, even from different scripts. Uses HTA, no temp files.

showmessage "Time is " & now

sub showmessage(text)
    ' source http://forum.script-coding.com/viewtopic.php?pid=75356#p75356
    dim shellwnd, proc, wnd
    on error resume next
    for each shellwnd in createobject("Shell.Application").windows
        set wnd = shellwnd.getproperty("messagewindow")
        if err.number = 0 then
            wnd.document.body.innerhtml = text
            exit sub
        end if
        err.clear
    next
    do
        set proc = createobject("WScript.Shell").exec("mshta ""about:<html><head><script>moveTo(-32000,-32000);</script><hta:application id=app border=dialog minimizebutton=no maximizebutton=no scroll=no showintaskbar=yes contextmenu=no selection=no innerborder=no /><object id='shellwindow' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shellwindow.putproperty('messagewindow',document.parentWindow);</script></head></html>""")
        do
            if proc.status > 0 then exit do
            for each shellwnd in createobject("Shell.Application").windows
                set wnd = shellwnd.getproperty("messagewindow")
                if err.number = 0 then
                    with wnd
                        .document.title = "Message"
                        .document.body.style.background = "buttonface"
                        .document.body.style.fontfamily = "verdana"
                        .document.body.style.fontsize = "0.7em"
                        .document.body.innerhtml = text
                        .resizeto 300, 150
                        .moveto 200, 200
                    end with
                    exit sub
                end if
                err.clear
            next
        loop
    loop
end sub
omegastripes
  • 12,351
  • 4
  • 45
  • 96
1

VBScript doesn't allow replacing the text in message boxes, not even from the same script.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328