- @echo off
-
- REM 选择进程名
- set /p "strProcessName=输入父进程名:"
-
- set "nProcessID="
- REM 取得父进程PROCESSID
- 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 (
- REM echo,%%i:%%j
- REM 第一个进程不管
- if "%%i" NEQ "2" (
- REM 最后的空行不管
- echo,%%j | findstr [0-9] >nul 2>null && (
- REM 其余进程中止
- echo,--中止子进程:%%j
- call wmic process where processid=%%j call terminate
- )
- ) else (
- echo,第一个子进程:%%j
- )
- )
- pause
- goto :EOF
复制代码
|