我有批处理文件,它获取用户输入,将输入传输到vb脚本。
set /p "whichPort= Which port do you want to reset:"
start /b "" cscript.exe //NoLogo loginInXyplex.vbs /portname:"%whichPort%"
然后从批处理文件中开始执行telnet会话,然后执行相同的脚本文件,以便在telnet会话中发出命令。
telnet.exe 192.120.187.35 2000
REM run the script
cscript loginInXyplex.vbs
在telnet会话中,当两个脚本在conmmands不同步时同时运行,因此无法正常登录
这是我的第一个vb脚本,所以我可能会遗漏一些事情,所以我已经包含了所有源代码:
批处理文件:
@echo off
cls
echo.
echo Welcome to Xyplex Server Port Reset
echo.
pause
echo.
set /p whichXplex= Which Xyplex server is your device connected too: 1 or 2 ?
echo.
set /p "whichPort= Which port do you want to reset:"
echo Sending port "%whichPort%" to script file
echo.
pause
rem send using strat /b so we open script file on same command line window
start /b "" cscript.exe //NoLogo loginInXyplex.vbs /portname:"%whichPort%"
echo.
echo Conencting to Xyplex "%whichXplex%"
pause
if "%whichXyplex%" == "1" (
REM COnnecting to xyplex one IP:Socket
echo.
echo Connecting to Xpyplex %whichXyplex%...
telnet.exe 192.120.187.35 2000
REM run the script
cscript loginInXyplex.vbs
) ELSE (
rem ^ missing spaces in )ELSE(
echo Conencting to xyplex %whichXyplex%....
telnet.exe 193.120.187.245 2000
REM run the script in same widow wuth start /b
cscript loginInXyplex.vbs
)
脚本:
set OBJECT=WScript.CreateObject("WScript.Shell")
OBJECT.SendKeys"{ENTER}"
OBJECT.SendKeys "access{ENTER}"
WScript.sleep 50
OBJECT.SendKeys "access{ENTER}"
OBJECT.SendKeys "SET PRIV{ENTER}"
OBJECT.SendKeys "system{ENTER}"
OBJECT.SendKeys "sh po all{ENTER}"
OBJECT.SendKeys "{ENTER}"
' source heer: http://stackoverflow.com/questions/21013428/pass-variable-from-batch-to-vbs
port = WScript.Arguments.Named.Item("portname")
OBJECT.SendKeys port
OBJECT.SendKeys "Port number selected is: " & port
OBJECT.SendKeys "{ENTER}"
OBJECT.SendKeys "Port reset....logging off...{ENTER}"
OBJECT.SendKeys "SET NOPRIV {ENTER}"
Wscript.Sleep 1000
OBJECT.SendKeys "Quit"
任何帮助表示感谢。