Windows closes the process based on the port number

First, Windows queries the Pid based on the port number:
Command: netstat -ano | findstr "port number"
Example: netstat -ano | findstr 1246 (I use the terminal that comes with idea here)
Insert picture description here
Then, kill the process based on the Pid:
command : Taskkill -F /pid "PID"
Example: taskkill -F /pid 14860 Find a
Insert picture description here
way to integrate two commands into one script:
create a new kp.bat file (the script name is taken by yourself)

@echo off
set port=%1%
netstat -ano | findstr %port%
echo please input PID...
set /p pid=%2%
taskkill -F /pid %pid%

Insert picture description here
The terminal runs the script
Command: kp port number (add a space after the command, then add the port number)
Example: kp 1246
Insert picture description here

After running here, you can see the pid, and the command enters the state of waiting for input, and then enter the 6264 above, close the process,
Insert picture description here
and there are some on the Internet that can automatically obtain the return value according to the first command, and add the return value to the first In the two commands, the process can be automatically shut down. I am still studying. There are children's shoes who know how to do it. Welcome to contact (the echo print that is waiting, the Chinese looks garbled)

Guess you like

Origin blog.csdn.net/pjw1217/article/details/111738897