Opening/Closing application via .bat file [Windows]

跟風遠走 提交于 2020-01-12 05:09:27

问题


Good Day, I have a .bat file that run a specific application then after 5 seconds it will close/kill it.

I having right now due to it successfully open the application thought when the app opens it will not execute the remaining commands unless I manually close the app.

Here is my code:

cd "C:\Program Files (x86)\Aspera\Point-to-Point\bin\"
asperascp.exe
sleep 5 
taskkill /IM asperascp.exe /f

I also try removing the sleep command.

cd "C:\Program Files (x86)\Aspera\Point-to-Point\bin\"
asperascp.exe
taskkill /IM asperascp.exe /f

But it will have same output it will not execute the remaining commands when the asperascp.exe starts.

Any tips?

Thanks.


回答1:


You can use Start /b command.

@echo off
cd "C:\Program Files (x86)\Aspera\Point-to-Point\bin\"
Start "" /b asperascp.exe 
timeout /T 5 /nobreak >nul
taskkill /IM asperascp.exe /F



回答2:


TASKKILL /IM asperascp.exe /F
will kill all images with the same image name. So if you run the same program twice, for example, and the second one starts before the first one exits, the second one will be killed too when the first one runs taskkill. If you do tasklist you will see some images with the same image name, but with differing PIDs. You will have to get the PID of the process started by your batch file (I can't think of how to do this with CMD.) Then you can use: TASKKILL /PID 999 /F



来源:https://stackoverflow.com/questions/36027461/opening-closing-application-via-bat-file-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!