Powershell GUI, MSI - uninstall all previous versions?

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Powershell GUI, MSI - uninstall all previous versions?

Post by stevens »

Hi,

I'd like to uninstall any previous versions of MSI installs I installed (Powershell GUI to MSI).


There is an interesting post on MSI creation: https://www.sapien.com/blog/2019/08/15/ ... executable.
I guess I 'd have to add an msiexec.exe /x {my-product-code-guid} but:
-how can I achieve (all the) previous product codes to uninstall
-kill it when an upgrade occurs (guess something like stop-process myexe.exe)?

as I'll update my MSI really often ...

Thanks for your input!
S
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Powershell GUI, MSI - uninstall all previous versions?

Post by mxtrinidad »

If you really need to use the msiexec.exe providing the GUID, then you can use the following PowerShell code to get the installed application GUID:

## - List all Installed Apps GUID:
$appAll = Get-WmiObject -Class Win32_Product;
$appAll | select name, IdentifyingNumber | Sort-Object Name;

## - Sample uninstalling an Application using application name:
$app = Get-WmiObject -Class Win32_Product -Filter "Name = 'iTunes'" | Select IdentifyingNumber, name
$app.IdentifyingNumber.ToString()

## - Removing app using msiexec.exe
msiexec.exe /x "$($app.IdentifyingNumber.ToString())"

Of course, using PowerShell WMIObject, you can use the following method to uninstall a selected application "iTunes":

## - Uninstalling selected application: (Caution with this method!)
$app.uninstall()

Now, you could try using multiple ways of uninstalling an application.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Powershell GUI, MSI - uninstall all previous versions?

Post by Alexander Riedel »

The generates MSI will automatically uninstall the prior version before installing the new one.
All you need to do is always increment the Version number for the MSI when building it.
Alexander Riedel
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Powershell GUI, MSI - uninstall all previous versions?

Post by jvierra »

Thank you Alex. The issue is really an issue of what the MS installer technology is and how it works. Vendors like WIX and InstallShield are only using the MS installer APIs to perform installs. What is possible and how it works can be understood by reading the installer documentation on MSDN. This will inform all as to what is happening and how it happens.

Now I will lobby for changes -

The Sapien documentation is mostly complete and has almost all of the basic answers and examples however, it needs to be gathered together and presented in a more consistent way. The PowerShell Studio Product Manual is also always out of date in places although it is extremely well done and is always a first stop with any issue with using PSS to do a script development task. I still jump into it when in doubt. My one complaint is that it is not tightly tied to the product and takes some time to launch the first time in a session.

Now from the "hook" I will, once again, suggest the documentation needs to be delivered as a web service with an option to download the documentation to be used offline from a locally installed service. MS has made this quite easy with WCF and the ability to deliver HTML over HTTP directly from a database.

Windows Installer Reference: https://docs.microsoft.com/en-us/window ... -reference
WIX toolset: https://wixtoolset.org/documentation/

Assume that Sapien provides a simplified frontend to a reduced capability version of WIX and MSI. It is what is needed by all but the most sophisticated developers who would, likely, use a full installer product to build installers.
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Powershell GUI, MSI - uninstall all previous versions?

Post by stevens »

Thanks!
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Powershell GUI, MSI - uninstall all previous versions?

Post by stevens »

Thanks a lot for your input.
However, I add ps1 files to the MSI, they ARE executed (I see the blue popups during install), but the code is not executed. When I executed it manually in Powershell (the ps1 files) they work fine.
Custom actions msi should be 'when the system is modified', right?
This topic is 4 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked