Taskkill with timeout in bat

我的梦境 提交于 2019-12-11 04:01:07

问题


I want something like this:-

taskkill 7z.exe after 50sec.
Execute few lines of codes without waiting for 7z.exe to be killed. 

It will automatically be killed after 50sec, wherever the execution is going on.


回答1:


Is this what you mean ? Waiting 50 seconds before killing 7z.exe

Timeout 50 
taskill /f /im 7z.exe

or you want to wait after killing then do some commands.

taskill /f /im 7z.exe
Timeout 50 
REM do commands here.

EDIT: New version for OP.

start "7z killer" cmd "/c Timeout 50 && taskkill.exe /f /im 7z.exe"
echo "do something immediately"



回答2:


OK, here is a way to turn off the counting window, in addition to all the other stuff.

echo CreateObject("Wscript.Shell").Run """" ^& WScript.Arguments(0) ^& """", 0, False>Invisible.vbs
echo Timeout 50 ^&^& taskkill.exe /f /im 7z.exe>killer.bat
wscript Invisible.vbs killer.bat
echo "do something"

This creates two files in the same directory as itself, invisible.vbs and killer.bat then executes killer.bat invisibly with the 3rd line.



来源:https://stackoverflow.com/questions/21166364/taskkill-with-timeout-in-bat

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