Show-InstallationPrompt only while processes are running?

So I’m popping up a user dialog (using show-installationprompt) for installing some MSI’s but only if they have some specific processes (word and excel) running. I have 2 buttons on the show-installationprompt window called “Install Now” and “Defer”. What I would like to do is have a loop checking for those processes so that if the users closes them, they don’t have to come back and hit “install now”, it would just start running automatically. Hopefully this makes sense…

Has anyone done something like this?

Here’s what I have:

If ($deploymentType -ine 'Uninstall') {
	##*===============================================
	##* PRE-INSTALLATION
	##*===============================================
	[string]$installPhase = 'Pre-Installation'

$activeProcess = Get-Process winword, excel -ErrorAction SilentlyContinue
$installType = Get-Content $dirFiles\installtype.dat -Force

If ($activeProcess -ne $null)
{ Start-Sleep -Seconds 1
If ($installType -eq “full”) { Write-Host “Commence full installation” }
Else {
$userResponse = show-installationprompt -message “nAn update needs to be installed on your computer.nnnYou will be required to close out of Word and Excel for this update to install.nnnIt is not necessary to close these programs immediately. You may close them and begin at your convenience. All other programs will remain available during the update.nnnNOTE: Clicking Defer will install this software automatically the next time you logoff or restart your computer.” -buttonrighttext “Defer Update” -buttonlefttext “Install Now”
#Do {$userResponse} Until ($activeProcess -eq $null)

If($userResponse -eq ‘Defer Update’) {
$regPath = “HKLM:\Software\Microsoft\Windows\CurrentVersion\RunOnce”

Remove-Folder “C:\Source\CW2014” -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
New-Item -ItemType Directory “C:\Source\CW2014” -Force
Copy-Item * C:\Source\CW2014 -Recurse -Force
Set-ItemProperty -Path $regPath -Name CW2014install -Value “C:\Source\CW2014\Deploy-Application.exe”
#Show-InstallationPrompt -Message “You will be prompted to install again in 24hrs.” -buttonrighttext “OK”
Write-Host “Exiting with code 3010”
exit 3010

}
}
}

I’ve done a similar thing with a do while loop. Not at my workplace until Monday but I will try and get back to you by then.

do{ 
    $strProcess = Get-Process “CMD“ -ErrorAction SilentlyContinue
    Write-Host “CMD is running.“
} 
while($strProcess )

So that’s an example how to see if CMD is running. I’m not entirely sure how you’d get that working exactly the way you want it though.

FWIW HTH

Edit: be aware of the “sad" if copy pasting.