【问题标题】:Process not found in power-shell script checking msiexec is ready for another installation在 power-shell 脚本中找不到进程检查 msiexec 是否已准备好进行另一个安装
【发布时间】:2020-04-11 19:55:21
【问题描述】:
$check = Get-Process -Name 'msiexec' 

if($check -eq $null)
{
    Write-Host 'ready for installation'
}

else
{
    Write-Host 'waiting for completion of current process'
    Sleep(10)

    if($check -eq $null)
    {
        Write-Host 'ready for installation'
    }

    else
    {
        Write-Host 'stopping the process'
       Stop-Process -Name 'msiexec' -Force
    }

 }

所以在上面第一行的代码中,它给出了错误对象未找到,因为当没有安装正在进行时 msiexec 没有运行,所以如何在 try & catch 中处理它

【问题讨论】:

    标签: powershell scripting powershell-3.0 powershell-4.0


    【解决方案1】:

    你可以用这个:

    try 
    {
      $check = Get-process -Name "msiexec" -erroraction STOP
    }
    catch
    {
      # Here will be the statements which should be executed after the error is caught.
    }
    

    【讨论】:

    • 好的,我还有一个问题要检查天气过程“msiexec”是否处于理想状态,如何检查它。由于安装完成后 msiexec 在同一时间处于理想状态,所以我想检查一下是否有人可以帮助我?
    • @vip 你可以检查"_MSIExecute" mutex是否存在。
    猜你喜欢
    • 2012-09-27
    • 2021-11-20
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    相关资源
    最近更新 更多