Any tips on getting the cancel button working for a deferred custom action?
Question
Any tips on getting the cancel button working for a deferred custom action?
During our MSI uninstallation (full GUI mode), at the beginning of the uninstallation we call a deferred CA. When this CA is executing, if the user clicks the cancel button, the windows installer will pop up the dialog asking you if you want to really exit the (un)installation or resume. At this stage, if I click to cancel the installation, nothing happens, and after our CA completes and file removal starts, clicking on the cancel button again throughout the rest of the uninstallation had absolutely no effect… I checked our MSI package’s cancel dialog, the two buttons are returning the right events (Return, and Exit events).
My questions are
- Do I need to do anything in our custom action functions to handle the exit event?
- Or is this handled by the windows installer?
- If I need to handle this myself – what do I need to do?
- Also, why does the cancel button not work when it’s pressed again after my custom action has returned?
Answer
You should look at the return values from various MSI functions (such as MsiProcessMessage, you are sending progress messages aren't you?). You'll notice that there are return values that indicate the user has clicked cancel while your action was running. If this occurs, your CustomAction should bail and return ERROR_INSTALL_USEREXIT.
You can see examples how this is done in the WiX serverca CustomActions... they use the core OcaXXX functions that wrap the Msi APIs to correctly handle the user cancel case.
Related context:
- Search MSDN for ERROR_INSTALL_USEREXIT for the APIs that can return this error code
- Error Handling in Custom Actions
- Adding Custom Actions to the ProgressBar
- Custom Action Return Values
- Displayed Error Messages
- Logging of Action Return Values
Confirmation
Thanks, that suggestion worked, I put in code to trap return codes from MsiProcessMessage() in the custom actions and return the userexit error if MsiProcessMessage() returned IDCANCEL.
Content credit also belongs to
- Carolyn, MSI Team Dev Lead. You can get other Carolyn insights about developing for Windows Installer from the Windows Installer Chat Archives
- Rob, Microsoft Dev and WiX Lead. You can get other Rob insights about developing for Windows Installer from his blog when setup isn't just xcopy
[Author: Robert Flaming]
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at https://www.microsoft.com/info/cpyright.htm.