Skip to content

Instantly share code, notes, and snippets.

@farshidrezaei
Created September 10, 2019 15:42
Show Gist options
  • Save farshidrezaei/1e288ae963dc7cffed52b568031dfc1c to your computer and use it in GitHub Desktop.
Save farshidrezaei/1e288ae963dc7cffed52b568031dfc1c to your computer and use it in GitHub Desktop.
Bat file for kill and stop a port or process.
@ECHO OFF
cls
:loop
cls
:enterPort
cls
set /P port="Enter a port. [ q => exit ] : "
If "%port%"=="q" goto endLoop
cls
echo.
echo.
echo List of Process that contains the "%port%" string . find the process that you want.
echo.
netstat -aon | findstr i
echo.
netstat -aon | findstr %port%
echo.
echo. -------------------------
echo.
echo (*the last number is process id.)
echo.
set /P processId="Enter Process id to kill. [ b => back , q => exit ] : "
If "%processId%"=="b" goto enterPort
If "%processId%"=="q" goto endLoop
taskkill /F /PID %ProcessId%
goto loop
:endLoop
cls
echo.
echo.
echo by FarshidRezaei - github : https://github.com/farshidrezaei
echo.
echo.
PAUSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment