I am stuck on an issue trying to get away from the cmd popup and have all the data from the command to appear in span tag. I know just enought to get the command to work but not sure how to make it output into HTA. If somebody can please help me fill in the blanks I would be greatful. Again I am not the best at this coding what so ever.
<!doctype html>
<html>
<head>
<title>My HTA</title>
<meta http-equiv="X-UA-Compatible" content="IE=9">
<style>
body { font-family: 'Segoe UI'; font-size: 10pt; }
</style>
<HTA:APPLICATION
ID="MyHTA"
INNERBORDER="no"
CONTEXTMENU="no"
/>
<script>
window.onload = function sizeIt()
{
var sw = (screen.width-500)/2;
var sh = (screen.height-300)/2;
window.moveTo(sw,sh);window.resizeTo(678,590)
}
</script>
<script language="VBScript">
Sub displayinfo()
Dim infox
infox = (txt_info.value)
Set oShell = CreateObject ("WScript.Shell")
oShell.run "cmd.exe /k" & infox
Set oShell = Nothing
dataarea.innerhtml = "<font color='red'><b>URL: </b></font>" & infox
End Sub
</script>
</head>
<body bgcolor="gray">
<!--{{InsertControlsHere}} - Do not remove this line-->
<div align="center">
<font color="blue"><b>UR</b>L</font> <b>:</b> <input type="text" size="60" name="txt_info">
<br><br><br>
<input type="button" value="Submit" onClick="displayinfo()">
<br><br><br>
<span id="dataarea" style="vertical-align: middle;"><center>Information comes out here</center></span>
</div>
</body>
</html>
I read other post that was close to it but I cannot figure it out from what I am trying to do.
Creating a GUI to take a console command and then display the result is reinventing the wheel. You're better off using the console, especially if you want to see the results as they're generated (i.e. for long running commands). See this discussion for details:
HTA as a Command Line GUI
However, if it's for a special situation (i.e. not a full console replacement) and you're okay with getting the output in one splat, then you can use the
Runmethod to hide the console window and direct the output to a temp file to read back into a variable in the HTA.Here's an example, based on the code in the question.
VBScript Version
JScript Version
Note that JScript is much more case-sensitive than VBScript. For example "innerText" can be any case in VBScript, but must be "innerText" in JScript.
Also note that in VBSCript, the file gets closed immediately after the readall without additional code, but in JScript, the file will remain open until the HTA is closed, so we should have an explicit close in JScript.