Configuring WiX Toolset Custom Actions: Ensuring Execution During System Uninstall Only
Configuring WiX Toolset Custom Actions: Ensuring Execution During System Uninstall Only
Inno SetupWiX ToolsetInstallShieldMSIX Packaging Tool
Check your inbox and confirm the
subscription
Exclusive Newsletter
Exclusive Newsletter
Get the latest WiX insights direct to your inbox. Subscribe now!
Disclaimer: This post includes affiliate links
If you click on a link and make a purchase, I may receive a commission at no extra cost to you.
How to set a WiX Toolset custom action to run only on uninstall
When you create an installer using the WiX Toolset, there are instances where you may want to set a custom action to run under specific conditions, such as uninstalling an application, installing an application, or running a custom script.
In this article, we’ll see how you can set a custom action to run when uninstalling an application using WiX Toolset.
Understanding Custom Action conditions
Every event defined in the install sequences runs under more or less specific conditions.
These conditions can target more than one installer property. For this specific example, you may need to understand how the values of the “Installed”, and “REMOVE” properties are perceived by the installer’s runs.
You can have a look at the table below:
Property Name | Install | Uninstall | Change | Repair | Upgrade |
---|---|---|---|---|---|
Installed | False | True | True | True | True |
REINSTALL | False | False | False | True | False |
UPGRADINGPRODUCTCODE | False | False | False | False | True |
REMOVE | False | True | False | False | True |
Remember that property names are case sensitive.
How to Create a Custom Action and Link it to WiX Setup Project
1. Create a new “C# Custom Action Project for WiX v3 ” in your Visual Studio solution.
Here is a basic custom action snippet which will write “Hello World!” in the installation log.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace CustomAction
public class CustomActions
[CustomAction]
public static ActionResult CustomAction(Session session)
session.Log("Hello World!");
return ActionResult.Success;
Copy
2. You can change the name of the function to a name that suits your function.
3. Then, you have to reference this custom action in your WiX setup project.
To do that, right click the “References” folder on your WiX setup project and choose “Add Reference…”
4. Following up, click on the “Projects” tab and choose your custom action project.
How to declare the WiX custom action
Now, we need to actually declare the custom action in the “Product.wxs” file. For that, you need to add the following code under the Product Tag:
Copy
In order for it to work, you have to change the following names:
“CUSTOMACTIONSNAME” | The name of the custom action that was added in the references folder |
---|---|
“CUSTOMACTIONNAME” | The name of your choice |
“CUSTOMACTIONFUNCTION” | Your custom action project’s function name that you want to call |
Adding the custom action to the Install Execute Sequence
In order for your custom action to be called when the installer is running, you need to add it to the install sequence.
Insert the custom action into the Install Execute Sequence as follows:
Copy
The Installed AND REMOVE=”ALL” condition will make sure that the custom action will run only when uninstalling the application.
How to set a custom action to run only on uninstall using Advanced Installer?
Using Advanced Installer, you can automatically set custom actions to run only on uninstall directly from its GUI - NO need to write any code.
Custom Actions are available for Professional, Enterprise and Architect project types in Advanced Installer. Have a look at how custom actions work in Advanced Installer through our 30-day full featured trial . (No credit card required)
1. To add a new custom action, go to the Custom Actions page and add a new custom action to your project.
You can use the same custom action DLL as before by adding a “Call function from attached native DLL” custom action.
2. In the Properties section, under the Function field, select the function you want your custom action to call.
3. Now, in the Execution Stage Condition section, uncheck the Install and Maintenance checkboxes. That will make sure that your custom action will run only when you uninstall the application.
And that’s it! As you could see, setting a custom action through Advanced Installer intuitive GUI requires no code skills allowing you to be time efficient when configuring your application.
Conclusion
In this article, we presented two approaches for configuring a custom action to run on uninstall.As we’ve seen, WiX is not GUI-based and sometimes it can be challenging to achieve specific tasks, having to create custom scripts from scratch. On the other hand, the process of adding custom actions is much simpler and quicker using Advanced Installer which offers a dedicated GUI for adding and defining custom actions.
We hope you like it! For more topic suggestions, leave a comment below.
Advanced Installer #1 alternative to the WiX Toolset
We decided to focus on our main goal to save precious time of our developers.
HANS-LEO TEULINGS
PHD – CEO, NEUROSCRIPT, LLC
You might find useful:
- CAB Embedding Options in MSI
- Updated installers in WiX Toolset
- Custom Actions In WiX Toolset
- Windows Services with WiX Installer
- Set WiX Installer Version to the Current Build Version
- Remove Files and Folders when Uninstalling with WiX
- How to set a WiX Toolset custom action to run only on uninstall
- How to create non-advertised shortcuts for all users / per machine with WiX Toolset
- How to Remove Files on Uninstall Using WiX Toolset
- How to create major upgrades for MSI packages using WiX Toolset
- How to pass CustomActionData to a CustomAction using WiX
- How to build an installer without a license page using WiX Toolset
- How to create a WiX KeyPath attribute
- How to Create a Desktop Shortcut using WiX Toolset
- How to Use WiX MSI to Update an Installed Application
- How to correctly set the install folder in Wix
- WiX Toolset Visual Studio Extension
- How to create a custom dialog in WiX for user input
- How to create an MSI installer with WiX
- How to use WIX MSI to do a silent install or uninstall of a web app
Get the most from packaging with Advanced Installer
Try the 30-day fully-featured edition absolutely free!
No credit card required
Also read:
- [Updated] 2024 Approved Filming for Tweet Sharing Content without Retweeting
- ABBYY Renouvele Son Image Visuelle Et Logo
- Automated Conversion Tracking with Cookiebot Technology
- Bebop 2'S Avian Spectacle – A Compreran Analysis
- Boost Your Online Presence: The Revolutionary Power of Cookiebot Integration
- Connect with Creativity: Discover the Artistry of DigiArty
- How to Fix Facebook Notifications Not Loading
- How to Rescue Lost Pictures from Motorola Moto G14?
- In 2024, Boost Your Brand Twitter Ads Guide
- Meet the Mobile Marvel: Exclusive Insights Into the HP ZBook Firefly 15 G8 Laptop
- Nextorage's Trailblazing PCIe Gen 4 M.2 NVMe SSD for Gaming - Unmatched Speeds of Up to 7,400 MB/S!
- Pionierarbeit Von DSGF Für Digitalisierung Der Finanzen: Partnerschaft Mit ABBYY Macht Wirkung
- Remedied GeForce Shader Compatibility
- Revolutionize Your Marketing Analytics with Our Cutting-Edge Cookiebot Solutions
- Seamless Integration: ABBYY Connects with Automation Anywhere
- Unleashing Endless Possibilities: The Future of Document Capture Solutions - Insights From ABBYY
- Web Page Essentials: Unlocking Effective Strategies for Search Engines
- Title: Configuring WiX Toolset Custom Actions: Ensuring Execution During System Uninstall Only
- Author: Donald
- Created at : 2024-09-30 17:06:28
- Updated at : 2024-10-03 18:37:43
- Link: https://some-tips.techidaily.com/configuring-wix-toolset-custom-actions-ensuring-execution-during-system-uninstall-only/
- License: This work is licensed under CC BY-NC-SA 4.0.