0

VBScript と AutoIt は初めてです。AutoIt スクリプトを使用して VBScript (テキスト ファイル) を変更しようとしています。ユーザーからの入力をカンマ区切りのコマンド形式で受け取り、それを.vbsファイルに書き込んでいます。While文字列を配列に格納してからループ を使用して書き込むことで、これを実行しようとしました。

例:

入力の場合:テキスト ファイルの行"140"から次のような出力ALPHA,BETA,GAMMA期待されます

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

いろいろ考えましたが答えが出ませんでした。

4

1 に答える 1

1

わかりました、ここに実用的な解決策があります:

#include <File.au3>

$fileadd = "C:\Users\rmehta\Downloads\zyxw\Memorycheck.vbs"

$commands = InputBox("Command Settings", "Please enter the commands seperated by commas","")
If @error == 0 Then
    Global $count
    $commands = StringSplit($commands, ",", 2)
    $count = UBound($commands)

    Global $a[$count], $line
    $line = 140

    $index = 0
    While $index < $count
       $command = $commands[$index]
       _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) & $command & Chr(34), 1)
       $line += 3
       $index += 1
    WEnd
Else
    MsgBox(0, "You clicked on Cancel", 2)
EndIf

最初の試行とこのソリューションの違いを調べることをお勧めします。==とではなく との比較だけでなく、書式設定と間隔の使用法から学び=ます。それとも+=オペレーターの使い方...

于 2013-09-11T11:13:27.970 に答える