Accessing directory property in Custom Action Wix - wix

I have a WIX installation I am attempting to run, which has a custom action which creates some .INI files based on user input, and is supposed to put them in a subfolder of the user's chosen installation folder. I am attempting to pass the WIXUI_INSTALLDIR property to the C# Custom Action file, but this just passes its value of INSTALLFOLDER, instead of INSTALLFOLDER's Path. Does anyone have advice on how to do this?

Related

WIX installer: Use property value to place a file

I've read a property from the registry, and that property has been set properly (I'm using this to check the property value)
<CustomAction Id="Test" Script="vbscript">
<![CDATA[MsgBox Session.Property("MYEXTRAFILESFOLDER")]]>
</CustomAction>
Now I'm just trying to drop a few files into that folder. I can't figure out how to make a File element target a specific directory.
As I get you don't need to change taget path in general but only put some files to specific folder. Easiest way is to create custom action.
Add custom action as described
In InstallExecuteSequence set After=InstallFiles or After=InstallFinalize (to make sure that your files from installer will be copied already)
In custom action read you path from registry
Get you install path using TARGETDIR
Move files from TargetDir to your registry dir
Another option is
Create custom action as described
In custom action read you path from registry
Get file stream from installer and write it to folder
Also this can be an option too. But I don't know how it works exactly

WixSharp Windows Forms UI: Passing instalation directory from Form to Wix

I am working on a WixSharp windows forms application that lets the user choose an install directory and install some files at that location. Right now I don't know how to pass the installation directory path (stored as a string) selected by the user in the form to the "wix side of things" so that the files would go to the desired location. My project is based on the ("Samples\Custom_UI\EmbeddedUI"), if you are familiar with the files.
have you tied adding a property to your project for INSTALLDIR like:
new Project("App101",
new Property("INSTALLDIR", "C:\App101"),
new Dir(new Id("INSTALLDIR"), new Files( ....
then in your class that calls 'StartInstall', have a property 'DestinationFolder' that is bound to the UI, then you StartInstall command will look like:
base.StartInstall($"CUSTOM_UI=true ADDLOCAL=FeatureA,FeatureB INSTALLDIR=\"{DestinationFolder}\"");
which passes the UI DestinationFolder to the MSI as a property.

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.

WiX - validating a path that is not the installation directory?

As part of my WiX-based installation, I need to ask the user to enter the value for a property, JAVA_LOC, which I'm going to store as a registry value (it is NOT a directory I want to create on the install.) However, if I use the Publish Event="SetTargetPath", the linker says that I must declare JAVA_LOC as a directory in the component hierarchy. If I do that, things I can record the path okay. However, it turns out that if I run a 'Change' install afterward, the new path value is ignored, and JAVA_LOC is reset to the location of the JAVA_LOC directory I was forced to create.
How does one validate a path the user has entered that isn't for the install
directory? Remember, I'm just trying to store it in the registry, not really create a dir for it.
Dave
The SetTargetPath control event can only take a primary key from the Directory table as an argument. You would have to define the directory to be able to use this. Nothing says that the dirctory has to have a CreateFolder entry and/or any File resources. I'd think you could nest your component with the registry data under this directory and it should all work without creating the directory.

In WiX, how would you create a dialog to choose the name of a subfolder of the main application directory?

I am developing an MSI installer by using WiX.
The main program installs to [APPLICATIONFOLDER]. I use the InstallDirDlg to set the directory of this without any issues.
I'd like to display a custom dialogue based on the InstallDirDlg to specify a directory to install a particular component. I'd like to set the default directory to [APPLICATIONFOLDER]\Resources. However when I run the installer, I get an error, code 2343.
I think this may be a problem with displaying a second level folder in the dialogue.
You could take a look at how this is done in the WixUI FeatureTree UI example. In particular, look at the CustomizeDlg.
The error 2343 means "Specified path is empty.", so you have probably set a property incorrectly. Looking at the log files generated by your installer may also help.