如何发送“Enter-key”通过批处理文件到通过批处理文件连接的服务器
大家好
在格哈德的帮助下,下面的代码非常适合我
@echo off
set "range=10.151.12.11 10.151.13.11 10.151.27.11"
for %%i in (%range%) do (
start "" cmdkey.exe /generic:"%%i" /user:"buffer" /pass:"123$"
start "" mstsc.exe /admin /w:1600 /v:"%%i"
timeout /t 1
)
在下面的代码中,我做了一些更改来发送回车键,但它不起作用
@echo off
set "range=10.151.12.11 10.151.13.11 10.151.27.11"
for %%i in (%range%) do
(
start "" cmdkey.exe /generic:"%%i" /user:"buffer" /pass:"123$"
start "" mstsc.exe /admin /w:1600 /v:"%%i"
WScript.CreateObject("WScript.Shell").SendKeys("{Enter}");
timeout /t 1
)
有人知道如何在这些循环之间发送“Enter-key”吗?
我想在服务器连接后发送“Enter-key”,然后发送第二个服务器将连接
Hi guys
With Gerhard's help, these below codes work perfectly for me
@echo off
set "range=10.151.12.11 10.151.13.11 10.151.27.11"
for %%i in (%range%) do (
start "" cmdkey.exe /generic:"%%i" /user:"buffer" /pass:"123quot;
start "" mstsc.exe /admin /w:1600 /v:"%%i"
timeout /t 1
)
In the below code, I made some changes to send the enter key, but it does not work
@echo off
set "range=10.151.12.11 10.151.13.11 10.151.27.11"
for %%i in (%range%) do
(
start "" cmdkey.exe /generic:"%%i" /user:"buffer" /pass:"123quot;
start "" mstsc.exe /admin /w:1600 /v:"%%i"
WScript.CreateObject("WScript.Shell").SendKeys("{Enter}");
timeout /t 1
)
Does anyone know how to send "Enter-key" in between these loops?
I want to send "Enter-key" after server is connected, then second server will connect
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
组装混合批处理文件的最简单方法是将其与 JScript 代码组合,如 此示例:
但是,为了使此技巧发挥作用,接收当按键被“按下”时,窗口必须具有键盘焦点。也许您还需要使用 AppActivate 方法 来做到这一点...
The simplest way to assemble an hybrid Batch file is combining it with JScript code, as in this example:
However, in order for this trick to work, the receiving window must have keyboard focus when the key is "pressed". Perhaps you need to also use AppActivate method to do that...
您非常接近,但您的问题是
wscript.CreateObject
不是批处理命令,而是vbscript命令。为了在批处理脚本中运行该命令,您需要调用该行的cscript
解释器。不幸的是,cscript
仅接受文件,因此您必须在其中使用wscript
命令创建文件。You are very close, but your problem is that
WScript.CreateObject
is not a batch command, but rather a VBScript command. In order to run that command in a batch script, you need to invoke thecscript
interpreter for that line. Unfortunately,cscript
only accepts files so you have to create a file with theWScript
command in it.