错误:需要对象:' wscript'在HTA

时间:2016-11-07 23:05:53

标签: vbscript hta

我一直在寻找,但我似乎无法找到答案。我正在制作一个基于gui的程序选择器,我对VBS和HTA很新。我已经做了一个自动轮询,我似乎无法弄清楚为什么它在HTA中不起作用。它本身很好用。

<head>
<title>Gui Bases Program Selector.</title>
<HTA:APPLICATION 
     APPLICATIONNAME="HTA Test"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="maximize"
>
</head>

<script language="VBScript">
Sub TestSub
    Set shell = CreateObject("wscript.shell") 
    strtext  = InputBox("What Do you want your message do be?")
    strtimes = InputBox ("How many times would you like you type it?")
    If Not IsNumeric(strtimes) Then
        lol = MsgBox("Error = Please Enter A Number.") 
        WScript.Quit
    End If
    MsgBox "After you click ok the message will start in 5 seconds "
    WScript.Sleep(5000)
    Tor i=1 To strtimes
        shell.SendKeys(strtext & "")
        shell.SendKeys "{Enter}"
        WScript.Sleep(75)
    Next
End Sub
</script>

<body>
<input type="button" value="AutoTyper" name="run_button"  onClick="TestSub"><p> 
</body>

1 个答案:

答案 0 :(得分:0)

HTA引擎无法提供WScript对象,因此WScript.QuitWScript.Sleep等内容无法在HTA中发挥作用。要以编程方式退出HTA,请使用Self.Closewindow.Close。要替换Sleep方法,请参阅this question的答案。