# 按 Listen 端口终止进程树(含子进程)。默认 :3000 前端 / :3001 后端。 # 由 stop.bat 调用;也可直接:powershell -File stop.ps1 param( [int[]]$Ports = @(3000, 3001) ) $ErrorActionPreference = 'SilentlyContinue' foreach ($port in $Ports) { $pids = @( Get-NetTCPConnection -LocalPort $port -State Listen | Select-Object -ExpandProperty OwningProcess -Unique ) if (-not $pids -or $pids.Count -eq 0) { Write-Host " :$port 空闲" continue } foreach ($procId in $pids) { if ($procId -le 0) { continue } Write-Host " :$port -> PID $procId (含子进程)" & taskkill.exe /T /F /PID $procId | Out-Null } }