특정 Windows Installer 업데이트(MSP) 설치의 성공 여부를 스크립트에서 어떻게 확인할 수 있습니까?

특정 Windows Installer 업데이트(MSP) 설치의 성공 여부를 스크립트에서 어떻게 확인할 수 있습니까?

저는 매우 많은 수의 MSP 업데이트( .msp확장명이 있는 파일, Windows Installer를 통해 배포됨)를 차례로 설치하기 위해 PowerShell 스크립트(아래 참조)를 작성했습니다. 이제 MSP 업데이트 설치가 실패한 경우에도 이 스크립트를 통해 알려주고 싶습니다.

내가 시도한 것: 오류 코드 쿼리.두 가지 접근 방식이 있습니다.

  • 하나는 직접 실행한 후 $LASTEXITCODE를 사용하여 오류 코드를 얻는 것입니다 MSIEXEC.EXE. 지루하다.
  • 다른 하나는 -PassThru에 스위치를 추가하고 Start-Process그 결과를 객체에 저장하고 를 $a사용하여 오류 코드를 읽는 것과 관련이 있습니다 $a.ExitCode. 이와 같이:

    $a=Start-Process msiexec.exe -ArgumentList "/p `"$MspRelPath`" /log `"$LogRelPath`" /passive /norestart" -Wait -PassThru
    Write-Host $a.ExitCode
    

둘 다 유용하지 않습니다. msiexec.exe종료 코드로 항상 0을 반환하는 것 같습니다 .


누구든지 관심이 있는 경우 스크립트는 다음과 같습니다.

param (
    [parameter(mandatory=$false)][Switch]$BypassAdminPrompt
)
Try 
{
  Clear-Host

  # Get script name
  $ScriptFileObject=(Get-Item $PSCommandPath)
  $ScriptName=$ScriptFileObject.Name
  $ScriptPath=$ScriptFileObject.DirectoryName

  # Load Windows Forms and initialize visual styles
  [void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
  [System.Windows.Forms.Application]::EnableVisualStyles()

  # Is the script holding administrative privileges?
  $wid=[System.Security.Principal.WindowsIdentity]::GetCurrent()
  $prp=new-object System.Security.Principal.WindowsPrincipal($wid)
  $adm=[System.Security.Principal.WindowsBuiltInRole]::Administrator
  $IsAdmin=$prp.IsInRole($adm)
  if ($IsAdmin -eq $false) {
    if (!$BypassAdminPrompt) {
      Start-Process powershell.exe -ArgumentList "-ExecutionPolicy $env:PSExecutionPolicyPreference -File `"$PSCommandPath`" -BypassAdminPrompt" -Verb RunAs
    } else {
      $result=[System.Windows.Forms.MessageBox]::Show("This script requires administrative privileges, which are absent.", $ScriptName, "OK", "Error");
    }
    break;
  }

  # Install...
  Set-Location $ScriptPath
  $MSP_list = Get-ChildItem *.msp -Recurse
  if ($MSP_list -eq $null) {
    $result=[System.Windows.Forms.MessageBox]::Show("Nothing found to install.`rSearch path was "+$ScriptPath, $ScriptName, "OK", "Error");
  }
  else
  {
    $MSP_list | ForEach-Object {
      # Ordinarily, I'd pass the path in the form of ".\foldername\filename.msp" but Windows Installer does not accept that.
      # It must be in "foldername\filename.msp" form.
      $MspRelPath = $_.FullName.Substring($ScriptPath.Length+1)
      $LogRelPath = $MspRelPath+".log"
      Write-Host $MspRelPath
      Start-Process msiexec.exe -ArgumentList "/p `"$MspRelPath`" /log `"$LogRelPath`" /passive /norestart" -Wait
    }
    Remove-Variable MspRelPath
    Remove-Variable LogRelPath
    Pause
  }
  Remove-Variable MSP_list
}
Catch
{
  $result=[System.Windows.Forms.MessageBox]::Show("Error!`r`r"+$Error[0], $ScriptName, "OK", "Error");
  break;
}

답변1

MSIExec 이벤트에 대한 Windows 이벤트를 확인하거나 완료되면 로그 출력 내용을 가져와 실패 표시를 확인하십시오.

MSIExec을 사용하여 원격으로 MSI를 설치하고 MSIExec이 종료될 때까지(또는 프로세스/서비스가 시작될 때까지) 기다리는 스크립트가 있습니다. 일반적인 설치 시간 이후에 아무 일도 일어나지 않으면 MSIExec 호출에 포함된 로그 경로를 확인하고 실패 또는 성공 메시지 확인

관련 정보