2016-07-10 77 views
0

我搜索了很多沒有任何結果,所以我正在向你致意! 我想打開多個windows shell,然後加載不同的telnet連接,將相同的commad發送到不同的計算機。我需要在同一時間完成。所以,我錯誤地嘗試創建不同的「WScript.Shell」對象並在它們上使用發送鍵。沒有任何結果。我怎樣才能做到這一點?命令在多個shell窗口中用於多點telnet連接

Option Explicit 
Dim tll1, tll2, tll3 
set tll1=CreateObject("WScript.Shell") 
set tll2=CreateObject("WScript.Shell") 
set tll3=CreateObject("WScript.Shell") 

tll1.run "cmd.exe" 
tll2.run "cmd.exe" 
tll3.run "cmd.exe" 
WScript.Sleep 1000 

tll1.SendKeys "telnet 192.168.114.254" 
tll1.SendKeys ("{Enter}") 
tll2.SendKeys "telnet 192.168.114.254" 
tll2.SendKeys ("{Enter}") 
tll3.SendKeys "telnet 192.168.114.254" 
tll3.SendKeys ("{Enter}") 
... 

結果它是在最後一個shell窗口中鍵入的wole命令。謝謝!

+0

IP地址是相同的,因爲我使用單臺機器初始測試。 –

+0

您只需創建一個「Wscript.Shell」。使用AppActivate。在WScript.Shell的幫助下查找它。 –

+0

PS您需要直接使用Telnet(而不是啓動cmd,然後telnet),併爲每個窗口使用不同的IP地址,以便每個窗口都有不同的窗口標題。 –

回答

0

謝謝麪條。我已經做到了!唯一需要提醒的是在AppActivate和命令之間進行一次睡眠。沒有工作對我來說,這裏的最終代碼

Option Explicit 

Dim wshShell 
set wshShell=CreateObject("WScript.Shell") 
wshShell.run "telnet.exe" 
WScript.Sleep 1000 
wshShell.SendKeys "o 192.168.114.251" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "admin" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "CMD_PC1" 

wshShell.run "telnet.exe" 
WScript.Sleep 1000 
wshShell.SendKeys "o 192.168.114.252" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "admin" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "CMD_PC2" 

wshShell.run "telnet.exe" 
WScript.Sleep 1000 
wshShell.SendKeys "o 192.168.114.254" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "userPC3" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "PWD_PC3" 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
wshShell.SendKeys "CMD_PC3" 
WScript.Sleep 1000 

wshShell.AppActivate "Telnet 192.168.114.251" 
WScript.Sleep 3 
wshShell.SendKeys ("{Enter}") 
wshShell.AppActivate "Telnet 192.168.114.252" 
WScript.Sleep 3 
wshShell.SendKeys ("{Enter}") 
wshShell.AppActivate "Telnet 192.168.114.254" 
WScript.Sleep 3 
wshShell.SendKeys ("{Enter}") 
WScript.Sleep 1000 
Wscript.Quit