VBS Replace message box instead of place on top

前端 未结 2 2023
轻奢々
轻奢々 2021-01-21 17:26

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

相关标签:
2条回答
  • 2021-01-21 17:49

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

    0 讨论(0)
  • 2021-01-21 18:00

    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
    
    0 讨论(0)
提交回复
热议问题