gvnsandeep
Posts: 7
Joined: Tue Aug 11, 2020 3:23 pm

How to uninstall the package immediately after the installation has completed using PowerSheel

Fri Oct 29, 2021 12:06 pm

Hi,

I have a requirement to uninstall the MSI immediately after completing the installation using a Power Shell Script. Could you please let me know how to achieve that?

I am using the code below to do that "msiexec /uninstall "{66F0FF56-7139-48D7-BB00-B39F6A93A93D}" /qn".

I would like to make it dynamic which means "{66F0FF56-7139-48D7-BB00-B39F6A93A93D}" should be replaced with some thing like session.property("ProductCode") which will read the value directly from advanced installer properties and uninstall the package after finishing the installation. Could you please gudide me in achieving this.

Regards,

G.V.N.Sandeep

Liviu
Posts: 1035
Joined: Tue Jul 13, 2021 11:29 am
Contact:  Website

Re: How to uninstall the package immediately after the installation has completed using PowerSheel

Fri Oct 29, 2021 1:38 pm

Hello G.V.N.Sandeep,

To achieve this you can proceed as it follows:

1. Go to the "Custom Actions" page and add a "PowerShellScriptInline" custom action without sequence with the following code:

Code: Select all

#Requires -version 3
Param()

$propValue = AI_GetMsiProperty ProductCode


$MSIArguments = @(
    "/uninstall"
    ($propValue)
    "/qn"
)

Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow

2. Add this custom action on the Published Events of the "Finish" button --> "ExitDialog" dialog in the "Dialogs" page.
ExitDialog.png
ExitDialog.png (114.28KiB)Viewed 5265 times

I've tested this and everything works as expected.

You also need to make sure that your package is running elevated, otherwise you can not uninstall the package silently.

Please let me know if that helped you.

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”