@echo off for /l %%n in (8080,1,8080) do ( @echo find the process which use port [%%n] for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%%n"') do ( tasklist /FI "PID eq %%m"|find /i "PID" && ( echo PID:%%m 运行中,kill the process [%%m] who use the port [%%n] taskkill /F /pid %%m ) || echo PID:%%m 未运行 ) )