fix: resolve full exe path via Get-Command for Start-Process

This commit is contained in:
tian 2026-07-20 14:22:07 +08:00
parent c09a999710
commit e1e5f783c0

View File

@ -37,17 +37,21 @@ function Write-Banner {
function Start-Detached {
param([string]$Name, [string]$Exe, [string[]]$Args, [switch]$Visible)
$found = (Test-Path $Exe) -or (Get-Command $Exe -ErrorAction SilentlyContinue)
if (-not $found) {
$exePath = $Exe
if (-not (Test-Path $Exe)) {
$cmd = Get-Command $Exe -ErrorAction SilentlyContinue
if ($cmd) { $exePath = $cmd.Source }
}
if (-not $exePath -or -not (Test-Path $exePath)) {
Write-Host " [SKIP] $Name : 未找到 $Exe" -ForegroundColor Yellow
return $null
}
Write-Host " [START] $Name" -ForegroundColor Green
Write-Host " [START] $Name ($exePath)" -ForegroundColor Green
$style = if ($Visible) { "Normal" } else { "Minimized" }
if ($Args -and $Args.Count -gt 0) {
$proc = Start-Process -FilePath $Exe -ArgumentList $Args -WindowStyle $style -PassThru
$proc = Start-Process -FilePath $exePath -ArgumentList $Args -WindowStyle $style -PassThru
} else {
$proc = Start-Process -FilePath $Exe -WindowStyle $style -PassThru
$proc = Start-Process -FilePath $exePath -WindowStyle $style -PassThru
}
Start-Sleep -Milliseconds 500
return $proc