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.
Locked
User avatar
stevens
Posts: 443
Last visit: Thu Mar 04, 2021 2:25 am
Has voted: 1 time

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 Jan 19, 2021 10:16 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: 7665
Last visit: Wed Apr 21, 2021 12:28 am
Answers: 3
Been upvoted: 8 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: 14762
Last visit: Mon Apr 19, 2021 4:16 pm
Answers: 9
Has voted: 3 times
Been upvoted: 7 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: 443
Last visit: Thu Mar 04, 2021 2:25 am
Has voted: 1 time

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

Post by stevens »

Thanks!

User avatar
stevens
Posts: 443
Last visit: Thu Mar 04, 2021 2:25 am
Has voted: 1 time

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?

Locked