| @echo off | | | | REM 选择进程名 | | set /p "strProcessName=输入父进程名:" | | | | set "nProcessID=" | | | | for /f "tokens=1,* delims=:" %%i in ('wmic process where name^="%strProcessName%" get processid ^| findstr /n .*') do ( | | if "%%i" equ "2" set "nProcessID=%%j" | | ) | | if "%nProcessID%" equ "" ( | | echo,未找匹配的进程,请重试... | | pause | | goto :EOF | | ) | | | | REM 取得子进程,并杀死除第一个子进程外的进程 | | for /f "tokens=1,* skip=1 delims=:" %%i in ('wmic process where parentprocessid^=%nProcessID% get processid ^| findstr /n .*') do ( | | | | | | if "%%i" NEQ "2" ( | | | | echo,%%j | findstr [0-9] >nul 2>null && ( | | | | echo,--中止子进程:%%j | | call wmic process where processid=%%j call terminate | | ) | | ) else ( | | echo,第一个子进程:%%j | | ) | | ) | | pause | | goto :EOFCOPY |
|