Need Help With Removal Of Older Version Of Application

Hello there everyone, so I have the majority of the script already and working. But I wanted to enhance my script a bit more and I need some help. Basically, I am using the PowerShell AppDeploy Toolkit to Install/Uninstall Microsoft Windows Desktop Runtime. Where I need help is removing the older versions before installing the latest version v6.0.7

## Remove Any Existing Version of Microsoft Windows Desktop Runtime 5.X
$RuntimePath5 = Get-ChildItem -Path "C:\ProgramData\Package Cache\*" -Include windowsdesktop-runtime-5.0.*win*.exe -Recurse
ForEach ($Runtime in $RuntimePath5) {
Write-Log -Message "Found $($Runtime.FullName), now attempting to uninstall $installTitle."
Execute-Process -Path "$Runtime" -Parameters "/uninstall /quiet /norestart /log $configToolkitLogDir\NETDesktopRuntime50-Uninstall.log" -WindowStyle Hidden
}

## Remove Any Existing Version of Microsoft Windows Desktop Runtime 6.X
$RuntimePath6 = Get-ChildItem -Path "C:\ProgramData\Package Cache\*" -Include windowsdesktop-runtime-6.0.*win*.exe -Recurse
ForEach ($Runtime in $RuntimePath6) {
Write-Log -Message "Found $($Runtime.FullName), now attempting to uninstall $installTitle."
Execute-Process -Path "$Runtime" -Parameters "/uninstall /quiet /norestart /log $configToolkitLogDir\NETDesktopRuntime60-Uninstall.log" -WindowStyle Hidden
}

My goal is to remove all the older versions that are less than the current ones being deployed which in this case is v6.0.7. Appreciate the time and help with this question.

Is the uninstalls failing?
or are you asking how to retrieve the version number from the main executable?

Please note that I am not familiar with “Windows desktop”

Well in our envirotment, we have multiple versions of Microsoft Windows Desktop Runtime. What I am trying to do is in the Pre-Installation stage, where I am trying to look for all the installed versions of Microsoft Windows Desktop Runtime on the systems and uninstall any version that is else then v6.0.7. I hope this help, thank you for your help.

Go on a few machines and determine how to obtain the version of “Microsoft Windows Desktop Runtime”. Once you determine how to do this, I or others can help you.

Sometime the version of the main EXE will match what is shown in the app.
Otherwise you will have to extract that version info from Programs and Features or by other means.

Lol, I guess I am doing a horrible job explaining myself. If you look at my code, you will see that I have a process scripted to look for versions 5.x, and 6.x individually, so I know how to get the versions.

What I would like to do is simplify my chunk of code and look for any version that is less the 6.0.7. If it finds anything less than the current version, uninstall the older versions of the application before installing the current one which in this case is v6.0.7

This will work but if you encounter versions higher than 6.0.7, it will remove it:

## Remove Any Existing Version of Microsoft Windows Desktop Runtime 6.X
$RuntimePath6 = Get-ChildItem -Path "C:\ProgramData\Package Cache\*" -Include windowsdesktop-runtime-6.0.*win*.exe -Recurse
ForEach ($Runtime in $RuntimePath6) {
	If ($Runtime.BaseName -like "*6.0.7*") { #Quick-n-dirty but cannot handle higher versions
		Write-Log -Message "Found [$($Runtime.FullName)], Leaving it alone"
	} Else {
		Write-Log -Message "Found [$($Runtime.FullName)], now attempting to uninstall [$installTitle]."
		Execute-Process -Path "$Runtime" -Parameters "/uninstall /quiet /norestart /log $configToolkitLogDir\NETDesktopRuntime60-Uninstall.log" -WindowStyle Hidden
	}
}

A better solution is to use REGEX to extract the version number in the filename of the installation file and skip versions equal or higher than 6.0.7.
I just don’t have the time to fight that demon right now.

1 Like

Option #1:

Looking in my own Registry, I see the Uninstall Key for “Microsoft Windows Desktop Runtime” calls MSIExec, so you should be able to use PSADT’s Remove-MSIApplication cmdlet. (I have three versions of the desktop runtime installed, though I’ve never worked with it and am not sure its purpose.)
“RemoveAllButThisVersion” is the version # you want to keep.

Remove-MSIApplications -Name "*Windows Desktop Runtime*" -ExcludeFromUninstall (,('DisplayName', '<RemoveAllButThisVersion>', 'Contains'))

– Or –
Option#2:

This is how I remove previous versions of Java prior to installing the latest update.
(thought I posted this in response to another question earlier this week, but now can’t find it)

Query the Registry for installed versions and run the Uninstall String for all found versions.

    $x86 = 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
    $x64 = 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
    $x86Uninstall = Get-ChildItem -Path $x86 | ForEach-Object { Get-ItemProperty -Path $_.PSPath } | Where-Object { $_ -match 'Java ' } | Select-Object -Property UninstallString
    $x64Uninstall = Get-ChildItem -Path $x64 | ForEach-Object { Get-ItemProperty -Path $_.PSPath } | Where-Object { $_ -match 'Java ' } | Select-Object -Property UninstallString
    
    If ($x86Uninstall) 
    {
      $x86Uninstall = $x86Uninstall.UninstallString -Replace 'msiexec.exe','' -Replace '/I','' -Replace '/X',''
      $x86Uninstall = $x86Uninstall.Trim()
      Write-Log -Message 'Uninstalling older 32-bit version(s)...'
      Start-Process -FilePath 'msiexec.exe' -ArgumentList "/$x86Uninstall /q" -Wait
    }
        
    If ($x64Uninstall) 
    {
      $x64Uninstall = $x64Uninstall.UninstallString -Replace 'msiexec.exe','' -Replace '/I','' -Replace '/X',''
      $x64Uninstall = $x64Uninstall.Trim()
      Write-Log  -Message 'Uninstalling older 64-bit version(s)...'
      Start-Process -FilePath 'msiexec.exe' -ArgumentList "/$x64Uninstall /q" -Wait
    }

Since I’m not clear on just what Microsoft Windows Desktop Runtime does/is used for, I can’t vouch for how Windows will react to removing it. I suggest you test thoroughly!

2 Likes

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