How do I kill the process currently using a port on localhost in Windows?

后端 未结 20 2289
陌清茗
陌清茗 2020-11-22 11:37

How can I remove the current process/application which is already assigned to a port?

For example: localhost:8080

20条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 12:13

    You can do by run a bat file:

    @ECHO OFF                                                                              
    FOR /F "tokens=5" %%T IN ('netstat -a -n -o ^| findstr "9797" ') DO (
    SET /A ProcessId=%%T) &GOTO SkipLine                                                   
    :SkipLine                                                                              
    echo ProcessId to kill = %ProcessId%
    taskkill /f /pid %ProcessId%
    PAUSE
    

提交回复
热议问题