Skip to content

Instantly share code, notes, and snippets.

@SethVandebrooke
Last active August 3, 2022 04:54
Show Gist options
  • Save SethVandebrooke/ab3842b5534f2e27b532beb711c31015 to your computer and use it in GitHub Desktop.
Save SethVandebrooke/ab3842b5534f2e27b532beb711c31015 to your computer and use it in GitHub Desktop.
Self Modifying HTA file ( HTML + VBS + JavaScript)
<head>
<title>HTA Test</title>
<HTA:APPLICATION
APPLICATIONNAME="Application"
SCROLL="no"
SINGLEINSTANCE="yes"
>
</head>
<script language="VBScript">
Function say(msg)
Msgbox msg
End Function
Sub writeToFile
strFilePath = "personList.hta"
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set file = objFSO.OpenTextFile(strFilePath, 1)
strFile = file.ReadAll
fname = InputBox("Please enter first name.", 1)
lname = InputBox("Please enter last name.", 1)
r = "//DATA_" + "INSERTION"
strFile = Replace(strFile, r, ",{ firstName: '" + fname + "', lastName: '" + lname + "' }" + vbCrLf + r)
Set objFile = objFSO.CreateTextFile(strFilePath,True)
objFile.Write strFile
objFile.Close
Set output = document.getElementById("people")
output.InnerHTML = output.InnerHTML + "<p>" + fname + " " + lname + "</p>"
Msgbox "Finished!"
End Sub
</script>
<body style="text-align:center;">
<input type="button"
value="Add Person"
name="run_button"
onClick="writeToFile"
>
<div id="people">
</div>
<script type="text/javascript">
var people = [
{ firstName: '', lastName: '' }
//DATA_INSERTION
];
var str = "";
for (var i = 0; i < people.length; i++) {
var p = people[i];
str += "<p>" + p.firstName + " " + p.lastName + "</p>";
}
document.getElementById("people").innerHTML = str || "";
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment