如何以固定顺序而不是随机地连接到bat文件中列出的服务器?
该bat文件一键连接35台服务器,但它们是随机连接的,而不是我在bat中提到的。我需要连接第一台服务器,我在蝙蝠上列出了该服务器,但它们无法连接。如果您能给我任何帮助,我将不胜感激
start cmdkey /generic:"10.151.12.201" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.13.201" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.27.11" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.28.11" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.29.11" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.31.11" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.32.11" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.33.11" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.35.11" /user:"nas" /pass:"itti@123$"
start cmdkey /generic:"10.151.36.11" /user:"nas" /pass:"itti@123$"
start mstsc /admin /w:1600 /v:"10.151.12.201"
start mstsc /admin /w:1600 /v:"10.151.13.201"
start mstsc /admin /w:1600 /v:"10.151.27.11"
start mstsc /admin /w:1600 /v:"10.151.28.11"
start mstsc /admin /w:1600 /v:"10.151.29.11"
start mstsc /admin /w:1600 /v:"10.151.31.11"
start mstsc /admin /w:1600 /v:"10.151.32.11"
start mstsc /admin /w:1600 /v:"10.151.33.11"
start mstsc /admin /w:1600 /v:"10.151.35.11"
start mstsc /admin /w:1600 /v:"10.151.36.11"
The bat file connects 35 servers at one click, but they connect randomly instead of what I mention in the bat. I need to connect the first server, which I list on the bat, but they won't connect. I would appreciate any help you can give me
start cmdkey /generic:"10.151.12.201" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.13.201" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.27.11" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.28.11" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.29.11" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.31.11" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.32.11" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.33.11" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.35.11" /user:"nas" /pass:"itti@123quot;
start cmdkey /generic:"10.151.36.11" /user:"nas" /pass:"itti@123quot;
start mstsc /admin /w:1600 /v:"10.151.12.201"
start mstsc /admin /w:1600 /v:"10.151.13.201"
start mstsc /admin /w:1600 /v:"10.151.27.11"
start mstsc /admin /w:1600 /v:"10.151.28.11"
start mstsc /admin /w:1600 /v:"10.151.29.11"
start mstsc /admin /w:1600 /v:"10.151.31.11"
start mstsc /admin /w:1600 /v:"10.151.32.11"
start mstsc /admin /w:1600 /v:"10.151.33.11"
start mstsc /admin /w:1600 /v:"10.151.35.11"
start mstsc /admin /w:1600 /v:"10.151.36.11"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了让生活稍微轻松一点,您实际上只需要使用 for 循环一次命令,并且仅将元变量传递给命令。在本例中,元变量
%%i
是一个临时变量,保存当前值,直到do
之后的所有命令完成,它将把下一个值分配给 < code>%%i然后,根据您的具体要求(并非 100% 清楚),有几个选项:
在每个命令之间添加超时,以确保它在下一个命令之前启动:
但这将需要您由于延迟,每个远程会话需要 35 秒启动,因此接下来是强迫他们使用条件运算符。原理很简单
&&
将告诉系统仅启动下一个,如果上一个成功或%errorlevel%
或exitcode
不大于 0。因此我们使用相同的循环来构建宏,然后启动宏。
最后,如果打算一次打开一个,执行某些操作,然后关闭并启动下一个,请使用
start "" /wait
To ease life a bit, you really only need the commands once off by utilizing a for loop and only passing the meta variables to the commands. The meta variable,
%%i
in this instance, is a temp variable holding the current value until all the commands afterdo
is completed where it will assign the next value to%%i
Then, depending on your exact requirement, which is not 100% clear there are a few options:
add a timeout between each command to ensure it starts up before the next one:
This however will take you 35 seconds to start up each remote session because of the delay, so the next would be to force them using conditional operators. Principal is simple
&&
will tell the system to only start up the next, if the previous was successful or%errorlevel%
orexitcode
is not larger than 0.So we use the same loop to build macros and and then launch the macros.
Lastly, if the intension was to open one at a time, do something, then close and start the next, use
start "" /wait
要按顺序运行命令,请将
/W
或/WAIT
添加到每一行。请参阅 https://ss64.com /nt/start.html
To run your commands in sequential order, add the
/W
or/WAIT
to each line.See https://ss64.com/nt/start.html