使用批处理文件关闭App_B时如何自动关闭App_A [英] How to automatically close App_A when I close App_B using batchfile

查看:88
本文介绍了使用批处理文件关闭App_B时如何自动关闭App_A的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是一批批处理的新手,但我喜欢每隔一段时间进行修补和编码.我可以制作一个同时关闭两个程序的批处理文件吗?例如,我创建了一个打开两个程序的批处理文件,App_A(游戏手柄模拟器)是最小化App_B(离线RPG游戏)的正常窗口.我想要的是当我关闭App_B时App_A也会自动关闭,这样我就不必还原窗口并手动关闭模拟器.

Hi everyone I'm a newbie in batchfiling but loved tinkering and coding every other time. Can I make a batch file that closes two program simultaneously? Example, I created a batchfile that opens two program, App_A (gamepad imulator) is minimized App_B (offline RPG Game) normal window. What I want is when I close App_B App_A would automatically close too so that I don't have to restore the window and manually close the imulator.

这是我刚刚在该网站上找到并运行的代码:

this is the code I just did which I also found in this site and got it working:

ECHO OFF
start /d "C:\Documents and Settings\Computer\My Documents\Imulator\PROFILE" SET1.imulatorprofile /m
ECHO IMULATOR STARTED
start /d "C:\Program Files\App_B" App_BLauncher.exe
ECHO APP_B STARTED
ECHO OPERATION COMPLETE

任何评论或建议都将受到赞赏!在此先感谢:)

Any comments or suggestions is GREATLY APPRECIATED! THANKS in ADVANCE :)

推荐答案

我对Windows命令行的使用不是很好,但是我会尝试以下方法:

I'm not very good using the windows commandline, but I would try the following approach:

  1. 启动模拟器(退出APP_B后应自动退出)
  2. 启动APP_B(使用/wait选项-这将暂停批处理)
  3. 杀死模仿者(按名称使用PsKill)

您可以找到有关开始此站点上的命令.

You can find details about start, PsKill and other commands at this site.

希望能有所帮助.

* Jost

...稍后添加...

...added later...

另一种选择是在后台进行常规检查,以了解进程(App_B)是否正在运行,并在完成时继续(停止App_A).当App_B只是另一个进程(例如App_Launched_By_B)的启动器并直接返回时,这种方法很有意义.

Another option would be to do regular checks in the background if a process (App_B) is running and continue (with stopping App_A) when it is finished. This approach makes sense when App_B is only a launcher for another process (e.g. App_Launched_By_B) and comes back directly.

这可以通过一个看起来类似于此循环的小循环来完成:

This can be done with a small loop which might look similar to this one:

start "App_A" /d "C:\Programs\App_A" App_A.exe
ECHO App_A STARTED
start "App_B" /d "C:\Programs\App_B" App_B.exe
ECHO App_B STARTED

ECHO GIVE App_B 30 SECONDS TO LAUNCH App_Launched_By_B 
SLEEP 30

:LOOP
PSLIST App_Launched_By_B >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO CONTINUE
) ELSE (
  ECHO App_Launched_By_B IS STILL RUNNING - PAUSE ANOTHER 5 SECS
  SLEEP 5
  GOTO LOOP
)

:CONTINUE
PsKill App_A
ECHO App_A STOPPED

此示例最初来自 aphoria 编写.在这种情况下,我只进行了一点修改.

This example came originally from another answer and was written by aphoria. I adapted it just a little little bit for this case.

有关 PsList 的其他信息和其他命令可以在

Additional information about PsList and other commands can be found at this site.

我还想指出,我不太喜欢这种方法,因为它消耗了一些CPU,而没有做太多事情.但这是我可以看到的批处理文件中唯一的解决方案.

I also want to note that I do not really like this approach, because it consumes some cpu without doing much. But it is the only solution from a batch file I can see.

这篇关于使用批处理文件关闭App_B时如何自动关闭App_A的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆