我是 VBScript 和 AutoIt 的新手。我一直在尝试使用 AutoIt 脚本对 VBScript(文本文件)进行更改,方法是从用户以逗号分隔命令的形式获取输入,然后将其写入.vbs
文件。我试图通过将字符串存储在数组中然后使用While
循环编写它来做到这一点。
例子:
对于输入:ALPHA,BETA,GAMMA
我期望从文本文件中的“140”行开始的输出如下
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys"ALPHA"
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys"BETA"
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys"GAMMA"
相反,我得到这样的输出:
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys""
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys""
WshShell.appactivate "telnet 10.250.124.85"
WScript.Sleep 1999
WshShell.SendKeys""
即由于某些错误,SendKeys 引号是空的。我使用的代码如下:
$fileadd="C:\Users\rmehta\Downloads\zyxw\Memorycheck.vbs"
$commandnewstring= InputBox("Command Settings","Please enter the commands seperated by commas","")
If @error=0 Then
Global $count,$usestring,$output
$usestring=$commandnewstring
$count= UBound(StringSplit($commandnewstring, ",",""))-1
Global $a[$count],$line
$line=140
$count= $count-1
$output= StringSplit($usestring,",","")
While $count >= 0
$a[$count]= $output
_FileWriteToLine($fileadd,$line,"WshShell.appactivate" & Chr( 34 ) & "telnet 10.250.124.85" & Chr( 34 ),1)
_FileWriteToLine($fileadd,$line+1,"WScript.Sleep" & " 1999",1)
_FileWriteToLine($fileadd,$line+2,"WshShell.SendKeys" & Chr( 34 ) & $a[$count] & Chr( 34 ),1)
$count=$count-1
$line=$line+3
WEnd
Else
MsgBox(0,"You clicked on Cancel",2)
EndIf
我想了很多,但没有得到答案。