portfind

How to kill the process using a port on Windows

Updated

A server won't start because the port is taken, and you need to know what is holding it. Windows can tell you the process ID (PID) on any port; this guide shows how to find it and stop it, using port 3000 as the example. Replace it with your port.

Quick answer (PowerShell)

Show what is listening on the port, with the process name:

PowerShell
Get-NetTCPConnection -LocalPort 3000 -State Listen |
  Select-Object LocalAddress, LocalPort, OwningProcess,
    @{n='Name'; e={(Get-Process -Id $_.OwningProcess).ProcessName}}
PowerShell: stop it (use the PID from above)
Stop-Process -Id 12345

Check the name before you stop it. If it says svchost, System, or a database such as postgres or mysqld, read the sections below first.

With Command Prompt: netstat and taskkill

In Command Prompt, netstat -ano lists every connection with its PID in the last column. Filter it for your port and look for the line that says LISTENING:

cmd
netstat -ano | findstr :3000
output
  TCP    0.0.0.0:3000    0.0.0.0:0    LISTENING    12345
cmd: stop PID 12345
taskkill /PID 12345 /F
  • findstr :3000 also matches ports like 30000 and outgoing connections, so make sure you pick the LISTENING line for exactly your port.
  • /F forces the process to end. Without it, taskkill asks politely, and console programs such as Node often ignore that.
  • To see the program name for a PID: tasklist /FI "PID eq 12345".

One line: free a port (PowerShell)

This stops whatever is listening on the port without showing you what it was first, so use it only when you already know:

PowerShell
Get-NetTCPConnection -LocalPort 3000 -State Listen |
  ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }

"Access is denied"

The process belongs to a Windows service or to a program running as administrator. Open Terminal or Command Prompt with Run as administrator and try again.

If it is a service (a database, IIS, a VPN client), stop the service instead of killing the process; otherwise Windows may restart it:

PowerShell (as administrator)
Get-Service | Where-Object Status -eq 'Running' | Sort-Object DisplayName
Stop-Service -Name 'postgresql-x64-16'

Port 80 or 443 is owned by PID 4 ("System")

PID 4 is the Windows kernel. When it holds port 80 or 443, the real owner is the HTTP.sys driver, usually used by IIS or another web service. You can't kill PID 4; find and stop the service behind it:

Command Prompt (as administrator)
netsh http show servicestate
net stop w3svc

See what you are killing first, with portfind

portfind shows every listening port with the process, the project folder it was started from, how long it has been running and a risk level. Type the port to filter, press Enter to kill. Databases and system services need you to type the name to confirm, and core Windows processes are always refused.

PowerShell: install
irm https://raw.githubusercontent.com/rpratap2111/portfind/main/install.ps1 | iex
then
portfind