Solved

WiX Installer copy files before uninstall previous version

Posted on 2013-12-09
7
1,965 Views
Last Modified: 2013-12-10
In the WiX installer, or just in a .msi file, is it possible to copy files before the program uninstalls the previous version?

The previous version has a database and user settings files. I want to copy those to a temp directory, then copy them to the installed directory after the installer installs the new version.

I currently have
      <MajorUpgrade
        Schedule="afterInstallInitialize"
        DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />

Open in new window

I could change the uninstall to later if that helps.

Should I use a custom action that runs a batch file or something, or can I do the copy within WiX using CopyFile, FileExists, stuff like that? Example?
0
Comment
Question by:deleyd
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39707335
Most likely you don't need to do anything. Read article "How Windows Installer handles file replacement logic for versioned and unversioned files" , especially the paragraph that begins with "In the case when both files are unversioned and have file hashes". In your case, if the user changed those files, their created time and modified time will be different, so they won't be replaced.
0
 

Author Comment

by:deleyd
ID: 39707568
Well in my case the MajorUpgrade uninstalls any previous version after InstallInitialize,before the installer actually installs new files, so the old files are already gone.

Plus we're changing the location where we install the files, so we're not installing on top of an old install, because the previous install is in a different location.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39707718
Then definitely custom action. Because the execution phase of your new installation will be running after the old version has already been uninstalled.
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:deleyd
ID: 39708467
I can't seem to execute a custom action, such as a .bat batch file, early on, before the uninstall. I'm guessing because the .bat batch file hasn't been installed yet.

The doc says if I schedule the uninstall after InstallExecute, then I need to have "strict adherence to the component rules." That's the phrase that I'm unsure of what they mean by that.

It's a simple install with only a couple dozen files. However the number of files does change. I have each file listed as a separate component. e.g.:
            <Component Id="C__DataAndLogic.dll" Guid="{4027F0C8-8A03-3B33-7B47-CC68F842EDB6}">
                <File Id="FILE_DataAndLogic.dll" Name="DataAndLogic.dll" KeyPath="yes"
                Assembly=".net" AssemblyManifest="FILE_DataAndLogic.dll" AssemblyApplication="FILE_DataAndLogic.dll" DiskId="1"
                  Source="..\binaries\DataAndLogic.dll" />
            </Component>

Open in new window

As long as I do that does that mean I'm adhering to the "component rules"?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39708484
> I can't seem to execute a custom action, such as a .bat batch file, early on, before the uninstall. I'm guessing because the .bat batch file hasn't been installed yet.

Right, no files. Can be .vbs or .js script, actions 5 / 6.

>  I need to have "strict adherence to the component rules." That's the phrase that I'm unsure of what they mean by that.

In a nutshell, don't add new files to the existing components. More in the section "Organize the installation of your application around components" of Windows Installer Best Practices.
0
 

Author Comment

by:deleyd
ID: 39708512
If I stick with the "one file per component" format, then am I following the "component rules"? (I recall somewhere reading the WiX developers went with "one file per component" for some reason.)
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 500 total points
ID: 39708548
>If I stick with the "one file per component" format, then am I following the "component rules"? (

Yes, you do.

>  WiX developers went with "one file per component" for some reason

Looking at the reasons (if this discussion reflects them accurately), I'd absolutely disagree. The desire to have full resiliency, provided by every file being the keypath of its component, will often result in Installer's attempts to self-repair, and these attempts practically always will be unneeded; further, the user probably won't have the installation source ready when self-repair requests it, so it all will be nothing but frustration. For that reason, I'd rather recommend to have components without the keypaths at all - those that can be changed by the application for sure, and also unversioned files.

WiX developers sure can have their own views, but I don't think that WiX itself enforces these practices in any way. You can build your installation the way you want.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
One of the most frequently asked questions on EE in the "Windows Installer" zone is how to eliminate self-triggered installation of some product.  The problem occurs when, suddenly, whenever a certain application is launched, or even when a folder i…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now