本帖最后由 taofan712 于 2017-2-10 13:22 编辑
- @echo off
- set /p portnum=设定端口
- set /p process=设定进程
- for /f "delims=" %%a in ('netstat -ano^|find "%portnum%"') do set a=%%a
- for %%b in (%a%) do set processpid=%%b
- for /f "delims= " %%c in ('tasklist 2^>nul^|find "%processpid%"') do set b=%%c
- if /i not "%process%"=="%b%" (
- echo;占用端口%portnum%的进程为%b%,其pid值为%processpid%
- taskkill /f /pid %processpid%
- ) else (
- echo;端口正常&pause>nul )
复制代码 (测试了正常占用状态,没测试不正常占用。(请求评分鼓励^_^)) |