简体   繁体   English

winrs命令后,批处理脚本停止执行

[英]Batch script stops executing after winrs command

I have a script that contains a call to winrs in order to remotely start the execution of a .exe on a user specified target machine. 我有一个脚本,其中包含对winrs的调用,以便在用户指定的目标计算机上远程启动.exe的执行。

I want the following functionality: 我想要以下功能:

  • start script 启动脚本
  • prompt user for name of target PC 提示用户输入目标PC的名称
  • winrs into target PC executing the .exe and tell user who ran the script that this is being done. 进入执行.exe的目标PC,并告诉运行脚本的用户已完成此操作。
  • stop the execution of winrs and tell the user who ran the script that it has finished. 停止执行winrs,并告诉运行脚本的用户它已经完成。
  • exit. 出口。
  • I want all the output on the machine that the script was run on and don't want any show of activity on the target machine. 我想要运行脚本的计算机上的所有输出,并且不希望在目标计算机上显示任何活动。

The code I have is as follows: 我的代码如下:

@echo off

echo -------------------------------------------------------
echo PLEASE ENTER PC NAME OF DISCONNECTED MACHINE
echo -------------------------------------------------------
SET /p pcToReconnect= 
echo Attempting to contact Agent.

call winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1

echo Agent reconnected. Please allow ~5mins for your management console to update.

The code executes until the winrs call, and it does infact execute the .exe on the target machine, but it seems then that the remote shell just stays open doing nothing after this. 该代码一直执行到winrs调用为止,并确实在目标计算机上执行了.exe,但随后看来,远程shell仍然保持打开状态,此后什么也不做。

If I push ctrl+c at this point "Terminate the shell? (y/n)" gets placed in my logfile, (but no output in the cmd prompt) and I can then push "y" and enter, upon which the remote shell exits and "Terminate batch job (Y/N)" appears in the cmd prompt, however the last echo statement never executes. 如果此时我按ctrl + c,则将“ Terminate the shell?(y / n)”放置在我的日志文件中(但cmd提示符中没有输出),然后可以按“ y”并输入,远程Shell退出并在cmd提示符中出现“终止批处理作业(Y / N)”,但是最后一个echo语句从不执行。

How can I get the remote shell to automatically close after the .exe has been run, and echo some sort of confirmation that the script has completed on the prompt of whoever has executed it? 在运行.exe之后,如何使远程外壳程序自动关闭,并在执行该脚本的任何人的提示下回显某种形式的脚本确认的确认?

All help appreciated! 所有帮助表示赞赏!

You are using call which executes a new cmd.exe window and running winrs in that new window and exiting. 您正在使用执行新cmd.exe窗口并在该新窗口中运行winrs并退出的call Remove it and it will work. 删除它,它将起作用。 I added pause at the end, in case you are running batch by double clicking it. 我在末尾添加了暂停,以防您双击运行批处理。

@echo off @回声关闭

echo -------------------------------------------------------
echo PLEASE ENTER PC NAME OF DISCONNECTED MACHINE
echo -------------------------------------------------------
SET /p pcToReconnect= 
echo Attempting to contact Agent.

winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1

echo Agent reconnected. Please allow ~5mins for your management console to update.
pause

EDIT 编辑

After some analysis it seems that the batch is waiting for the program to finish, so it would be possible to just call it with start which should call it and return to the original prompt. 经过一些分析,似乎该批处理正在等待程序完成,因此可以仅使用start调用它,然后应调用它并返回到原始提示。

start winrs -r:%pcToReconnect% "C:\Path\To The\exe that I want\toExecute.exe" >> logfile.txt 2>>&1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM