Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTA create vbscripts on the fly

Tags:

vbscript

hta

Is there a way in HTA to read a file containing vbscript and dynamically add it to a subroutine ? so than when i click on a button that subroutine gets called having the vbscript which is read from the file having it ?

I have tried reading the file and storing it to a variable. and i know u cant execute a variable. so how do we achieve this ?

typically i need a way to populate data inside

<script language="VBScript">
..........
.........
text from the file
..........
.........
</script>

is this possible ? or if it cant be hard coded some how can run the script ?.. creating a Wscript shell and pointing to the file using cscript wont work cause im using other objects in the vbs that require HTA to work.

help is needed thanks :)

like image 624
Mani kv Avatar asked Apr 29 '26 19:04

Mani kv


1 Answers

It is possible. You need to use the ExecuteGlobal() function to add your dynamic code to your HTA. Here's an example.

Code to dynamically import (let's call it c:\library.vbs):

Sub ImportedLater()
    MsgBox "I am not part of the HTA. I was imported later."
End Sub

Ad then, in your HTA:

<html>
<head>
    <title>HTA Test</title>
    <HTA:APPLICATION>
</head>

<body>
    <button onclick="Test()">Click me</button>
</body>

<script language="VBScript">

    ' Add code from VBS file to global scope...
    ExecuteGlobal CreateObject("Scripting.FileSystemObject").OpenTextFile("c:\library.vbs").ReadAll()

    Sub Test()

        ' Button clicked. Call an imported function...
        ImportedLater

    End Sub

</script>
</html>

This should display the message in the ImportedLater subroutine.

like image 68
Bond Avatar answered May 02 '26 12:05

Bond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!