how to copy a file and then conditionally remove it - wix

(I'm newbe in Installer world so I'm still not sure what is right what is wrong. Anyway.)
I make a installer for service which uses desktop database. The database file should somehow be copied during first installation, be intact during upgrades and finally removed during uninstall.
As far I know, I can't add the database file as a directory component - 'cause installer will automatically remove it during uninstall. On the other hand, if I set the Persistent attribute, the database file will be NEVER removed by installer (even, if I will create separate component with RemoveFile element).
The above leads me to thinking, that I can't add the database file as directory's component.
So what are other options?
Is it possible to include a file into installer file (msi) and then copy the file with custom action to target folder?
Then deletion could be solved with RemoveFile element and condition base on UPGRADINGPRODUCTCODE property.
What do you think, guys?

If you are going to be using a custom action, why not create a custom action the will remove the file on uninstall. I have a custom action like that in a couple of my installers due to updates that happen to the target folder after the program has been running for a while. this just ensures a clean uninstall with no files laying around.

Related

Create file in installation folder using WiX custom action

I try to create a wix installer that has the need to create a file in the programme folder after Installation. For doing so, I have created a custom action, but I now have the following problem:
In order to write the file, I need to know the installation directory from session["INSTALLDIR"], which is only available if the action is executed "immediate".
However, if i run "immediate" after "install files", the target directory does not yet exist. If I run "deferred", it exists, but i cannot access session["INSTALLDIR"].
If I run "immediate" after "InstallFinalize", I can get the variable and the directory exists, but I am not elevated and hence not allowed to write the file.
What is the correct combination for writing a file to the installation directory?
You need to use CustomActionData to access property values from a deferred CA. You need something like this
or
another answer
Beyond using a built in extension for custom actions instead of writing your own, the next level would be how can I move complexity / custom actions out of the installer?
One thought is to write it to the registry instead. Another thought is for the application reading the value to be able to determine installation directory on it's own. One possibility is reflection to get the location another possibility is to query the MSI API for where the product is installed.

Upgrading doesn't update VirtualStore file

I haven an installer which must run with elevated admin rights if UAC is enabled. This works fine. When I upgrade the app (using the MajorUpgrade element) the app gets uninstalled and reinstalled correcly.
During runtime the app attempts to change some files in the program files folder which places copies them items in the users virtualstore. These do not get removed during uninstall.
During the upgrade/reinstall process, is there a correct way to delete the application file copies, for all users, in the VirtualStore?
Files placed into a virtual store are, by definition of who wrote them and when, per-user data files. Such files typically should not be removed during uninstallation. If the files in question are not actually per-user data files, the application that caused them to be written should be fixed to write to a proper location, update them in a controlled fashion, or even not write them at all.

How to use WIX CopyFile element to copy file on change/repair to a system folder without installing it to the target?

I have a problem which is related to the execution of CopyFile on change/repair when using WIX to make a msi setup.
I have a feature which has a component which copies/moves a file from the source folder to a folder already present somwhere inside a users system. It is not the folder of my application. I am only moving this file and not installing it to the the target. This feature works fine if I install it using a complete setup. But when on initial install I chose not to install this feature and then try to install it during a " change " all other custom actions/components inside the feature are executed/installed except for the CopyFile component. This is critical to my setup and if it does not get copied my setup will fail.
Just wondering if anyone found a solution to a similar problem or ever came across a similar issue?
The component which contains the CopyFile operation is configured incorrectly. It should have an actual file or registry entry as a key path.
Although Windows Installer uses components to manage resources, the component key path is main factor which decides if the component is installed or not.
So a component without a resource as a key path will never be installed and the CopyFile operation it contains will never be executed.

Windows Installer in XML

When uninstalling my app, I'd like to configure the WiX setup to remove directories and like user settings and user data I want add a dialog with two check boxes and optionally remove all the files that were added. It looks like the uninstaller removes only the directories and files that were originally installed from the MSI file .
In other words, I want to give user a chance to Delete his data with a dialog while uninstall is called ?
Is this possible through WiX without resorting to custom actions? Any help would be appreciated.
To do this without using custom actions, see the WiX documentation regarding the RemoveFile and RemoveFolder elements. You can use these to remove files and folders on uninstallation. RemoveFolder will only work if the folder is empty.
Note that if the files are located in the user's application data directory, you will only be able to do this for the user that is uninstalling the application. You cannot easily do it for all users.

Using WiX, how to install single file to (potentially) multiple sub-directories, based on what is available at install time?

I'm using WiX, and would like to know the .wxs necessary to take a file and install it to every available sub-directory of a particular location. This could mean 0 or more final installation locations, determined at install time based on the currently existing directory structure. For example, if I started the install with:
\target
\subdir-1
\subdir-2
Then at the end of the installation my file would be in \subdir-1 and \subdir-2. If on the other hand these directories did not exist on the system when the install was started, my file would not be installed at all and no sub directories would be created.
Afaik this is not possible with WiX (because it is basically against the nature of MSI to install a component into several locations).
You could either
create a different component for each subfolder, or
use a custom action to copy the component to all subfolders.
In the latter case you should also provide a corresponding CA for uninstallation which removes all the files from the subfolders again.
EDIT: Seems my above answer is not totally correct. MSI supports duplicating files using the DuplicateFile tables and WiX 3.0 also provides a mechanism called "smart cabbing". Both are mentioned in a blog post by Aaron Stebner.
Not without a custom action, you need to write a custom action that will do that.
The latest and greatest in custom actions is the DTF (and here) framework that comes with Wix3.
If you are targeting Vista (or Win2k8, not sure about Win2k3), you can use mklink.