为什么我的剧本不起作用?错误:“需要对象:WScript”并且不执行任何操作

时间:2017-06-17 23:57:24

标签: html vbscript

我正在尝试创建一个名为dummy.vbs的VBS文件,该文件会自动为我播放的视频游戏输入内容。它有一个HTA文件,名为start.hta,以方便人们使用它。但是,当我打开HTA文件时,它会显示this错误消息。当我点击“开始”按钮时,它什么也没做。

我该怎么办?这是HTA文件,然后是VBS文件。

<SCRIPT LANGUAGE="VBScript" src="dummy.vbs"> </SCRIPT>
<input type='button' value='Start' onclick='startLoop()'>
<input type='button' value='Stop' onclick='stopLoop()'>
<input type='button' value='Set Username To Pay' onclick='inputUsername()'>
<p>Won't work when stopped once; close and reopen. Sorry!</p>
<p> Make sure you set a username to pay, or else the thing won't work! </p>
<img src="think.png" alt="thonk"
style="width:200px;height:200px">
<p style="font-size:300%;","font-family:comicsansms;">Vncz</p>
Set objTimer = WScript.CreateObject("WScript.Shell")
Set objTyping = WScript.CreateObject("WScript.Shell")
loopState = true

Do While loopState = true

WScript.Sleep "5000"
objTyping.SendKeys "t"
WScript.Sleep "1000"
objTyping.SendKeys "/"
WScript.Sleep "50"
objTyping.SendKeys "s"
WScript.Sleep "50"
objTyping.SendKeys "e"
WScript.Sleep "50"
objTyping.SendKeys "l"
WScript.Sleep "50"
objTyping.SendKeys "l"
WScript.Sleep "50"
objTyping.SendKeys " "
WScript.Sleep "50"
objTyping.SendKeys "a"
WScript.Sleep "50"
objTyping.SendKeys "l"
WScript.Sleep "50"
objTyping.SendKeys "l"
WScript.Sleep "1000"
objTyping.SendKeys "~"
WScript.Sleep "1000"

objTyping.SendKeys "t"
WScript.Sleep "1000"
objTyping.SendKeys "/"
WScript.Sleep "50"
objTyping.SendKeys "p"
WScript.Sleep "50"
objTyping.SendKeys "a"
WScript.Sleep "50"
objTyping.SendKeys "y"
WScript.Sleep "50"
objTyping.SendKeys " "
WScript.Sleep "50"
objTyping.SendKeys "%usernameToPay%"
WScript.Sleep "50"
objTyping.SendKeys " "
WScript.Sleep "50"
objTyping.SendKeys "6"
WScript.Sleep "50"
objTyping.SendKeys "9"
WScript.Sleep "50"
objTyping.SendKeys "6"
WScript.Sleep "50"
objTyping.SendKeys "9"
WScript.Sleep "50"
objTyping.SendKeys "6"
WScript.Sleep "50"
objTyping.SendKeys "9"
WScript.Sleep "50"

Loop


Sub startLoop()
loopState = true
End Sub

Sub stopLoop()
loopState = false
End Sub

 Sub inputUsername()
usernameToPay = Inputbox("What is the username for your alt to pay? All 
lowercase; '+-' for underscores!","Username to Pay")
End Sub

希望你能帮忙,Vncz

编辑:新的VBS代码,仍然无效。

'''''Defining stuff to make the loop work'''''

Set WshShell = CreateObject("WScript.Shell")


Sub Wait(Time)
Dim wmiQuery, objWMIService, objPing, objStatus
 wmiQuery = "Select * From Win32_PingStatus Where Address = '1.1.1.1' AND 
Timeout = " & Time
 Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
 Set objPing = objWMIService.ExecQuery(wmiQuery)
 For Each objStatus in objPing
 Next
End Sub

loopState = false
















'Making a loop and telling it to do it only when the Start button is'
'''''pressed'''''


Do While loopState = true

Wait(5000)
WshShell.SendKeys "t"
Wait(1000)
WshShell.SendKeys "/"
Wait(50)
WshShell.SendKeys "s"
Wait(50)
WshShell.SendKeys "e"
Wait(50)
WshShell.SendKeys "l"
Wait(50)
WshShell.SendKeys "l"
Wait(50)
WshShell.SendKeys " "
Wait(50)
WshShell.SendKeys "a"
Wait(50)
WshShell.SendKeys "l"
Wait(50)
WshShell.SendKeys "l"
Wait(1000)
WshShell.SendKeys "~"
Wait(1000)

WshShell.SendKeys "t"
Wait(50)
WshShell.SendKeys "/"
Wait(50)
WshShell.SendKeys "p"
Wait(50)
WshShell.SendKeys "a"
Wait(50)
WshShell.SendKeys "y"
Wait(50)
WshShell.SendKeys " "
Wait(50)
WshShell.SendKeys " & usernameToPay & "
Wait(50)
WshShell.SendKeys " "
Wait(50)
WshShell.SendKeys "6"
Wait(50)
WshShell.SendKeys "9"
Wait(50)
WshShell.SendKeys "6"
Wait(50)
WshShell.SendKeys "9"
Wait(50)
WshShell.SendKeys "6"
Wait(50)
WshShell.SendKeys "9"
Wait(50)

Loop













'''''Defining what the buttons in the HTA do'''''


Function startLoop(loopState)
loopState = true
End Function

Function stopLoop(loopState)
 loopState = false
End Function

Sub inputUsername()
usernameToPay = Inputbox("What is the username for your alt to pay? All 
lowercase; '+-' for underscores!","Username to Pay")
End Sub

2 个答案:

答案 0 :(得分:0)

wscript对象仅在wscript.exe或cscript.exe中运行时可用。

VBscript有自己的CreateObject命令,是你应该使用的正常命令。

答案 1 :(得分:0)

从HTA运行的vbs文件不能使用wscript或cscript。您可以使用自定义函数代替wscript.sleep:

Sub Wait(Time)
  Dim wmiQuery, objWMIService, objPing, objStatus
  wmiQuery = "Select * From Win32_PingStatus Where Address = '1.1.1.1' AND Timeout = " & Time
  Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  Set objPing = objWMIService.ExecQuery(wmiQuery)
  For Each objStatus in objPing
  Next
End Sub

然后:

Wait(5000)
objTyping.SendKeys "t"
Wait(1000)
objTyping.SendKeys "/"
Wait(50)
...

您还需要更改Set objTimer = WScript.CreateObject(&#34; WScript.Shell&#34;)

for set objTimer = CreateObject(&#34; WScript.Shell&#34;)

换句话说:使用HTA时删除或替换所有wscript或cscript对象