3

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?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

2 Answers2

6

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."
}
Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
-2

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"
  • This approach doesn't seem to work on every system. On a 2016, a 2019 and a 10 Pro, this key in never appearing while a msi is installing – NeitoFR Jan 27 '22 at 13:49