0
1つの.vbsファイルを作成しようとしているバッチファイルを作成しました。しかし、私はすべてのコマンドを.vbsファイルに転送することができません。続き1つのファイルにバッチコマンドとVBスクリプトコマンド
@echo off
echo:
set /a i=1
:Loop
if %i% GTR 0 (
rem create temp vbs file
echo Dim IPAddress > temp.vbs
echo IPAddress="192.168.1.109" >> temp.vbs
echo SET WshShell = WScript.CreateObject("WScript.Shell"^) >> temp.vbs
echo WshShell.run("telnet.exe " &IPAddress) >> temp.vbs
echo WScript.Sleep 3000 >> temp.vbs
echo WshShell.SendKeys"qwert" >> temp.vbs
echo WshShell.SendKeys("{Enter}") >> temp.vbs
echo WScript.Sleep 3000 >> temp.vbs
echo WshShell.SendKeys"asdf123" >> temp.vbs
echo WshShell.SendKeys("{Enter}") >> temp.vbs
echo WScript.Sleep 1000 >> temp.vbs
echo ' Reboot Device >> temp.vbs
echo ' WshShell.SendKeys"reboot" >> temp.vbs
echo ' WshShell.SendKeys("{Enter}") >> temp.vbs
echo ' WScript.Sleep 1000 >> temp.vbs
echo strPath = WshShell.CurrentDirectory >> temp.vbs
echo ' Close telnet session >> temp.vbs
echo WshShell.Run "taskkill /im telnet.exe", , True >> temp.vbs
rem wscript C:\Users\guest\Desktop\temp.vbs
echo Reboot Count %i%
echo:
set /a i+=1
Timeout /t 90 >nul
GOTO Loop
) ELSE (
echo Out of if loop
)
はtemp.vbsの実際の出力は親切に、このシナリオを実現するために、この上で私を助ける
Dim IPAddress
IPAddress="192.168.1.109"
SET WshShell = WScript.CreateObject("WScript.Shell"^)
WshShell.run("telnet.exe " &IPAddress)
WScript.Sleep 3000
WshShell.SendKeys"qwert"
WshShell.SendKeys("{Enter}")
WScript.Sleep 3000
WshShell.SendKeys"asdf123"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1000
' Reboot Device
' WshShell.SendKeys"reboot"
' WshShell.SendKeys("{Enter}")
' WScript.Sleep 1000
strPath = WshShell.CurrentDirectory
' Close telnet session
WshShell.Run "taskkill /im telnet.exe", , True
ファイルtemp.vbsの
WshShell.run("telnet.exe "
WScript.Sleep 3000
WshShell.SendKeys"qwert"
WshShell.SendKeys("{Enter}")
WScript.Sleep 3000
WshShell.SendKeys"asdf123"
WshShell.SendKeys("{Enter}")
WScript.Sleep 1000
' Reboot Device
' WshShell.SendKeys"reboot"
' WshShell.SendKeys("{Enter}")
' WScript.Sleep 1000
strPath = WshShell.CurrentDirectory
' Close telnet session
WshShell.Run "taskkill /im telnet.exe", , True
の予想される出力をファイルです。
ありがとうございます。
あなたの 'echo'ステートメントですべての閉じ括弧をエスケープする必要があります。それで 'telnet'のスクリプトに' SendKeys'を使わないでください。 [PuTTY suite](https(https://the.earth.li/~sgtatham/putty/0.70/htmldoc/Chapter7.html#plink)のような実際にスクリプト化可能な '' telnet''コマンドを使用してください(https://the.earth.li/~sgtatham/putty/0.70/htmldoc/Chapter7.html#plink) ://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html))。 –
バッチ+ VBScriptハイブリッドを作成するには、より適切な方法があります(https://stackoverflow.com/a/9074483/1683264)。 (さらにいくつかの例があります(https://stackoverflow.com/search?q=user%3A1683264+batch+vbscript+wsf)) – rojo
Frankenscriptsの宣伝をやめてください。彼らは知的に特定の魅力を持っているかもしれませんが、生産の維持とトラブルシューティングには苦労しています。 –