VBS Replace message box instead of place on top

こ雲淡風輕ζ 提交于 2019-12-02 01:21:17

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!