rbarros-symphony
Posts: 8
Joined: Mon Jun 05, 2017 4:31 pm

Uninstall previous version when upgrade from cmd line

Hello all!

I´m facing an odd situation and I´d like to ask if someone has already seen something like this and can give me some help:

I have an installer that on previous version only allow user to install as single user.
An update was created in order to allow user to install as single user or all user.

In order to have previous version uninstalled, I have set a custom action UnistallPreviousVersion just after InstallTypeDlg.
This works like a charm when user is installed through UI and selects to install as All Users.
When user is installing through cmd line though, it does not uninstall the previous version when installing as All User. So, I ended with 2 registers on Add/Remove apps.

Is there any way to force uninstalling previous version when doing an install? I checked on Upgrades and Automatically upgrade older product version is set.

I have also tried to add a RemoveExistingProducts on Install Execution Stage but this does not seem to have any effect in my case.

I really appreciate any help on this.

Thanks!!!
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Uninstall previous version when upgrade from cmd line

Hello and welcome to our forums,

If you need to uninstall the previous installation from silent mode, you could launch a bath file at the fininsh execution. This batch should run the uninstall with a delay. This delay is necessary because Windows Installer can't run two installation processes at the same time, so you need to make sure that the first installation is completed before launching the uninstall.

The complete method is the following:
1. Copy the product code of the old installation. You could find it in "Product Details" pages, "Product IDs" tab
2. Create a batch file with the following code and paste the product code in it:

Code: Select all

timeout 10
msiexec /x {Your product code] /qn
This code will create a 10 seconds delay before the uninstall of the old product. You could configure this timeout depending on the time your application needs to uninstall.

3. Add the batch file to "Files and Folders" page
4. Create a launch file custom action for your batch file, placed last in the "Install Execution Stage", configured as described in the attached screenshot.


Best regards,
Sorin
Attachments
screenshot.jpg
screenshot.jpg (111.77 KiB) Viewed 10577 times
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
rbarros-symphony
Posts: 8
Joined: Mon Jun 05, 2017 4:31 pm

Re: Uninstall previous version when upgrade from cmd line

Hi Sorin!

Thanks for the response.
With this solution, I would have to be sure that user is using an specific previous version, wouldnt I? Product code vary from one version to another.
This is something that can be problematic. We have several users, they can be on different previous versions when upgrading. One solution would be getting all product codes for previous version and add it on the batch uninstaller.
Also, I noticed that after installing the new version, uninstalling previous version result on abnormal two entries on Add/Remove programs. How can I know why is this happening?

Thanks!!
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Uninstall previous version when upgrade from cmd line

Hello,
Product code vary from one version to another
You could write a custom action that identifies the product code of the old version based on the upgrade code of the package, which is the same for all versions.
Please take a look on our user guide article regarding How to integrate and debug custom actions

-in you custom action code you could use MsiEnumRelatedProducts function to return the product code and store it in an installer property, for example "PC_PROPERTY"
-modify you batch file in order to pass the PC_PROPERTY as a parameter . Its code should have the following form:

Code: Select all

timeout 10
msiexec /x %1 /qn
-modify you launch file custom action for the bat file, by entering "[PC_PROPERTY]" in the command line field.
Also, I noticed that after installing the new version, uninstalling previous version result on abnormal two entries on Add/Remove programs. How can I know why is this happening?
This happens because of a Windows Installer limitation : A per-user installation cannot upgrade a per-machine installation and a per-machine installation cannot upgrade a per-user installation. This limitation can be overcome by the method I presented earlier. Basically, you will see two entries in Control Panel for 10 second after the upgrade is installed, if the delay from the batch file is configured to this interval. After that delay, the uninstall will be triggered and the old version will disappear from Control Panel.

The standard Windows Installer behaviour, when the installation type is not changed by an upgrade from per-user to per-machine or vice versa, when the upgrade is performed is the following: the old package is automatically removed by Windows Installer before the new one is installed,thus the method presented earlier is redundant.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
rbarros-symphony
Posts: 8
Joined: Mon Jun 05, 2017 4:31 pm

Re: Uninstall previous version when upgrade from cmd line

Sorin, hi!

I have tried this approach using C# Custom Action and it seems to work.

Thanks!
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Uninstall previous version when upgrade from cmd line

Hello,

You are welcome! Please let me know if you have any other questions.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
rbarros-symphony
Posts: 8
Joined: Mon Jun 05, 2017 4:31 pm

Re: Uninstall previous version when upgrade from cmd line

Sorin, hi!

After implementing the postponed uninstall approach, it is correctly started BUT there are some leftovers on the machine. For instance, the entries on Add/Remove Programs are still there. Have you seen something like this before?
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Uninstall previous version when upgrade from cmd line

Hello,

Have you tried to refresh the Add/Remove Programs page after waiting for the delayed uninstall to take place? The entries should disappear after the uninstall.
Also please analyze if the delay you've chosen is sufficient for your application.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
rbarros-symphony
Posts: 8
Joined: Mon Jun 05, 2017 4:31 pm

Re: Uninstall previous version when upgrade from cmd line

Hi Sorin!
Yes, I have tried both refreshing contents of add/remove page and increasing time to start uninstall. None of these action help.
The Removed App still remains on add/remove page.
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Uninstall previous version when upgrade from cmd line

Hello,

If you try to manually uninstall the application, is the Control Panel entry removed?

Please take a look on the way my attached sample projects(old and upgrade) are configured.
I have implemented your scenario using a launch file custom action that launches a batch file containing the msiexec /x command. The previous version product code is sent as a parameter to the batch file. The uninstall command is executed with a 10 second delay.

You could build and install the sample project. 10 seconds after the upgrade package install, the first package will be removed and will disappear from Control Panel.

Best regards,
Sorin
Attachments
sample.zip
(6.95 KiB) Downloaded 278 times
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
rbarros-symphony
Posts: 8
Joined: Mon Jun 05, 2017 4:31 pm

Re: Uninstall previous version when upgrade from cmd line

Hi Sorin!

Thank you very much for your effort on helping us! I really appreciate that!

I have tried your demo project without success. It seems that .bat file is not doing the uninstall, not sure the reason.
Here are the steps I did:
-Installed latest Advanced Installer downloaded from webpage.
-Unzipped the provided project files.
-Build Your Application.aip on root of sample folder. (1)
-Build Your Application.aip on upgrade folder. (2)
-Performed simple next-next-finish install of (1) msi file.
-Executed on (2) output folder: msiexec /i "Your Application.msi" /q /l* install.log

Results are: first version (1.0.0) is installed. Second version (1.0.1) is installed. None is uninstalled after some time (>10s).

I have manually uninstalled version 1.0.0 from control panel and everything went fine though.

So, in order to have your sample project more likely to what we need, I have performed some changes on your sample project (attached). bat file also logs into "c:\" root folder. Installer has single / all users selection.
Our scenario is upgrading an existing 1.0.0 version installed as single user by installing by admin an updated 1.0.1 version as all users.
Attachments
sample.zip
(7.87 KiB) Downloaded 250 times
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Uninstall previous version when upgrade from cmd line

Hello,

You are always welcome!
I have tried your demo project without success. It seems that .bat file is not doing the uninstall, not sure the reason.
I'm not sure why this happens. I have tested my sample on multiple machines and it works. Please pay attention to the UAC prompt at the end of the installation. Sometimes this prompt could be sticking in the background, flashing in the taskbar. Without clicking "Yes" on the prompt's dialog, the launch bat file custom action is not executed.

Please try to test my sample on other machines. For testing purposes we always recommend to be used virtual machines with clean states so that when something goes wrong you can easily revert to a clean state of the virtual machine.
So, in order to have your sample project more likely to what we need, I have performed some changes on your sample project (attached).
Please note that in my sample, the product code is retrieved via a registry search performed in Local Machine hive (this key is created by the first package which is installed per machine, thus the key is installed in Local Machine).

Please take a look on the attached sample based on the sample you've posted. I have modified the registry search in order to work for all possible scenarios : first install is per user, upgrade is per machine or first install is per machine, upgrade us per user.

Anyway, this registry search is just a simple way to retrieve the old product code, but as your first package is already released, you should obtain the product code via the custom action you wrote in C# (with MsiEnumRelatedProducts function).

Best regards,
Sorin
Attachments
sample.zip
(6.95 KiB) Downloaded 261 times
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
rbarros-symphony
Posts: 8
Joined: Mon Jun 05, 2017 4:31 pm

Re: Uninstall previous version when upgrade from cmd line

Hi Sorin!

Thanks again!

I still could not make this version works. It is possible that it is because I tested on Win10 32bits which makes Registry entry being placed under Wow6432node.
Anyway, I have changed demo project to use C# Custom Action and it seems fine!
I´ve applied some changes on my .aip project file and we are testing it. So far so good!

Thanks for helping!
Sorin
Posts: 663
Joined: Mon May 08, 2017 1:03 pm

Re: Uninstall previous version when upgrade from cmd line

Hello,

You're welcome! I'm glad that you've sorted things out using the C# custom action implementation. Please let me know if you have any other question.

Best regards,
Sorin
Sorin Stefan - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”