How to check, kill, and block a port on Windows 11
INTRO
Sometimes a local server or app fails to start because <my_port> is already busy. Here are the most important commands for Windows 11 (CMD, PowerShell, and Git Bash) to check port availability, find which app uses it, stop the process, and block it in the future.
1. CHECK PORT AVAILABILITY & FIND THE APP
First, check if <my_port> (for example, 4001) is in use and get its PID (Process ID) and application name. If the command returns nothing, the port is free.
PowerShell
Simple port occupation check
1 | |
More informative script
1 | |
CMD (Command Prompt)
1 | |
Git Bash
1 | |
2. TERMINATE THE PROCESS
Once you have the <PID>, force-stop the process to free <my_port>.
PowerShell
1 | |
CMD
1 | |
Git Bash
1 | |
3. BLOCK THE APP FROM USING THE PORT
If an unwanted program keeps taking <my_port>, you can block its network access or stop it from auto-starting.
Block via Windows Firewall (PowerShell as Administrator)
First, get the full path to the program’s .exe file, then add a firewall rule to block it:
1 | |
Disable Auto-Start (For Background Services)
If a Windows service keeps restarting and taking <my_port>:
- Press
Win + R, typeservices.msc, and press Enter. - Find the service in the list, right-click it, and click Properties.
- Set Startup type to Manual or Disabled, then click OK.
How to check, kill, and block a port on Windows 11
https://ooge0.github.io/hexo-blog/dev/tools/os/manage_ports_windows11/