Gabriel M.
Gabriel M.

Reputation: 21

Running cmd from HTA file

I am new to scripting ,vbs and HTA commands but I have tryed to create a simple hta folder with some text boxes that represent a date and the current time and I need to run a specific cmd command that takes that date/hour and use them in the specified commad.I think you will understand more when you read the code.I appologise in advance for the mistakes.

<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION 
 ID="objTest" 
 APPLICATIONNAME="HTA Test"
 SCROLL="no"
 SINGLEINSTANCE="yes"
>
</head>

<SCRIPT LANGUAGE="VBScript">
Sub TestSub
Dim Shell
Set Shell = WScript.CreateObject ("WScript.Shell")
Shell.run WScript "cmd /g applStart.sh SetTime.dat Year.Value-Month.Value-Day.Value-          Hour.Value-Minute.Value-Second.Value"
Set Shell = Nothing
End Sub
</SCRIPT>
<body>
 Type in the date you want to jump to:</br>

<input type="number" name="Day" size="2">
<input type="number" name="Month" size="2">
<input type="number" name="Year" size="4">
<input type="number" name="Hour" size="2">
<input type="number" name="Minute" size="2">
<input type="number" name="Second" size="2">

<input id=runbutton  type="button" value="Run Script" name="run_button"   onClick="TestSub">

Hey, thanks for the rapid responses.I have managed to get it to run a part of what i want.The part of settime.sh was actually a command in putty and i didn't quite realise it at the moment of writing but i have managet to get it to a point where it runs putty when I press the run button.Now I need it to type in the command with the values given by the user in the text boxes.This is what I have so far: HTA Test

<SCRIPT LANGUAGE="VBScript">
Sub RunProgram 
    Set objShell = CreateObject("Wscript.Shell")
    objShell.Run "C:\Users\uidv4860\Desktop\Getlogs\PuTTY\putty.exe -load EOBR"
End Sub

</SCRIPT>
<body>
Type in the date you want to jump to:</br>
Day:
<input type="int" name="fDay" size="2" maxLength="2">
Month:
<input type="int" name="fMonth" size="2" maxLength="2">
Year:
<input type="int" name="fYear" size="4" maxLength="4">
Hour:
<input type="int" name="fHour" size="2" maxLength="2">
Minute:
<input type="int" name="fMinute" size="2" maxLength="2">
Second:
<input type="int" name="fSecond" size="2" maxLength="2">
<button onclick="RunProgram">Run Program</button> <p>
</body>

Upvotes: 2

Views: 14395

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200573

Shell.run WScript "cmd /g applStart.sh SetTime.dat Year.Value-Month.Value-Day.Value-Hour.Value-Minute.Value-Second.Value"

I see several mistakes in the above statement:

  • There's a spurious WScript.
  • CMD.EXE doesn't have an option /g. Did you mean /c?
  • .sh is an extension typically used for Linux/Unix shell scripts. Windows batch files have the extension .bat or .cmd.
  • VBScript doesn't expand variables inside strings, so you need to concatenate your variables with the string literals.

Also, I'd append , 0, True to the statement, so that the CMD instance runs hidden and the code waits for the external command to complete.

Try this:

Shell.run "cmd /c applStart.cmd SetTime.dat " _
  & Year.Value & "-" & Month.Value & "-" & Day.Value & "-" _
  & Hour.Value & "-" & Minute.Value & "-" & Second.Value, 0, True

Upvotes: 1

Related Questions