DEV Community

Petr Janik
Petr Janik

Posted on

1 1

Kill process on port on Windows

I would like to create an alias for finding process on specified port and an alias to kill process by PID.

  1. Create an alias.cmd file in %USERPROFILE%

    notepad alias.cmd
    

    then add the following three lines to the file:

    @echo off
    DOSKEY proc=netstat -ano ^| findstr :$1
    DOSKEY kill=taskkill /F /PID $1
    

    The first alias proc accepts one argument and lists PID of process running on that port.
    The second - kill (which also accepts one argument) - terminates the process by PID.

  2. Run regedit and go to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor (for MS10), HKEY_CURRENT_USER\Software\Microsoft\Command Processor (for < MS10). Add String Value entry with the name AutoRun and value %USERPROFILE%\alias.cmd (path to .cmd file).

Now I can start cmd, type proc 8080 and then for example kill 15003.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay