bobblez
bobblez

Reputation: 1370

How to get the installation directory (installed with MSI, created with VS2010) at a custom uninstall action?

So I've created a simple msi-setup for my application using a setup project and added a couple of custom actions that take care of stuff like extracting files from archives. Now, there are two extra files in my program files -directory which means that the MSI won't remove the directory at the uninstall by itself. My solution to this was to create a custom action that removes the rest of the files.

Now this works just fine and dandy, as long as the default directory is used at installation. But what if the user chooses to change it? I'd assume there has to be a very simple way to read the directory at the custom action, but I'm not quite sure what that is.

As far as I've found out by googling, there are properties such as TARGETDIR related to the MSI-package. However, some sites also say that I should be setting this property by myself, at the installation stage.

All this has left me quite confused. Basically I see two ways to resolve this:

1) Make sure the application does not create files by itself, and the MSI will take care of it. This would mean a bit more work because I'm not responsible for those extra files.

2) Find out the installation directory at the custom action while uninstalling the application, and remove the last bits by myself. This is the quick-and-dirty way as I see it, and would definitely suffice for now. But how to accomplish this?

Also while I'm here I might as well ask this one more related question. As I mentioned earlier, I extract some files at the install. Now, I'd like to get rid of these archives once I've extracted them. The problem is, if I do this, MSI will think my installation is broken and copy them back each time I launch the application. So how to avoid this?

Upvotes: 0

Views: 1373

Answers (1)

Ciprian
Ciprian

Reputation: 3565

There is no need to use a custom action to remove the files. MSI has built in support for this scenario in two steps:

  1. Use a search to locate the files you want to remove. Here is a tutorial http://msdn.microsoft.com/en-us/library/aa371564(VS.85).aspx

  2. Then you can schedule a file removal operation to actually delete the files. http://msdn.microsoft.com/en-us/library/aa371201(VS.85).aspx

Regarding your second question:

Don't add the archives to the File table. Instead create some self extracting archives and use binary custom actions to unpack them.

http://msdn.microsoft.com/en-us/library/aa368085(VS.85).aspx

Upvotes: 1

Related Questions