DHeinzBMGF
Posts: 8
Joined: Wed Mar 27, 2019 4:15 pm

Unable to uninstall previous app using Powershell

My msi has been re-packaged to
1) Stop Outlook.exe
2) Uninstall a previous version of PhishAlarm (installed using exe)
3) Install current version of PhishAlarm (using msi)

The msi completes but does not uninstall the previous version. I am using PowershellScriptInline

Code: Select all

$Phish = Get-ChildItem -Path HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
        Get-ItemProperty |
            Where-Object {$_.Displayversion -like "3.0.44*" -or $_.Displayversion -like "3.2.12*" } |
                   Select-Object -Property Displayversion, UninstallString

ForEach ($ver in $Phish) {

    If ($ver.Uninstallstring) {

        $uninst = $ver.Uninstallstring
           & cmd /c $uninst /q
    }

}
I'm not certain but I think I may have to modify the "Conditions" but I'm not clear as to what I should specify.
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Unable to uninstall previous app using Powershell

Hi,

The easiest way to upgrade a product (uninstall the previous version and install a new one) is to use the same Upgrade Code in the new version as in the old one. This can be set in the "Product IDs" tab from the "Product Details" page. In this case you won't need the PowerShell custom action anymore.

If you want to uninstall it through the PowerShell custom action, you can try to place it after the "Finish Execution" action group and uncheck the "Wait for custom action to finish before proceeding" and "Wait for return code at the end of the sequence" options for it.

However, this custom action will uninstall the old version after the new one was already installed. Thus, the uninstallation may break the new version if some of its resources are at the same path as the old ones.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
DHeinzBMGF
Posts: 8
Joined: Wed Mar 27, 2019 4:15 pm

Re: Unable to uninstall previous app using Powershell

So the upgrade code shown is for the new version which is an msi. The version to be uninstalled is an exe file. When I run the msi locally it performs a ise-by-side installation and does not uninstall the old version. With regard to the powershell script I have unchecked both boxes and moved the script as requested but still get the same result.

The work around is to run the old versions exe from ProgramData with the uninstall switch. This closes Outlook, Uninstalls the old version and installs the new one. I am able to uninstall the new version but when I deploy through SCCM it fails
Eusebiu
Posts: 4931
Joined: Wed Nov 14, 2012 2:04 pm

Re: Unable to uninstall previous app using Powershell

Hi,

Many EXE setups are based on MSI packages. They are actually just wrappers over MSI packages and, most likely, this is your case too. Otherwise the two versions (uninstall and install) would not conflict to each other.

So, in order to get the Upgrade Code of your old version, you can try to create a verbose log during its uninstall and search for the "UpgradeCode" property in that log.

If you cannot create a verbose log, you can enable the logging on the machine as described in the "Automated logging with the Windows Installer Logging Policy" section and it will be automatically created in the %temp% folder during the uninstall or your package.

Best regards,
Eusebiu
Eusebiu Aria - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”