param([Parameter(Mandatory = $true)][string]$InstallDir) $ErrorActionPreference = 'Stop' $installPath = [IO.Path]::GetFullPath($InstallDir) $ownedPaths = @('ttstd_sender.exe', 'signaling_server.exe') | ForEach-Object { Join-Path $installPath $_ } # Match full executable paths, never terminate another installation by name alone. Get-CimInstance Win32_Process -Filter "Name = 'ttstd_sender.exe' OR Name = 'signaling_server.exe'" | ForEach-Object { if ($_.ExecutablePath -and $ownedPaths -contains $_.ExecutablePath) { $process = Get-Process -Id $_.ProcessId -ErrorAction SilentlyContinue if ($process) { Write-Output "Stopping installed process: $($_.ExecutablePath) ($($_.ProcessId))" if ($process.CloseMainWindow()) { $null = $process.WaitForExit(3000) } if (-not $process.HasExited) { $process.Kill() if (-not $process.WaitForExit(5000)) { throw "Process did not stop: $($_.ProcessId)" } } } } }