与vbscript并行运行多个Telnet会话
问题描述:
我从一个.bat脚本调用7个vbscripts来启动7个Android模拟器的Telnet会话。问题是最后所有的vbscript都会写入同一个Telnet会话。我对脚本很陌生,所以请帮忙。与vbscript并行运行多个Telnet会话
begin.bat
setlocal enabledelayedexpansion
FOR /L %%G IN (1,1,7) DO (
::start emulator
emulator -avd em%%G
:: Open a Telnet window
timeout /t 60 /nobreak >NUL
set /A "_myport= 5552+2*%%G"
timeout /t 1 /nobreak >NUL
telnet.exe localhost !_myport!
::run script
cscript SendKeys.vbs)
SendKeys.vbs
set OBJECT=WScript.CreateObject("WScript.Shell")
WScript.sleep 50
Dim max,min
max=100
min=1
Randomize
battery_level= Int((max-min+1)*Rnd+min)
OBJECT.SendKeys "power capacity "
OBJECT.SendKeys battery_level
OBJECT.SendKeys "{ENTER}"
'Xml stuff for getting the coordinates
Set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = False
objXML.Load ("C:\Users\basilhs\Downloads\alimos-omonoia.xml")
Set point = objXML.getElementsByTagName("trkpt")
For i = 0 To point.length - 1
Set subNodes = point(i)
OBJECT.SendKeys "geo fix "
OBJECT.SendKeys subNodes.getAttribute("lon")
OBJECT.SendKeys " "
OBJECT.SendKeys subNodes.getAttribute("lat")
OBJECT.SendKeys "{ENTER}"
WScript.Sleep 5000
Next
OBJECT.SendKeys "exit{ENTER}"
答
查找AppActivate
set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "calc"
WshShell.Run "notepad"
WScript.Sleep 100
Msgbox WshShell.AppActivate("Save As")
WScript.Sleep 100
Msgbox WshShell.AppActivate("Calculator")
WScript.Sleep 100
Msgbox WshShell.AppActivate("Notepad")
WScript.Sleep 100
Msgbox WshShell.AppActivate("Calculator")
WScript.Sleep 100
和这里的另一个样本
set WshShell = WScript.CreateObject("WScript.Shell")
If WSHShell.AppActivate("Calculator")=False then
WshShell.Run "C:\windows\System32\calc.exe", 1, false
End If
它永远不会让我感到惊讶,人们会如何采取笨拙的'SendKeys'方法来编写'telnet'而不是使用['telnet'](http://www.chiark.greenend.org.uk/)。 〜sgtatham/putty/download.html)这实际上是脚本化的... – 2014-09-21 21:35:41
感谢您的回复,但您可以更具体请,我是新手脚本。 – ecespecial 2014-09-22 09:32:39