fix: use Get-Process instead of Get-CimInstance for process matching

This commit is contained in:
tian 2026-05-06 14:08:13 +08:00
parent 038b5b2cfe
commit 134d5f6e34

View File

@ -18,9 +18,7 @@ function Write-Info {
}
function Get-ManagerdProcess {
$all = Get-CimInstance Win32_Process -Filter "name = 'managerd.exe'"
$matched = $all | Where-Object { $_.ExecutablePath -eq $exePath }
return $matched | Select-Object -First 1
return Get-Process -Name "managerd" -ErrorAction SilentlyContinue | Select-Object -First 1
}
function Get-HealthInfo {
@ -104,7 +102,7 @@ function Invoke-Start {
$proc = Get-ManagerdProcess
if ($proc) {
Write-Info ("已在运行PID={0}" -f $proc.ProcessId)
Write-Info ("已在运行PID={0}" -f $proc.Id)
Show-Health
return
}
@ -123,7 +121,7 @@ function Invoke-Start {
throw "进程未启动成功"
}
Write-Info ("已启动PID={0}" -f $proc.ProcessId)
Write-Info ("已启动PID={0}" -f $proc.Id)
Show-Health
}
@ -134,8 +132,8 @@ function Invoke-Stop {
return
}
Write-Info ("停止 managerd.exePID={0} ..." -f $proc.ProcessId)
Stop-Process -Id $proc.ProcessId -Force
Write-Info ("停止 managerd.exePID={0} ..." -f $proc.Id)
Stop-Process -Id $proc.Id -Force
if (-not (Wait-ForStop)) {
throw "进程停止超时"
}
@ -150,7 +148,7 @@ function Invoke-Restart {
function Show-Status {
$proc = Get-ManagerdProcess
if ($proc) {
Write-Info ("进程状态: running (PID={0})" -f $proc.ProcessId)
Write-Info ("进程状态: running (PID={0})" -f $proc.Id)
} else {
Write-Info "进程状态: stopped"
}