Adding an If statement to detect previous versions

Hi
I’m trying to wrap my head around how best to do this. For info I’m almost completely new to psadt.

What I want to do is have the toolkit detect if an old version exists and if so call the uninstall, else goto the install.

The particular application has to have a mandatory reboot after uninstall or it breaks the app. You can’t install over the top.

I have managed to get it to work, but I feel this is probably not the best way as it seems a bit hacky

I’d like to know if there is a better way of doing it and how to call the install or from inside the invoke-application ps1. I basically wrapped the info for the install and uninstall processes in the if statement.

  # App variables.
    AppVendor = 'Numecent, Inc.'
    AppName = 'Cloudpaging Player'
    AppVersion = '9.4.4.2436'
    AppArch = 'x64'
    AppLang = 'EN'
    AppRevision = '01'
    AppSuccessExitCodes = @(0)
    AppRebootExitCodes = @(1641, 3010)
    AppScriptVersion = '1.0.0'
    AppScriptDate = '02/19/2025'
    AppScriptAuthor = 'ISB'

    # Install Titles (Only set here to override defaults set by the toolkit).
    InstallName = ''
    InstallTitle = ''

    # Script variables.
    DeployAppScriptFriendlyName = $MyInvocation.MyCommand.Name
    DeployAppScriptVersion = '4.0.4'
    DeployAppScriptParameters = $PSBoundParameters
}

function Install-ADTDeployment
{
    ##================================================
    ## MARK: Pre-Install
    ##================================================
    $adtSession.InstallPhase = "Pre-$($adtSession.DeploymentType)"

    Show-ADTInstallationWelcome -CloseProcesses @{ Name = 'JukeboxPlayer'; Description = $null } -CloseProcessesCountdown 1800 -AllowDefer -DeferTimes 3
    $app =  Get-ADTApplication -Name 'Cloudpaging Player' -NameMatch 'contains'
    
if ($app) {
	Show-ADTInstallationProgress   
   Uninstall-ADTApplication -Name 'Cloudpaging Player' -NameMatch 'contains' -ApplicationType 'MSI'
	## Master Wrapper detection
    Remove-ADTRegistryKey -Key "HKLM\SOFTWARE\InstalledApps\Numecent, Inc._Cloudpaging Player_9.4.4.2436"
    Show-ADTInstallationRestartPrompt -CountdownSeconds 1800 -CountdownNoHideSeconds 300
} else {
     
    Show-ADTInstallationProgress
     Start-ADTMsiProcess -Action 'Install' -FilePath 'cloudpaging-player-setup-x64_9.4.4_hotfix.msi'
	 Show-ADTInstallationRestartPrompt -CountdownSeconds 1800 -CountdownNoHideSeconds 300

    ## Master Wrapper detection
    Set-ADTRegistryKey -Key "HKLM\SOFTWARE\InstalledApps\Numecent, Inc._Cloudpaging Player_9.4.4.2436"
}
}

    
{
    Show-ADTInstallationProgress

I would be more worried about if MECM/SCCM/Intune would target the same machines over and over again while your PSADT detection says it not a good match.

That wasn’t an issue in the v3 version where we called the if statement to call the uninstall or install, the detection was with a registry key and exact exe = version greater than or = to.

I managed to deploy to circa 10’000 machines and the only issue we had was with broken installs of the cloudpaging player where it just flat refused to uninstall regardless what method you used. But for the vast majority, it worked.
I’m just trying to do it the right way, but due to lack of decent examples for v4 I feel I’m doing this blind.

1 Like

Hi,

I haven’t repackaged it for v4, but this is the logic I use:

If (Test-Path -LiteralPath "C:\Program Files\Numecent\Application Jukebox Player\JukeboxPlayer.exe")
{
    # Upgrade
    Write-Log -Message "Cloudpaging Player will be upgraded" -Source "Cloudpaging Player"
    Execute-MSI -Action Install -SkipMSIAlreadyInstalledCheck -Path 'cloudpaging-player-setup-x64.msi' -Parameters "/qn /norestart REBOOT=ReallySuppress REINSTALL=ALL REINSTALLMODE=vamus"
}
Else
{
    # New Install
    Write-Log -Message "New installation of Cloudpaging Player" -Source "Cloudpaging Player"
    Execute-MSI -Action Install -SkipMSIAlreadyInstalledCheck -Path 'cloudpaging-player-setup-x64.msi' -Parameters "/qn /norestart REBOOT=ReallySuppress ET_AUTO_ELEVATION=1 ET_CACHE_SIZE=`"$cacheSize`""
}

Basically you can just use the upgrade feature of the MSI, rather than uninstall/install manually.
And for the time being, you’ll need to reboot the device afterwards.

HTH!

1 Like

Two ways you can do it.

I added my own sections in our scripts so its easy to read what stage the deployment is at.

$previouschrome = (Get-ADTApplication -Name 'Google Chrome')
    if ($previouschrome -ne $null){   
    Write-ADTLogEntry -Message "$($adtSession.Appvendor, $adtSession.Appname) previous version detected. Uninstalling."
    Uninstall-ADTApplication -InstalledApplication $previouschrome `
    -LogFileName "$($adtSession.Appvendor, $adtSession.Appname) Previous Version" `
    -ArgumentList '/QN /noreboot'}
    
    else{
    Write-ADTLogEntry -Message "No previous versions detected. Moving onto Pre-Requisites stage"}

The above removes any other version of chrome we have installed so the latest is only installed on devices.

for what i would call “BAU”

$QGIS3165 = Test-Path -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\QGIS 3.16"

    if($QGIS3165 -eq $true){
    Write-ADTLogEntry -Message "$($adtsession.appvendor, $adtsession.appname) 3.16.5 detected. Uninstalling"
    Start-ADTProcess -FilePath "C:\Program Files\QGIS 3.16\uninstall.exe" `
    -ArgumentList "/S"
    Write-ADTLogEntry -Message "Removing residual files"
    Remove-Item -Path "C:\Program Files\QGIS 3.16" -Force -Recurse -ErrorAction SilentlyContinue}

    else{
    Write-ADTLogEntry -Message "No previous versions to uninstall. Moving onto pre-requisite stage"}  

The above been working fine for me and then it moves onto the next stages of the installation.

2 Likes

Thanks, it’s interesting what you did, but what about the mandatory reboot we have to have for cloudpaging player, and I need this to be all visible to the end user so they can hit the restart after uninstall, hence me calling all the sections as if you had say done an invoke-appdeploy toolkit ‘uninstall’
This would work a treat for updating acrobat reader, firefox, chorme etc

.

How do you get around the reboot issue? as the cloudpaging player breaks with .com issues if you don’t do the reboot after uninstall. This is really helpful also. I can try run that through the v3 to v4 convertor and see what it spits out. I’ve found a lot of things you could get away with in v3 doesn’t work in v4.
I could always look at a mix of mine, yours and Gordy_B’s solutions.
Thanks

The thing with a mandatory reboot halfway through an install is, the install will then need to retrigger and thus, the whole sequence starts again but the else statement executes. Not sure how you can get around that.

We do test a system reboot is pending at the start of the installation as well:

if((Get-ADTPendingReboot).IsSystemRebootPending)
    {
    if ((Show-ADTInstallationPrompt -Message "An install of $($ADTsession.InstallTitle) is about to take place but is unable to proceed because your device has a reboot pending. `nPlease can you save any work and reboot so the install can begin." `
    -ButtonRightText 'Reboot Now' -ButtonLeftText 'Reboot Later' -Subtitle "Action Required") -eq 'Reboot Now')
    {
    Restart-Computer -force}
    else
    {
    Close-ADTSession -ExitCode 60012}
    }

I always give a toast at the end of the entire installation or uninstallation asking a user to reboot but, that’s the best we can do. We have been asked not to make it mandatory though (to force a reboot even with a countdown).

Hi had to look it up, because it’s one of those apps that’s a real pain… It is said that from 9.5 reboots will no longer be required, can’t wait.

So, I do not run the installation silently, but I only show dialogs if the app is installed.

        ##*===============================================
        ##* PRE-INSTALLATION
        ##*===============================================
        [String]$installPhase = 'Pre-Installation'

        ## <Perform Pre-Installation tasks here>
        If (Test-Path -LiteralPath "C:\Program Files\Numecent\Application Jukebox Player\JukeboxPlayer.exe")
        {
            # Upgrade
            Show-InstallationWelcome -CloseApps 'JukeboxPlayer' -AllowDefer -DeferTimes 3 -CheckDiskSpace -PersistPrompt
            Show-InstallationProgress

            Stop-Service -Name "StreamingCore" -ErrorAction SilentlyContinue
        }

        # Delete reference to the previous version's MSI file name, in case it is different  (causes MSI error 1316)
        Remove-ItemProperty -Path HKLM:\SOFTWARE\Classes\Installer\Products\C7BF6F322E1CB194191A40145D91B17C\SourceList -Name PackageName -ErrorAction SilentlyContinue

In terms of the reboot, you only need one if you upgrade, note the following parameters when executing the MSI for upgrade:
“REINSTALL=ALL REINSTALLMODE=vamus”

and in post-install I just do:

## Display a message at the end of the install
        If ($DeployMode -eq 'Interactive')
        {
            Write-Log "Prompting for reboot"
            Show-InstallationRestartPrompt -CountdownSeconds 3600 -CountdownNoHideSeconds 120
        }

But I can see a lot of commented code in this section, it looks like I used to check if no one was logged on and would reboot right away, but that broke Autopilot.

Hope that makes sense!

… Alex …

1 Like

For reference: https://support.appsanywhere.com/hc/en-us/articles/231990328-Managed-Deployment-of-AppsAnywhere-Clients#h_01H9TQ1DMJ04EP14K56PS4E3S6

1 Like

Hi,
Yep that does make sense, I’ve put the switches in the config file in v4.
You’ll see I pushed Numecent to give us a clean up utility in the support pages over on AA as we had some destroyed desktops that a rebuild was the best fix previously when there had been an issue with deployment order and people trying to fix the install that didn’t know the correct order and reboot process. It became impossible to uninstall the cloudpaging player as it had disappeared from add and remove but there were bits hidden here and there, we needed something for the service desk to run to fix it .
I have the reboot prompt as you’ll see in my code at the top of thread. I was just checking if I’d missed something.
The v4 is an absolute head wobble after v3 where we just called a separate install script and uninstall script from the install and uninstall section. We used the psappdeploy as a hack to get the user reboot message and wrap our uninstall and install in a user interface. But as I’m doing it from scratch rather than a colleague I can see the advantage of trying to do it all within the toolkit and using their syntax, that way when there’s a v4.7 or whatever version I can drop in the new toolkit files and not have to redo the whole thing if I understood the presentation.
Like you, I can’t wait for 9.5, well actually, 9.6 as the versions after 9.5 don’t need a reboot.

Yeah that’s another issue, Autopilot, a reboot part way through an autopilot build will cause Autopilot to break. So we have the guy who does autopilot do his own version tweaked from mine as he knows best about autopilot and I know best About AppsAnywhere clients