通过 .bat 文件打开/关闭应用程序 [Windows]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36027461/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Opening/Closing application via .bat file [Windows]
提问by Edmhar
Good Day, I have a .bat file that run a specific application then after 5 seconds it will close/kill it.
美好的一天,我有一个运行特定应用程序的 .bat 文件,然后在 5 秒后它会关闭/杀死它。
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.
我也尝试删除sleep
命令。
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.
但是它会有相同的输出,当 asperascp.exe 启动时它不会执行剩余的命令。
Any tips?
有小费吗?
Thanks.
谢谢。
回答by Hackoo
回答by Marichyasana
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
TASKKILL /IM asperascp.exe /F
将杀死具有相同图像名称的所有图像。因此,例如,如果您运行相同的程序两次,并且第二个在第一个退出之前启动,那么当第一个运行 taskkill 时,第二个也会被杀死。如果这样做,tasklist
您将看到一些具有相同图像名称但具有不同 PID 的图像。您必须通过批处理文件获取进程的 PID(我想不出如何使用 CMD 执行此操作。)然后您可以使用:
TASKKILL /PID 999 /F