1
votes

I wrote a little PowerShell script that invokes different MSI files to install software. Sometimes I got the following error from Windows Installer:

Another program is being installed. Please wait until that installation is complete, and then try installing this software again.

How could I prevent this error before I invoke the MSI files? I tried to associate this with the process TrustedInstaller. I thought that the process would come up when the PC is installing something that blocks my installation. But unfortunately, sometimes my installations work fine although the process is running. Is there a definitive indication which could be caught with PS?

2
you can check if process msiexec.exe is runningAvshalom
That's not a proper indicator. You will get many false positives.Christopher Painter

2 Answers

4
votes

You want to see if the _MSIExecute Mutex is set.

Simply checking for a running msiexec.exe won't tell you because a) msiexec could be processing a UI sequence which doesn't block you or b) msiexec could have finished an install and be waiting for 10 minutes to spin down it's service.

try
{
    $Mutex = [System.Threading.Mutex]::OpenExisting("Global\_MSIExecute");
    $Mutex.Dispose();
    Write-Host "An installer is currently running."
}
catch
{
    Write-Host "An installer is not currently runnning."
}
-1
votes

In the meantime I found the following approach: Whenever an MSI based installation is currently running a specific regkey is set. This is more reliable than trusting any processes that are active at this time. The regkey is only set when an installation is running.

Test-Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Installer\InProgress"