Script funciona bem como .wsh, vai berzerk na HTA

0

Eu tenho um código que envia chaves para o Telnet para manipular um transmissor IR meu. O script funciona bem como um script autônomo do WSH, mas assim que eu tento colocá-lo em um Sub dentro de um HTA ele vai para BERZERK. Em vez de enviar minhas chaves para a primeira instância do cmd, ele abre uma nova para cada .sendkey!

Por favor, ajude!

Este é o meu script autônomo de trabalho:

    <job>
<script language="VBScript">
Option Explicit
On Error Resume Next
Dim WshShell
set WshShell=CreateObject("WScript.Shell")
WshShell.run "cmd.exe"
WScript.Sleep 500


WshShell.SendKeys "telnet 130.160.176.219 4998"

WshShell.SendKeys ("{Enter}")
WScript.Sleep 5000


WshShell.SendKeys "sendir,1:1,1,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,64,21,22,21,64,21,22,21,22,21,22,21,22,21,64,21,22,21,64,21,22,21,64,21,64,21,64,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "sendir,1:1,10,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,22,21,22,21,22,21,64,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,22,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "sendir,1:1,5,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,64,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,22,21,64,21,64,21,64,21,64,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "sendir,1:1,11,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,64,21,64,21,64,21,64,21,22,21,64,21,22,21,64,21,22,21,22,21,22,21,22,21,64,21,22,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 500
WshShell.SendKeys "sendir,1:1,1,37764,1,1,340,168,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,22,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,64,21,22,21,64,21,22,21,64,21,22,21,22,21,22,21,22,21,64,21,22,21,64,21,22,21,64,21,64,21,64,21,64,21,4833"
WshShell.SendKeys ("{Enter}")
WScript.Sleep 1000
WshShell.SendKeys ("^{]}q{Enter}exit{Enter}")
WScript.Quit 
</script>
</job>
    
por jake 06.05.2015 / 19:06

1 resposta

0

WScript.Sleep 500

não funciona em um HTA. Existe isto a partir de uma janela do IE (o HTA tem um)

setTimeout Method

--------------------------------------------------------------------------------

Evaluates an expression after a specified number of milliseconds has elapsed. 

Syntax

iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])
Parameters

vCode Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed. 
iMilliSeconds Required. Integer that specifies the number of milliseconds. 
sLanguage Optional. String that specifies one of the following values: JScript Language is JScript. 
VBScript Language is VBScript. 
JavaScript Language is JavaScript. 


Return Value

Integer. Returns an identifier that cancels the evaluation with the clearTimeout method. 

Remarks

Sempre use WshShell.AppActivate antes de enviar as chaves, caso contrário você não sabe para onde elas estão indo.

Como você está usando o TELNET e não o CMD, não faz sentido iniciar o cmd e pedir que ele inicie o telnet. Basta iniciar o telnet direto.

    
por 06.05.2015 / 21:43

Tags