批处理文件- VBS替换消息框,而不是放在顶部



我有这个VBS脚本来创建一个消息框。

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

但是如果我用不同的消息运行另一个脚本,它会把它放在最上面。vbs是从批处理文件中调用的,代码如下:

@echo off & %temp%message.vbs

我的问题是我如何使它取代消息,而不是把它放在顶部。

VBScript允许替换窗口中的文本,即使是从不同的脚本。使用HTA,没有临时文件。

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

VBScript不允许替换消息框中的文本,即使来自同一脚本。

最新更新