Install a folder to ALLUSERS (not a shortcut!) using WiX - wix

I have an MSI file that is installing a folder with a bunch of files inside it. I have a location that I am putting the files in:
Windows XP:
C:\Documents and Settings\All Users\Documents\MyFolder
Windows 7:
C:\Users\Public\Documents\MyFolder
The issue is that I do not want to hardcode these paths, but no matter where I look I cannot find out how to do this, because everywhere I look they are talking about making shortcuts for all users and that is not what I am trying to do. How can one install a folder to an "All Users" location?
Something like this:
<PropertyRef Id="WIX_DIR_COMMON_DOCUMENTS" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="WIX_DIR_COMMON_DOCUMENTS">
<Directory Id="MyFolder" Name="MyFolder">

Windows Installer does not have a property for that folder, but a WiX-provided custom action does.
Per the documentation on the OSInfo custom actions:
Reference the WixUtilExtension extension for the linker.
Define the property via a reference:
<PropertyRef Id="WIX_DIR_COMMON_DOCUMENTS" />
Then, define the directory somewhere under the TARGETDIR directory. For example:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="WIX_DIR_COMMON_DOCUMENTS">`
<Directory Id="MyFolder" Name="MyFolder" />`
</Directory>`
</Directory>`

Related

WiX Install on a different drive to the standard ProgramFilesFolder name

I'm using what appears to be the standard XML for a WiX install. Generally things work like expected for the defaults.
Sometimes I would like to install on another drive but, use the standard directory. What seems to be right idea is to specify TARGETDIR=D: on the msi command line:
nonsenseInstaller.msi TARGETDIR=D: /log=Install.log
Typically ProgramFilesFolder is set to: C:\Program Files (x86)\
Below is my WiX XML, pretty standard stuff. What is happening is that ProgramFilesFolder already has C: baked in. Is there a standard WiX way to override this with TARGETDIR? (Or another command line property?)
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='ProgramFilesFolder' Name='PFiles'>
<Directory Id='Draeger' Name='Dyer Heavy Industries'>
<Directory Id='APPLICATIONROOTDIRECTORY' Name='Build Tools'></Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="New Build Email"/>
</Directory>
</Directory>
<Directory Id="FontsFolder" SourceName="Fonts Folder"></Directory>
</Directory>
In this case you'd want to say msiexec intaller.msi APPLICATIONROOTDIRECTORY=D:\SomePath
I do see a couple problems with your XML though. ProgramMenuFolder should be a child of TARGETDIR not ProgramFilesFolder. Also APPLICATIONROOTFOLDER should typically be called INSTALLLOCATION to match most WiX convention.

How can I create a folder (at Runtime) during installation via msiexec.exe?

I am deploying one MSI via msiexec.exe, but when I specify the path=D:\folder_name, the folder is not created.
Code:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLDIR" Name="bin" />
</Directory>
</Fragment>
From the above code, I can achieve folder "bin" but I want that "bin" should go into the folder which will get created via msiexec.exe i.e
msiexec.exe /i /path/to/msi /quiet PATH=Drive/Folder_name
Can we have a workaround so that if the folder is not present then it should create it and should put the "bin" in that folder?
You need to specify the TARGETDIR and not PATH. Try the following:
msiexec.exe /i /path/to/msi TARGETDIR="DRIVE/Folder_name" /qb
It's not clear what you're asking because:
Why is PATH in your msiexec command line? If you want to specify the actual directory you should perhaps be using INSTALLDIR=....
The Directory element seems incomplete. Typically you'd have something like:
Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="MyName">
<Directory Id="MYDIR" Name="Fred" />
</Directory>
</Directory>
</Directory>
and use INSTALLDIR in the command line to specify the name within ProgramFiles or TARGETDIR to customize the entire path, or MYDIR to change the name "Fred".
To get to the question: a folder is created by specifying that files will be installed there. Maybe more of your source would show that.
If you want to create an empty directory it's done with a CreateFolder element inside a component, as here in the WiX docs:
Creating an empty folder
This is not in your question, but silent installs that require elevation will fail because silent means that the UAC elevation prompt will not be shown, and the install will proceed with limited privileges and fail.

Program Files folder instead of Program Files (x86) installation path in wix

I am making a Windows installer and I am using the following directory structure for the installation path:
<Directory Id="ProgramFilesFolder">
<Directory Id="Company" Name="CompanyName">
<Directory Id="INSTALLFOLDER" Name="ProductName" />
</Directory>
</Directory>
The above code snippet will install my app in the "Program Files (x86)" folder. My application only runs on a 64 bit version of Windows so I would like to install it in the Program Files folder instead. How can I do this?
Use ProgramFiles64Folder instead of ProgramFilesFolder.
Besides that, set:
Product/Package/#Platform="x64"
Product/Package/#InstallerVersion to at least 200
Component/#Win64="yes"
For .NET assemblies:
File/#ProcessorArchitecture="x64"

How to create a folder in the windows folder using wix 3.8 installer

I need to install file in the regular installation folder (i.e. c:\program files\mycompany\myapp) but I also need to copy files into a subfolder located in the windows folder i.e. c:\windows\myfolder.
While I have no problem with the "install" folder, I can't see how to create a sub-folder in c:\windows?
Any ideas?
Thanks.
Thierry
UPDATE:
I probably should have been a bit more precise and provide additional information. This is the xml I have:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MyCompany">
<Directory Id="ClientFolder" Name="Client">
</Directory>
<Directory Id="ServerFolder" Name="Server">
</Directory>
</Directory>
</Directory>
</Directory>
<Directory Id="WindowsFolder" Name="WindowsFolder">
<Directory Id="MyFolder" Name="MyFolder"></Directory>
</Directory>
</Fragment>
When I try to compile my wix project, I get the following error:
Error 1 : The Directory with Id 'WindowsFolder' is not a valid root directory.
There may only be a single root directory per product or module and its Id attribute
value must be 'TARGETDIR' and its Name attribute value must be 'SourceDir'
PS: I'm new to this and I'm reading a book on how to use Wix, but I need this asap, so please be patient with me :). Thank you.
You create Directory elements based on System Folder Properties. Specifically the WindowsFolder property. Then create a child Directory element for your folder.
You should have very strong justification before doing this as this is an operating system area. I typically tell developers no unless they have a very, very good reason.
The penny dropped!!
You need to add a directory reference directly under
<Directory Id="TARGETDIR" Name="SourceDir">
along with the rest of your directories. You'll end up with something like this
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MyApp">
<Directory Id="ClientFolder" Name="Client"/>
</Directory>
</Directory>
<Directory Id="WindowsFolder">
<Directory Id="MyFolder" Name="MyFolder"/>
</Directory>
</Directory>
Where the WindowsFolder will tell the installer to use the "windows" folder and to use the sub folder within it, just set the Directory your ComponentGroup (or other) to MyFolder i.e.
<ComponentGroup Id="MyFolderComponents" Directory="MyFolder">
..
..
</ComponentGroup>
That regular installation folder of yours is based on a tree that will have ProgramFilesFolder somewhere, and then your subfolder name. You do the same for the Windows folder using the standard Windows Installer property:
Windows Folder
which is one of this bunch:
Property Reference

Wix - Setting Install Folder correctly

I'm creating a program which is being installed by Wix, using VS 2010 and I've already got the product.wxs ready.
In my wxs file, I've got directory definitions which looks like this:
<SetDirectory Id="INSTALLFOLDER" Value="[WindowsVolume]Myapp" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLFOLDER" Name="Myapp">
<Directory Id="Myapp_Installer_Dir" Name="Myapp">
<Directory Id="BIN" Name="Bin" />
<Directory Id="ICONS" Name="Icons" />
</Directory>
</Directory>
</Directory>
And then I got these file installation definitions:
<DirectoryRef Id="Myapp_Installer_Dir">
<Component Id="INSTALLER_Myapp" Guid="{94F18477-8562-4004-BC6F-5629CC19E4CB}" >
<File Source="$(var.Myapp.TargetPath)" KeyPath="yes"/>
</Component>
</DirectoryRef>
<DirectoryRef Id="BIN">
<Component Id="INSTALLER_Data" Guid="{545FB5DD-8A52-44D7-898E-7316E70A93F5}" >
<File Source="$(var.Data.TargetPath)" KeyPath="yes"/>
</Component>
...
And it continues in that manner. The files for the "ICONS" directory are defined as well.
I am also using the WixUI_InstallDir dialog set and I got these lines present as well:
<Property Id="WIXUI_INSTALLDIR" Value="Myapp_Installer_Dir" />
<UIRef Id="WixUI_InstallDir" />
The problem is when the user installs the program and changes the value of the installation folder, the files of the "Bin" and "Icons" are installed to their correct path, but the Myapp target is installed to a fix location which was defined at the start as the default installation path.
Why do only the bin and icon files installed to the correct folder the user wanted, but the myapp target does not?
I have finally figured out the problem.
After searching for a while, I came across this document:
WixUI_InstallDir Dialog Set
The relevant part: "The directory ID must be all uppercase characters because it must be passed from the UI to the execute sequence to take effect."
And as you can see in my code: "Myapp_Installer_Dir" does not meet this criteria.
After changing it to "MYAPPINSTALLERDIR", everything worked.
I'm not quite sure, but this is what I think has happened.
When you author a SetDirectory element, you basically add a custom action which sets a directory to the MSI database. As long as you do not specify the sequence it is executed in, it defaults to both, which means execute in both InstallUISequence and InstallExecuteSequence.
Now, when a user changes the installation directory in the wizard, this happens in the UI sequence. Obviously, when the installation enters the execute sequence, the value of INSTALLFOLDER is set to [WindowsVolume]Myapp as it was instructed.
So, you have to rework this somehow. Keep in mind the silent installation as well - there's only execute sequence there.
UPDATE instead of what you have, try something like this:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="WindowsVolume">
<Directory Id="INSTALLFOLDER" Name="Myapp">
<Directory Id="BIN" Name="Bin" />
<Directory Id="ICONS" Name="Icons" />
</Directory>
</Directory>
</Directory>
And let the user optionally change the INSTALLFOLDER as you do now.
Additionally to the pitfall with capital letters there is also an other one:
You have to mark the ID of the changeable directory as secure. (At least when the setup runs with admin rights.)
Related to Yonatan's answer with the directory ID MYAPPINSTALLERDIR you have to add this:
<Property Id="MYAPPINSTALLERDIR" Secure="yes" />
Related to the example WixUI_InstallDir in the WiX documentation you have to add this:
<Property Id="TESTFILEPRODUCTDIR" Secure="yes" />
Unfortunately this important fact is not mentioned in the WiX example.