diff --git a/scripts/managerd.ps1 b/scripts/managerd.ps1 index fcba70c..77c3479 100644 --- a/scripts/managerd.ps1 +++ b/scripts/managerd.ps1 @@ -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.exe,PID={0} ..." -f $proc.ProcessId) - Stop-Process -Id $proc.ProcessId -Force + Write-Info ("停止 managerd.exe,PID={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" }