Error: Object required: 'wscript' in HTA

与世无争的帅哥 提交于 2019-12-23 03:59:17

问题


I've been searching for awhile, but I cannot seem to find the answer. I am making a gui based program selector and I am quite new to VBS and HTA. I've made a auto-typer and I cannot seem to figure out why it does not work in HTA. It works fine on its own.

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


The HTA engine doesn't provide a WScript object, so things like WScript.Quit or WScript.Sleep don't work in HTAs. To programmatically exit from an HTA use Self.Close or window.Close. For replacing the Sleep method see the answers to this question.



来源:https://stackoverflow.com/questions/40476304/error-object-required-wscript-in-hta

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!