@echo off
Net session >nul 2>&1 || mshta vbscript:CreateObject("Shell.Application").ShellExecute("cmd.exe","/c %~s0","","runas",1)(window.close)&&exit
@echo off
setlocal enabledelayedexpansion
set /p port=Please enter the port number:
set pid=init
for /f "tokens=5" %%a in ('netstat -ano^|findstr %port%') do (
set pid=%%a
)
if not "%pid%" == "init" (
taskkill /F -PID !pid!
echo The service occupying port %port% has been shut down successfully!
)else (
echo No service occupies port %port%!
)
echo Automatically exit after 5 seconds
choice /T 5 /C ync /CS /D y /n
===================================
新建一个文本文本,将上面的代码复制进去,修改文件后缀名为 .bat
双击运行,输入端口号 回车即可。
if defined port ( FOR /F "tokens=5 delims= " %%P IN ('netstat -a -n -o ^| findstr :%port%') DO TaskKill.exe /PID %%P -t -f ) else ( echo please enter your port)