How does WiX IISMain get set? - wix

My installers use IISMain to install to the typicall IIS folder structure:
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="IISMain" Name="inetpub">
When there is only a C:\ drive, this installs to C:\inetpub\. However, we recently added an E:\ drive and created an Inetpub folder on it. We did not make any changes to the system beyond this - all we did was add the E:\ drive and use typical New Folder functionality to create the new Inetpub folder. However, my installers now install to the new E:\Inetpub\ folder.
While this is the desired functionality for the installer, I am confused as to how IISMain knows to point to the new folder instead of the original folder. How does the IISMain directory path get set?

TARGETDIR is a Windows Installer folder that will end up pointing to the root of the largest (most free space) drive on the machine. So if E:\ is larger than C:\ then TARGETDIR will be E:\.

Related

WiX: Change .msi Directory and CustomAction table with changes to be used by .msp Patch file

with the Wix Toolset v3.11 I have created a .msi file for my application (let's say version 1.1) with a Directory element that targets the LocalAppDataFolder and puts a Temp folder underneath. This structure is used with a DirectoryRef element to put some files there that are accessed within a custom action on InstallFinalize. Now I generated a Patch (version 1.2) that adds some files in the Temp folder. But I want that folder to be in the TARGETDIR now. So I changed
<Directory Id="LocalAppDataFolder">
<Directory Id="APPDATA_TEMP" Name="Temp" />
</Directory>
to
<Directory Id="MY_TEMP_PATH" Name=".">
<Directory Id="APPDATA_TEMP" Name="Temp" />
</Directory>
underneath the
<Directory Id="TARGETDIR" Name="SourceDir">
structure. For the Patch to be applied correctly I opened the .msi file that's referenced in the registry (under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\...\Products{GUID}\InstallProperties\LocalPackage) with the Orca tool and edited the corresponding values in the Directory table. I also edited the CustomActions table to reference the new path as it is used as a parameter there. So, now when I install the Patch it puts all the files (changed and new ones) in the LocalAppDataFolder as it did with the initial install. The custom action is called with the correct parameter though.
Is there a way to change the "base" msi to target my new Temp folder or, alternatively, somehow tell the Patch to use the new folder regardless of the initial path?
The goal is to apply the patch without having to uninstall the application first.
Any help on how to achieve that is greatly appreciated.
Finally we found a solution. So here's what solved our problem, should anyone ever come across something similar:
We found the actual path of the LocalAppDataFolder in two locations in the registry: The first entry is located in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\Folders. The second one is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData...\Components. The entry with the component ID that puts the files in the Temp folder holds exactly one value, which is the path to the first file in that component. We changed both paths to our new temp folder.
Now the patch extracts the files correctly to the new temp folder and the custom action can process them further.

Why does the TARGETDIR directory need a name? [duplicate]

This question already has answers here:
In WiX files, what does Name="SourceDir" refer to?
(3 answers)
Closed 6 years ago.
In wix projects you will generally see a line like
<Directory Id="TARGETDIR" name="SourceDir">
But why does the name need to be set here? From what I understand the name property specifies the name of the generated folder on the machine doing the installing. But no SourceDir folder will be created, so why is it needed?
UPDATE:
It turns out this question has been asked before. Check this post for an explanation from Wix creator Rob Mensching: In WiX files, what does Name="SourceDir" refer to?
TARGETDIR plays a special role in the resolution of an MSI file's Directory table. Specifically it forms the root of the source and target directory trees. This is indicated in the MSI file by the null value in the Directory_Parent column:
After directory resolution SourceDir will point to the path where the MSI is running from. Furthermore TARGETDIR will be the parent folder for most built-in Windows directories such as ProgramFilesFolder and ProgramMenuFolder as illustrated in the image above.
So in short SourceDir is defined to hold the location of the running MSI file, and this location is necessary to know in order to resolve the source locations on the distribution media for each file to install.
A target location is a full installation path for a file: C:\Program Files\My App (where the file is going). A source location is the full source path for a file: [SourceDir]Program Files\My App (where the file is coming from).
It is late, please let me know if this wasn't clear.

I have created an msi file which i ran from D drive, even though it is installing in the C drive only. how can i change the installation path?

As i have this in my wix application it should install the msi file from where it is running . like if i run from D drive it should take SourceDir as D , but it is taking as C only . how to change it to D drive ?
According to this, TARGETDIR will default to the commandline value (if specified), then the ROOTDRIVE (usually C:) then the drive with the largest amount of space available.
The directory you opened your msi from has absolutely no bearing on the value of TARGETDIR which roots your directory installation path. If you want to allow the user to change the installation path you can implement WixUI_InstallDir UI or, using it as an example, implement your own UI. You can also usually make the Install's root folder (Usually the name of the Company or Product itself) have a public ID so that it can be set in the command line. Alternatively you can create a custom action to read the value of SourceDir and force the TARGETDIR to use the root of the SourceDir path (where you launched the installer) however this is not recommended.
I did this by setting a parameter when I run the installation (My default installation drive was C but sometimes I want to install on D drive):
ReSecServer.msi /L*v log.log APPLICATIONROOTDIRECTORY="D:\Program Files (x86)\XServer"
Here is an example of my directories:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="APPLICATIONROOTDIRECTORY" Name="XServer">
</Directory>
</Directory>
</Directory>

How to give INSTALLDIR folder permission in WIX?

I am designing a WIX 3.6 installer project, during the installation we need to grand the user create file permission to the install folder(INSTALLDIR, especially with the default install folder, the Program Files, the user normally can't create file in the installation. We've experienced some failures). I guess it can be achieved by setting a Permission element, with CreateFile property. However, the INSTALLDIR is a directory, and only such elements as CreateFolder, File, FileShare, Registry, ServiceInstall can have permission element. So could anyone tell me how to do that? My directory declaration is something like this:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFiles64Folder">
<Directory Id='MANUFACTUREFOLDER' Name='$(var.ManufacturerName)'>
<Directory Id="INSTALLDIR" Name="$(var.ProductName)">
Thanks!
UPDATED:
Now I have managed to create a file (not the deployed file. But a generated file based on one deployed file, and it is generated in a custom action in commit phase). However, I now have a problem deleting the deployed file I just described (because there is no use of it after the other file is successfully generated). When the installation folder is Program Files, I can't delete it in the custom action. It says access denied.
Another thing is, I really don't understand the purpose of CreateFolder element. If its aim is to create a folder, as its name implies, don't nested Directory(s) do the same thing, as in my example code? And I think it is more clear to describe the folder structure there since it is very common to separate the Component elements (in which CreateFolder elements will reside) and the Directory elements. The Component will just use DirectoryReference to refer to the correct directory. Secondly, it is also common that multiple Components reside in the same Directory. So if I add a CreateFolder to one of those Components, with the default directory as the common parent directory of those Components, what does it even mean? It is really not intuitive of such a structure.
As you noted, CreateFolder elements may have Permission elements, and they default to the directory of the parent component if no directory is specified. So the structure would look something like the following.
<Directory Id="INSTALLDIR" Name="$(var.ProductName)">
<Component>
<CreateFolder>
<Permission>
</Permission>
</CreateFolder>
</Component>
</Directory>
However, based on Vista and Windows 7 restrictions and Windows Logo guidelines, I wouldn't be surprised if you still have issues with this, since the Program Files directory is pretty locked down. After install you should not be writing to this directory.

WIX Change Initial install directory

When I make my WIX Build setup,
by default it installs into the ProgramFIles directory.
I want to change this to the Application Local Data directory,
How would I do this?
Thanks
You can use folder definitions like this:
<Directory Id='LocalAppDataFolder'>
<Directory Id='MyAppFolder' Name='MyApp' />
</Directory>
To find the IDs of other system folders like LocalAppDataFolder, take a look at the System Folder Properties section of the Windows Installer Property reference.
Are you doing a per-user installation using the built in dialog sets?
If you set Package/#InstallScope="perUser" then the default installation folder will automatically be set to [LocalAppDataFolder]Apps\[ApplicationFolderName]
For more information refer to the WiX manual.