我刚开始批量编写脚本,尝试搜索和删除进程列表,并且不确定如何在第二个管道之后继续执行。
@echo off
wmic process where "Name like 'java%%.exe' " get Processid, Caption, Commandline | find "abc" |这里,我使用WMIC列出所有java进程,并使用find对它们进行过滤,以获得命令行中带有特定单词的java进程,现在我需要在找到它们之后终止这些进程。这可以通过taskkill实现,还是在将其写入文件后使用for循环?我不想使用调用终止来终止进程。有人能帮我做这个吗。提前谢谢。
发布于 2021-12-13 19:56:42
首先通过.exe名称查找进程,然后在了解进程id之后查看那些进程的命令行:
@echo off
setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
set exe=winver.exe
set findcommand=foo bar
REM start example programs
start "" "%exe%" %findcommand%
start "" "%exe%" %findcommand% baz
ping -n 3 localhost>nul&rem SLEEP
for /F "tokens=2 delims==" %%A in ('wmic process where "Name like '%exe%'" get ProcessID /format:list') do for /F "tokens=1,* delims==" %%B in ('wmic process where "ProcessID like '%%A'" get commandLine /format:list') do for /F %%D in ("%%~B") do (
(echo.%%C|find /I "%findcommand%" >nul)&&call taskkill /PID %%A
)我确信,如果命令行包含echo不喜欢的内容,那么有一些方法可以打破这种情况,但是这就是使用批处理文件的生命.
https://stackoverflow.com/questions/70339533
复制相似问题