18 lines
733 B
PowerShell
18 lines
733 B
PowerShell
# 单实例验证:第二个实例应在 2 秒内自动退出
|
|
$ErrorActionPreference = 'Stop'
|
|
$exe = 'E:\002_Demo\One_click_run_wpf\src\OneClickRun\bin\Debug\net8.0-windows\OneClickRun.exe'
|
|
Get-Process -Name 'OneClickRun' -ErrorAction SilentlyContinue |
|
|
Where-Object { $_.Path -eq $exe } |
|
|
ForEach-Object { Stop-Process -Id $_.Id -Force }
|
|
|
|
$first = Start-Process -FilePath $exe -PassThru
|
|
Start-Sleep -Seconds 3
|
|
$second = Start-Process -FilePath $exe -PassThru
|
|
Start-Sleep -Seconds 2
|
|
$second.Refresh()
|
|
Write-Output "FirstAlive: $(-not $first.HasExited)"
|
|
Write-Output "SecondExited: $($second.HasExited)"
|
|
if (-not $second.HasExited) { Stop-Process -Id $second.Id -Force }
|
|
Stop-Process -Id $first.Id -Force
|
|
Write-Output 'Done'
|