4

I've been following the advice in this question.

How to add a WiX custom action that happens only on uninstall (via MSI)?

I have an executable running as a custom action after InstallFinalize which I intend to purge all my files and folders. I was just going to write some standard deletion logic but I'm stuck on the point that Rob Mensching made that the windows installer should handle this incase someone bails midway through an uninstallation.

"create a CustomAction that adds temporary rows to the RemoveFiles table"

I'm looking for some more information on this. I'm not really sure how to achieve this in c++ and my searching hasn't turned up a whole lot.

http://msdn.microsoft.com/en-us/library/windows/desktop/aa371201(v=vs.85).aspx

Thanks Neil


EDIT: I've marked the answer due to the question being specific about how to add files to the removeFiles table in c++ however I'm inclined to agree that the better solution is to use the RemoveFolderEx functionality in wix even though it is currently in beta (3.6 I think)

Community
  • 1
  • 1
Neil
  • 5,179
  • 8
  • 48
  • 87

2 Answers2

3

Roughly you will have to use the following functions in this order:

  • MsiDatabaseOpenView - the (input) handle is the one you get inside your custom action functions
  • MsiCreateRecord - to create a record with the SQL stuff inside
    • MsiRecord* - set of functions to prepare the record
  • MsiViewExecute to insert the new record into whatever table you please ...
  • MsiCloseHandle - with the handle from the very first step and the record handle (from MsiCreateRecord)

Everything is explained in detail over at MSDN. However, pay special attention to the section "Functions Not for Use in Custom Actions".

The documentation of MsiViewExecute also explains how the SQL queries should look. To get a feel for them you may want to use one of the .vbs scripts that are part of the Windows Installer SDK.

0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
3

If you use WiX to create your installation package, consider using RemoveFolderEx element. It does what you want and you don't have to write the code yourself.

Read Tactical directory nukes for an example of how to use it.


If you still want to implement it yourself, you can get your inspiration from this blog post, there's the code for doing this in VBScript.

Alexey Ivanov
  • 11,541
  • 4
  • 39
  • 68
  • 2
    +1, I didn't know RemoveFolderEx is in the toolset already. That's nice! @Neil, I would strongly recommend you using this approach - it will anyway be better and safer than any custom action. – Yan Sklyarenko Nov 22 '11 at 14:04