【问题标题】:Running cmd from HTA file从 HTA 文件运行 cmd
【发布时间】:2013-08-13 17:00:17
【问题描述】:

我是脚本、vbs 和 HTA 命令的新手,但我尝试创建一个简单的 hta 文件夹,其中包含一些代表日期和当前时间的文本框,我需要运行一个特定的 cmd 命令,该命令需要该日期/小时并在指定的逗号中使用它们。我想您阅读代码后会理解更多。对于错误,我提前致歉。

<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">

嘿,感谢您的快速响应。我已经设法让它运行我想要的一部分。settime.sh 的部分实际上是 putty 中的一个命令,我当时并没有完全意识到正在写作,但我已经设法让它在我按下运行按钮时运行腻子。现在我需要它用用户在文本框中给出的值输入命令。这就是我到目前为止所拥有的: HTA测试

<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>

【问题讨论】:

    标签: vbscript scripting cmd hta


    【解决方案1】:
    Shell.run WScript "cmd /g applStart.sh SetTime.dat Year.Value-Month.Value-Day.Value-Hour.Value-Minute.Value-Second.Value"
    

    我在上面的语句中看到了几个错误:

    • 有一个虚假的WScript
    • CMD.EXE 没有选项 /g。你是说/c吗?
    • .sh 是一个通常用于 Linux/Unix shell 脚本的扩展。 Windows 批处理文件的扩展名为 .bat.cmd
    • VBScript 不会在字符串中展开变量,因此您需要将变量与字符串文字连接起来。

    另外,我会将, 0, True 附加到语句中,以便CMD 实例隐藏运行,代码等待外部命令完成。

    试试这个:

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

    【讨论】:

    • 我刚开始学习 2 天前所以再次请原谅我和代码不匹配。我已经尝试过批处理文件和 vbs 脚本,这就是您看到 WScript 的原因。是的,它应该是 /c 但我又有点困惑。关于脚本,我尝试了您的建议,但出现错误:错误的争论数量或无效的属性分配:'Year'
    • Year(以及MonthDay、...)是 VBScript 内置函数的名称。将输入字段的名称更改为与内置函数名称不冲突的名称,例如fyear, fmonth, fday, ...
    猜你喜欢
    • 2022-01-05
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多