How can i run a Powershell script when uninstalling ? - Advanced Installer Community
Mel
Posts: 53
Joined: Fri Jul 10, 2020 10:59 am

How can i run a Powershell script when uninstalling ?

I have a powershell script that i want to run before a total uninstall. I want to run the file from the APPDIR and I want it to run before all other files are uninstalled because the script relies on reading a file and if it is deleted first then the script wont run .
How can i do this ?
Liviu
Posts: 1419
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: How can i run a Powershell script when uninstalling ?

Hello,

In order to achieve this, you can add your script before the "Remove resources" action group in the Install Execute Stage. The "RemoveFiles" standard action removes the files created in the Files and Folders page. Runs only during an uninstall.

You can also condition your script to run only when you perform an uninstall.
uninstall PS.png
uninstall PS.png (75.36 KiB) Viewed 3443 times

Hope this helps!

Best regards,
Liviu
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Mel
Posts: 53
Joined: Fri Jul 10, 2020 10:59 am

Re: How can i run a Powershell script when uninstalling ?

I have a file in my APPDIR , how can i get the file using the following

Param($appDir)

# Your code goes here.

Copy-Item "$appDir\one.txt" -Destination C:\Users\Sample

The one.txt is installed with the installer , i have checked and it is present . My install directory is c:\program files\mytestapp
It doesnt seem to recognize the appdir variable ?
Liviu
Posts: 1419
Joined: Tue Jul 13, 2021 11:29 am
Contact: Website

Re: How can i run a Powershell script when uninstalling ?

Hello,

1. If your PowerShell script is set to run on "Immediately" execution time, then you can get the APPDIR value like this:

Code: Select all

$propValue = AI_GetMsiProperty APPDIR

2. If you run your script on "deferred" execution time, you need to pass the APPDIR value into the "Parameter values" field:

Code: Select all

-mypath "[APPDIR]"

More details about these both implementation on the below article:

Getting a property value into a script (for immediate and deferred custom actions)


Attached you can find a sample project.

Best regards,
Liviu
Attachments
sample.aip
(15.93 KiB) Downloaded 210 times
________________________________________
Liviu Sandu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”