param([Parameter(Mandatory = $true)][ValidateSet('baseline', 'reference')][string]$Copy)
# Agent S: stop the app started by start-app.ps1, by its recorded pid, only if it is still that dotnet process.
$scan = '<scratch>\sec\scan'
$pidFile = Join-Path $scan "out\zap\$Copy\app.pid"
$appPid = [int](Get-Content $pidFile)
$p = Get-CimInstance Win32_Process -Filter "ProcessId = $appPid"
if ($null -eq $p) { Write-Output "pid $appPid not running"; exit 0 }
if ($p.CommandLine -notlike '*PatientPortal.Api.dll*') { Write-Output "pid $appPid is not the app: $($p.CommandLine)"; exit 1 }
Stop-Process -Id $appPid -Force
Write-Output "stopped pid $appPid"
