?
Solved

Delete a file during installation of an MSI package

Posted on 2009-04-17
11
Medium Priority
?
727 Views
Last Modified: 2013-11-14
I would like to be able to delete an arbitrary file from the disk from within an MSI package.  It needs to sequence *before* the uninstallation of the previous package.

As far as I understand at the moment, I would need to create a row in the *CustomAction* table, and the relevant entry in the *InstallExecute* table of the MSI.

In the *InstallExecute* table, I have sequenced this action just before the *RemoveExistingProducts* action.

In the *CustomAction* table, I have defined an action, but don't know what information to use for the 'Type', 'Source' and 'Target' columns.

Many thanks,
Steve
0
Comment
Question by:sda100
  • 6
  • 5
11 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 24168477
No need in custom action; create an entry in RemoveFile table. See http://msdn.microsoft.com/en-us/library/aa371201(VS.85).aspx, pick a component of your choice.
0
 
LVL 9

Author Comment

by:sda100
ID: 24171084
Thanks for the reply vadimrapp1,

It needs to be done after the installation checks and before the removal of any existing product (I think it's the presence of this file which prevents successful removal).  AFAIK the RemoveFile table is processed after installation: "The RemoveFiles action removes files previously installed by the  InstallFiles action".

Anyway, I had another idea... I've written a python 10-liner and converted it to an .EXE (20Kb).  I could configure this to run after the pre-install checks have succeeded and before the removal of the previous product.  I think I've cracked it - it's trying to run, but failing with the error:
 
Error 1722.There is a problem with this Windows Installer package. A program run as part of the setup did not finish as expected. Contact your support personnel or package vendor. Action delfileRun, location: C:\Documents and Settings\Administrator.TECHNOLOGY\Desktop\9.1 MSI\, command: C:\Documents and Settings\Administrator.TECHNOLOGY\Desktop\9.1 MSI\delfile.exe
 
 I'm sure it's just a minor setting I've missed somewhere.  Here's a quick description of my .MST and an image showing the transform table:
 
  1. Created [Feature] entry
  2. Created [Component] entry
  3. Created [FeatureComponents] entry and linked feature/component
  4. Created [File] entry and linked to component
  5. Created [Media] entry to copy CAB containing file
  6. Created [CustomAction] entry
  7. Created [InstallExecuteSequence] entry

 I've also uploaded the Acrobat Reader MSI (4Mb) and my MST (20Kb) files.
 
Any suggestions, most welcome!

 Many thanks,
 Steve
 
0
 
LVL 9

Author Comment

by:sda100
ID: 24171104
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 1500 total points
ID: 24171462
The action RemoveFiles happens when it's put in the script.

Usually, in the installation the order of action is like this:

1. check everything
2. remove everything that needs to be removed
3. install everything that needs to be installed

Regarding the upgrade - there are two major scenarios:
1. remove old version completely, then install new version
2. install new version, then remove the components of the old version not present in the new version.

The latter case is smarter and preferred, but it requires careful match of the components, so Installer could recognize which are present.

If your case is #2, then action Removefiles definitely occurs before it, nothing to worry about. If #1, all you need to do is move action RemoveFiles before RemoveExistingProducts - actually the same place where you put your custom action. You can even have RemoveFiles twice, nothing wrong here. Of course using standard action is much more reliable than custom.

Though not 100% sure, but the most likely reason for that error message is that your custom program did not return zero return code.
0
 
LVL 9

Author Comment

by:sda100
ID: 24210815
SOLVED.


My case was #1.

Because of an error in the installer of the previous package (thank Adobe for that!), I needed to remove a file before attempting to remove the previous package.

I tried various ways, but in the end the simplest method which worked was:

1.
Write batch file, convert to .EXE

2.
Add .EXE to [Binary] table in MST

3.
Configure a row in the [CustomAction] and [InstallExecuteSequence] tables to run .EXE at the correct point (ie. just before the 'RemoveExistingProducts' action).

4.
Make sure the transform (.MST) is applied as part of the installation.


Many thanks for your help,
Steve :)
0
 
LVL 9

Author Closing Comment

by:sda100
ID: 31571457
Although this wasn't the solution, it was helpful in guiding me to it eventually - thank you.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 24210924
I'm still curious, did you try putting the standard action RemoveFiles in the exact place where you have put your standard action, before RemoveExistingProducts?
0
 
LVL 9

Author Comment

by:sda100
ID: 24211016
Yes, but that only applies to files listed in the File table, so the files aren't yet copied over at that stage, and in any case - the File table contains files for *this* version of the product, not the one I'm trying to remove.

Steve :)
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 24211055
Not only. Please read the 2nd paragraph of Remarks of the article RemoveFiles Action .
0
 
LVL 9

Author Comment

by:sda100
ID: 24211623
Ok, I might just have to grant you that ;)

Just to twitter on a bit... using RemoveFile would involve creating a row in the File table, a new component (feature not required), and it would remove all files from the previous version, preventing it from uninstalling.

This way works, and is much easier.

It's nice to have a bit more knowledge of the RemoveFile table/actions though - thank you.

Steve :)
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 24211800
> , a new component

no, can be any existing component

> it would remove all files from the previous version, preventing it from uninstalling.

LOL. Looks like you still did not get how it works. OK.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question