student001 student001 - 3 months ago 36
Bash Question

javascript hta application as GUI for command prompt

I need to create a simple HTA application that will ask for a command, then when I press a button that command should be executed in command prompt.

I have the following script so far which will only open a command prompt window but not read and run the script entered into the text box.

<html>
<head>

<HTA:APPLICATION>

<script type="text/javascript" language="javascript">

function Run() {

x = document.getElementById("command").value;
shell = new ActiveXObject ("Shell.Application");
shell.ShellExecute("cmd.exe", "/k ", "", "open", 1);
}

</script>
</head>

<body bgcolor="grey">
<form>
<h1> Enter MS-DOS Command </h1>
<p> eg: ipconfig </p>

<textarea cols="20" rows="1" id="command"> </textarea> <br> <br>

<input type="button" value="Run" onclick="Run();">

</form>
</body>
</html>

Answer

Use:

shell.ShellExecute("cmd.exe", "/k " + x, "", "open", 1);