param( [Parameter(Mandatory = $true)] [string]$Root ) $ErrorActionPreference = "SilentlyContinue" $Root = $Root.Trim().Trim('"').TrimEnd("\") $Root = (Resolve-Path -LiteralPath $Root).Path.TrimEnd("\") $Runtime = Join-Path $Root ".runtime" function Stop-Tree([int]$Id) { Get-CimInstance Win32_Process | Where-Object { $_.ParentProcessId -eq $Id } | ForEach-Object { Stop-Tree $_.ProcessId } Stop-Process -Id $Id -Force } Write-Host "" Write-Host "============================================" Write-Host " Knowledge Station - Cerrar plataforma" Write-Host "============================================" Write-Host "" if (!(Test-Path $Runtime)) { Write-Host "No hay registro de servicios abiertos." exit 0 } foreach ($name in @("backend.pid", "frontend.pid", "server.pid")) { $file = Join-Path $Runtime $name if (Test-Path $file) { $raw = Get-Content $file | Select-Object -First 1 if ($raw) { Stop-Tree ([int]$raw) } } } Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine -like "*$Root*" -and ($_.CommandLine -like "*uvicorn*backend.app.main:app*" -or $_.CommandLine -like "*next*dev*") } | ForEach-Object { Stop-Tree $_.ProcessId } foreach ($name in @("backend.pid", "frontend.pid", "server.pid", "backend.port", "frontend.port", "last.url")) { Remove-Item (Join-Path $Runtime $name) -Force } Write-Host "Plataforma cerrada de forma segura." -ForegroundColor Green