作为替代,以精彩的npocmaka答案,如果您知道或可以设置已启动的Selenium窗口的标题,可以使用此信息检索并过滤具有这些标题的任务列表。
当输出到控制台是正确的,从TASKKILL行删除echo
命令
@echo off
rem Prepare environment
setlocal enableextensions
rem Configure list of window titles
set titles="seleniumHUB" "seleniumNODE"
rem For each title in title list
for %%t in (%titles%) do (
rem Get the list of task with the indicated window title.
rem The list is get from tasklist, in verbose mode and in csv format
rem The last column in the list is the window title
for /f "tokens=1,2 delims=," %%a in (
'tasklist /fi "imagename eq cmd.exe" /v /fo csv ^| findstr /i /r /c:"%%~t[^,]*$"'
) do (
echo taskkill /pid %%~b
)
)
rem Clean
endlocal
aaw yes.'Title'.Simple and neat。+ 1 – npocmaka
这对我来说非常合适,解决了我在npocmaka的解决方案中提到的问题,该解决方案最初似乎达到了我想要的效果。将您的答案MC提升至已接受的答案。 – DaftMule