Run Show-InstallationWelcome only when apps need to be closed

We’re trying to be as inobtrusive as possible when deploying “updates” (i.e. newer versions of a program already installed in the user’s device).

In order to achieve that, we wanted to run Show-InstallationWelcome only if anything needs to be closed. Our current line reads as follows:

Show-InstallationWelcome -CloseApps 'program1,program2' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt -ForceCloseAppsCountdown 30

We want the Welcome window to only show, though, if program1 and program2 are running and needs to either be closed or give the user the option to defer. Otherwise, it should just silently proceed to install in the background.

Is there a way to do that? I thought about commenting out that line but then the user will never get prompted if either program1 or program2 is running.

I always thought Show-InstallationWelcome would not show if all applications listed were already closed. Please note that some applications have multiple instances running at the same time or are restarted automatically. I ran into this and I ended up using 2 lines of Show-InstallationWelcome. One prompting the user to close many apps and the other to forcibly and silently close the one that would not die.

It definitely shows up even if I randomly type in characters after -CloseApps to simulate a non-existent app.

For exactly the same reasons as you, I have a workaround for this in some of my scripts, for example with our Firefox installs I check if Firefox is running to decide if I need to show the Show-InstallationWelcome screen.

N.B. I have prefixed my amended lines with a > in the code below to show you the changes I made

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

  >     if (get-process Firefox) {
  >	    $AppRunning = $true
	    ## Show Welcome Message, close Internet Explorer if required, allow up to 3 deferrals, verify there is enough disk space to complete the install, and persist the prompt
	    Show-InstallationWelcome -CloseApps 'Firefox=Mozilla Firefox' -BlockExecution -MinimizeWindows $false -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt -TopMost $true

            ## Show Progress Message (with the default message)
            Show-InstallationProgress

            ## <Perform Pre-Installation tasks here>


            ##*===============================================
            ##* INSTALLATION
            ##*===============================================
            [String]$installPhase = 'Installation'

            ## Handle Zero-Config MSI Installations
            If ($useDefaultMsi) {
                [Hashtable]$ExecuteDefaultMSISplat = @{ Action = 'Install'; Path = $defaultMsiFile }; If ($defaultMstFile) {
                    $ExecuteDefaultMSISplat.Add('Transform', $defaultMstFile)
                }
                Execute-MSI @ExecuteDefaultMSISplat; If ($defaultMspFiles) {
                    $defaultMspFiles | ForEach-Object { Execute-MSI -Action 'Patch' -Path $_ }
                }
            }
>	} else {
>	    $AppRunning = $false
>	}

        ## <Perform Installation tasks here>
	Execute-Process -Path "$($dirFiles)\firefoxsetup.exe" -Parameters "-ms"

        ##*===============================================
        ##* POST-INSTALLATION
        ##*===============================================
        [String]$installPhase = 'Post-Installation'

        ## <Perform Post-Installation tasks here>
	
>	if ($AppRunning -eq $true) {
            ## Display a message at the end of the install
            If (-not $useDefaultMsi) {
                Show-InstallationPrompt -Message "Installation completed successfully.`r`nYou may now use Mozilla Firefox (version: 115.0.2)" -ButtonRightText "OK" -Icon Information -NoWait
            }
>	}
    }
    ElseIf ($deploymentType -ieq 'Uninstall') {
.....etc
1 Like

Thank you so much @Adrian_Scott. That worked perfectly.

Although our requirements do not exactly match, I understood what you did there and have made the same modifications but for the UNINSTALL and REPAIR sections in our case because we figured that if someone was installing an app, they’d want to be notified what’s happening whether or not the app was running. However, if we (IT) wanted something uninstalled and updated (we’re using the REPAIR section for forcing updates silently because a vulnerability exists in the software) then we really shouldn’t be bothering the user unless the app was running.

Cheers mate!

1 Like

You may want to use the AllowDeferCloseApps argument insted of the AllowDefer

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.