$ErrorActionPreference = 'Stop' $root = Split-Path $PSScriptRoot try { $exe = Join-Path $root 'build\KSwitcher.exe' $running = @(Get-Process KSwitcher -ErrorAction SilentlyContinue | Where-Object { $_.Path -eq $exe }) $stop = Start-Process -FilePath $exe -ArgumentList '--exit' -WindowStyle Hidden -PassThru if (-not $stop.WaitForExit(5000)) { throw 'Exit command timed out.' } foreach ($process in $running) { if (-not $process.WaitForExit(10000)) { throw 'KSwitcher did not stop.' } } Copy-Item -LiteralPath (Join-Path $root 'build\staged\KSwitcher.exe') -Destination $exe -Force Start-Process -FilePath $exe -WindowStyle Hidden 'OK' | Set-Content -LiteralPath (Join-Path $root 'build\update-result.txt') } catch { $_.Exception.Message | Set-Content -LiteralPath (Join-Path $root 'build\update-result.txt'); exit 1 }