@echo off
setlocal EnableExtensions
title Daily Loss Local App - Stop

set "STOPPED=0"

for /f "tokens=5" %%P in ('netstat -ano ^| findstr /R /C:":8501 .*LISTENING"') do (
  taskkill /PID %%P /F >nul 2>nul
  if not errorlevel 1 (
    set "STOPPED=1"
    echo Stopped local service on port 8501.
  )
)

if "%STOPPED%"=="0" echo No running local service was found on port 8501.
echo.
pause
