如何发送“Enter-key”通过批处理文件到通过批处理文件连接的服务器

发布于 2025-01-19 22:52:14 字数 804 浏览 4 评论 0原文

大家好

在格哈德的帮助下,下面的代码非常适合我

@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:"123
quot;
   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:"123
quot;
   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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

分分钟 2025-01-26 22:52:14

组装混合批处理文件的最简单方法是将其与 JScript 代码组合,如 此示例

@if (@CodeSection == @Batch) @then


@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"

   Cscript //nologo //E:JScript "%~F0"

   timeout /t 1
)
goto :EOF


@end


WScript.CreateObject("WScript.Shell").SendKeys("{Enter}");

但是,为了使此技巧发挥作用,接收当按键被“按下”时,窗口必须具有键盘焦点。也许您还需要使用 AppActivate 方法 来做到这一点...

The simplest way to assemble an hybrid Batch file is combining it with JScript code, as in this example:

@if (@CodeSection == @Batch) @then


@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
quot;
   start "" mstsc.exe /admin /w:1600 /v:"%%i"

   Cscript //nologo //E:JScript "%~F0"

   timeout /t 1
)
goto :EOF


@end


WScript.CreateObject("WScript.Shell").SendKeys("{Enter}");

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...

×纯※雪 2025-01-26 22:52:14

您非常接近,但您的问题是wscript.CreateObject不是批处理命令,而是vbscript命令。为了在批处理脚本中运行该命令,您需要调用该行的cscript解释器。不幸的是,cscript仅接受文件,因此您必须在其中使用wscript命令创建文件。

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"
    
    >hit_enter.vbs echo WScript.CreateObject("WScript.Shell"^).SendKeys("{Enter}"^)
    cscript /nologo hit_enter.vbs
    del hit_enter.vbs
    timeout /t 1
)

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 the cscript interpreter for that line. Unfortunately, cscript only accepts files so you have to create a file with the WScript command in it.

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
quot;
    start "" mstsc.exe /admin /w:1600 /v:"%%i"
    
    >hit_enter.vbs echo WScript.CreateObject("WScript.Shell"^).SendKeys("{Enter}"^)
    cscript /nologo hit_enter.vbs
    del hit_enter.vbs
    timeout /t 1
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文