@echo off rem ================================================================== rem Stops the portal: ends the supervisor loop AND the node process. rem (Only kills the node.exe running THIS app's server.js - other rem Node programs on the machine are untouched.) rem ================================================================== echo Stopping SAP-ERP Portal... rem End the scheduled-task instance (if it was started via autostart) schtasks /End /TN "SAP-ERP-Portal" >nul 2>&1 rem Kill the supervisor console (titled window), if running in foreground taskkill /F /FI "WINDOWTITLE eq SAP-ERP-Portal*" >nul 2>&1 rem Kill any cmd.exe still running the supervisor loop powershell -NoProfile -Command "Get-CimInstance Win32_Process | Where-Object { $_.Name -eq 'cmd.exe' -and $_.CommandLine -match 'start-server\.bat' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force }" rem Kill the node process running server.js (works whatever the app folder rem is named; on a dedicated portal server no other node app runs server.js) powershell -NoProfile -Command "Get-CimInstance Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -match 'server\.js' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force; Write-Host (' stopped node PID ' + $_.ProcessId) }" echo Stopped. pause