I am creating a new WIX installer. The installation is based on the customer's existing database. At the very first installation I have the information of the already installed features only in the database. So I have to query theese features from it and the installer shouldn't execute its activation scripts. Every feature has a property and from a custom action I set theese properties but the conditional SQL script execution is not working. I've created a sample wxs source file. Could you help me what is wrong with it?
<?xml version='1.0' encoding='UTF-8'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2006/wi' xmlns:util='http://schemas.microsoft.com/wix/UtilExtension' xmlns:sql='http://schemas.microsoft.com/wix/SqlExtension'>
<!-- https://wixtoolset.org/documentation/manual/v3/xsd/wix/product.html -->
<Product Id='BC075295-7BB8-4B82-89AC-3F81681130CC' Name='XXX' UpgradeCode='4AD0BCB8-B1BB-4FE1-ABEE-58E93321AAC5' Language='1033' Codepage='1252' Version='1.0.0' Manufacturer='XXX'>
<Package Id='*' Keywords='Installer' Description="XXX Installer" InstallerVersion='100' Languages='1033' Compressed='yes' SummaryCodepage='1252'/>
<Media Id='1' Cabinet='Andoc.cab' EmbedCab='yes' />
<Binary Id="WixCustomActions" SourceFile="CustomAction.CA.dll" />
<Binary Id="sqlScriptBinaryKey" SourceFile="insert.sql" />
<CustomAction Id="SetExecuteScriptCondition" BinaryKey="WixCustomActions" DllEntry="SetExecuteScriptCondition" Execute="immediate" Return="check" />
<Property Id="EXECUTE_SCRIPT" Value="NO" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALLDIR" Name="XXX" />
</Directory>
<Component Id="componentSqlScript" Directory="INSTALLDIR" Guid="1af938ef-6788-a0e1-2370-a6c2620c9dCC">
<Condition>EXECUTE_SCRIPT = "YES"</Condition>
<sql:SqlDatabase Id="db" Database="[DATABASE_NAME]" Server="[DATABASE_SERVER]" CreateOnInstall="yes" DropOnUninstall="no" ContinueOnError="no">
<sql:SqlScript Id="SqlScriptId" BinaryKey="sqlScriptBinaryKey" ExecuteOnInstall="yes" ExecuteOnUninstall="no" ContinueOnError="no" />
</sql:SqlDatabase>
<CreateFolder />
</Component>
<Feature Id="feature" Title="xxx" Description="xxx" ConfigurableDirectory="INSTALLDIR" Level="1">
<ComponentRef Id="componentSqlScript" />
</Feature>
<InstallExecuteSequence>
<Custom Action='SetExecuteScriptCondition' Before='InstallInitialize' />
</InstallExecuteSequence>
<UI>
<UIRef Id="WixUI_Mondo" />
</UI>
</Product>
</Wix>
My custom action looks like this.
[CustomAction]
public static ActionResult SetExecuteScriptCondition(Session session)
{
session["EXECUTE_SCRIPT"] = "YES";
return ActionResult.Success;
}
In the log I see that the EXECUTE_SCRIPT property value is 'YES' but the insert.sql script is not executed.
I've found a workaround to solve this problem by creating a subfeature to the sql component and moving the component condition to the feature level. And instead of InstallExecuteSequence I execute my custom action in InstallUISequence.
<Feature Id="feature" Title="xxx" Description="xxx" ConfigurableDirectory="INSTALLDIR" Level="1">
<Feature Id="feature_script" Title="script" Description="script" Display="hidden" Level="1" >
<Condition Level="0">EXECUTE_SCRIPT = "NO"</Condition>
<Condition Level="1">EXECUTE_SCRIPT = "YES"</Condition>
<ComponentRef Id="componentSqlScript" />
</Feature>
</Feature>
<InstallUISequence>
<Custom Action='SetExecuteScriptCondition' Before='LaunchConditions' />
</InstallUISequence>
InstallInitialize is too late, as the condition for your component 'componentSqlScript' is evaluated during costing. That's the reason setting that property didn't appear to work.
You need to schedule your action before 'CostInitialize', sequence it in both UI and Execute sequences (since the UI sequence doesn't necessarily run, and if costing is also preformed in the UI sequence then the execute sequence will be too late). You should add Execute="firstSequence" to your CustomAction element, and you should add Secure="yes" to your Property element, to prevent running code excessively and prevent issues where public property values aren't always set to the execute sequence.
Related
I'm using wix to create an installer for my application in Visual Studio.
I need a post-install executable run after install (which I've got working) and a pre-uninstall executable run before uninstallation.
All of these executables require elevated rights to run (my application, the post-install, and pre-uninstall).
I've scoured the web and stack overflow and found many posts related to this, but none of the solutions seem to work. Either the executables simply don't run, or, on uninstall I get error
There is a problem with this Windows Installer package. A program required for this install to complete could not be run. Contact your support personnel or package vendor.
Here is my Directory layout
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="ROOTDIRECTORY" Name="MyCompany" >
<Directory Id="FOLDERONE" Name="FolderOne" />
<Directory Id="UTILITYFOLDER" Name="Utility" />
</Directory>
</Directory>
</Directory>
</Fragment>
And a snippet of my File layout
<Fragment>
<DirectoryRef Id="UTILITYINSTALLFOLDER">
<Component Id="cmpPreInstallId" Guid="{56DC3D0A-E887-4A94-95B3-72825310DC5D}">
<File Id="filPreInstallId" KeyPath="yes" Source="path_to\PreUninstall.exe" />
</Component>
<Component Id="cmpPosUninstallId" Guid="{DE1DE45E-4D7C-4884-BA3E-EC078E265B7C}">
<File Id="filPostUninstallId" KeyPath="yes" Source="path_to\PostInstall.exe" />
</Component>
<!-- obviously there are other files/components -->
</DirectoryRef>
</Fragment>
<Fragment>
<ComponentGroup Id="UtilityPublishedComponents">
<ComponentRef Id="cmpPreInstallId" />
<ComponentRef Id="cmpPosUninstallId" />
</ComponentGroup>
</Fragment>
And in my Product.wxs
<Product ...>
<!-- The only way I found that actually worked to run the post install was -->
<UI>
<UIRef Id="WixUI_Minimal" />
<Publish Dialog="ExitDialog"
Control="Finish"
Event="DoAction"
Value="PostInstallExe">WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed</Publish>
</UI>
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOXTEXT" Value="Perform post-install operations." />
<Property Id="WIXUI_EXITDIALOGOPTIONALCHECKBOX" Value="1"/>
<Property Id="WixShellExecTarget" Value="[#filPostUninstallId]" />
<CustomAction Id="PostInstallExe"
BinaryKey="WixCA"
DllEntry="WixShellExec"
Impersonate="yes" />
<!-- this does not work to run the pre-uninstall -->
<CustomAction Id="EXECUTE_BEFORE_UNINSTALL"
Return="check"
Impersonate="yes"
Execute="immediate"
Directory="UTILITYINSTALLFOLDER"
ExeCommand="PreUninstall.exe" />
<InstallExecuteSequence>
<Custom Action="EXECUTE_BEFORE_UNINSTALL" Before="RemoveFiles">Installed AND NOT REINSTALL</Custom>
</InstallExecuteSequence>
<!-- other stuff plus the feature -->
</Product>
Anyone with experience see where this might be going wrong?
I've tried many variations of the CustomAction return, impersonate, execute, etc
Finally got it to work, so hopefully this helps someone.
Not sure what the issue was ... but here!
<!-- Setup post install operations -->
<CustomAction Id="PostInstall"
FileKey="key_to_post_install_exe"
ExeCommand=""
Execute="deferred"
Return="check"
Impersonate="no" />
<!-- Setup pre uninstall operations -->
<CustomAction Id="PreUninstall"
FileKey="key_to_pre_uninstall_exe"
ExeCommand=""
Execute="deferred"
Return="ignore"
Impersonate="no" />
<!-- Add pre and post install operations to the installer -->
<InstallExecuteSequence>
<Custom Action="PostInstall" Before="InstallFinalize">NOT Installed</Custom>
<Custom Action="PreUninstall" After="InstallInitialize">Installed</Custom>
</InstallExecuteSequence>
I am adding system variables and then i want to execute custom actions, that depends on those variables. The variables are being added correctly, but the scripts are exiting ( because at that time variables are not there yet ), depsite the fact I am using "After Install Files". Here is my code:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Id="*" Name="DataBaseds_Service_Installer" Language="1033" Version="1.0.0.0" Manufacturer="" UpgradeCode="3875ce89-3886-4cbf-b132-01f947ac7a08">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate EmbedCab="yes" />
<CustomAction Id="NssmUnzip" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="cmd.exe /c "unzip.exe nssm-2.24.zip -d "%TANGO_ROOT%\bin" "" Return="ignore" />
<CustomAction Id="Tango_db" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="[INSTALLFOLDER]create-tangodb.bat" Return="ignore" />
<CustomAction Id ="Baseds_Service" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="[INSTALLFOLDER]Tango-DataBaseds.bat" Return="ignore" />
<CustomAction Id="UninstallService" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="[INSTALLFOLDER]Remove_Baseds_Service.bat" Return="ignore" />
<InstallExecuteSequence>
<Custom Action="NssmUnzip" After="InstallFiles">NOT Installed</Custom>
<Custom Action="Tango_db" After="NssmUnzip">NOT Installed</Custom>
<Custom Action="Baseds_Service" After="Tango_db">NOT Installed</Custom>
<Custom Action="UninstallService" After="InstallInitialize"> Installed and Not REINSTALL</Custom>
</InstallExecuteSequence>
<Property Id="DIRR">
<RegistrySearch Id="aaa" Root="HKCU"
Key="Software\corp\Tango"
Name="Directory"
Type="directory"/>
</Property>
<Feature Id="ProductFeature" Title="DataBaseds_Service_Installer" Level="1">
<ComponentRef Id="MYSQL_Path"/>
<ComponentRef Id="MYSQL_USER"/>
<ComponentRef Id="MYSQL_PASSWORD"/>
<ComponentGroupRef Id="Components" />
</Feature>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="DataBaseds_Service_Installer" />
</Directory>
</Directory>
<ComponentGroup Id="Components" Directory="INSTALLFOLDER">
<Component Id="NSSM" Guid="54CEB76C-6974-4071-96E9-EF5AD1937BD4">
<File Source="nssm-2.24.zip" KeyPath="yes" />
<File Source="Tango-DataBaseds.bat" KeyPath="no"/>
<File Source="Remove_Baseds_Service.bat" KeyPath="no"/>
<File Source="create-tangodb.bat" KeyPath="no"/>
</Component>
<Component Id="unzip" Guid="E10EE17A-AA5A-416B-82DF-37532281116C">
<File Source="unzip.exe" KeyPath="yes"/>
</Component>
</ComponentGroup>
<DirectoryRef Id="TARGETDIR">
<Component Id="MYSQL_USER" Guid="D05C8155-8421-4AEB-9A19-5016DAFAED19">
<Environment Id="MYSQL_USER" Name="MYSQL_USER" Value="root" Permanent="no" Part="last" Action="set" System="yes" />
</Component>
<Component Id="MYSQL_PASSWORD" Guid="222C7887-1E4D-4DC2-B429-A3F18F707FA3">
<Environment Id="MYSQL_PASSWORD" Name="MYSQL_PASSWORD" Value="tango" Permanent="no" Part="last" Action="set" System="yes" />
</Component>
<Component Id="MYSQL_Path" Guid="34D14695-1803-4D7E-AD65-3C9011D019CE">
<Environment Id="PATH" Name="PATH" Value="[DIRR]bin" Permanent="no" Part="last" Action="set" System="yes" />
</Component>
</DirectoryRef>
</Product>
</Wix>
Am I doing something wrong?
Greetings
There are two general issues with environment variables in Windows Installer:
When they are set they don't just automatically show up for running programs because Windows Installer doesn't send the "environment variables have changed" broadcast message until the end of the install. If you run a program AFTER that it will pick up the new values.
There is no reason for any running processes to pick them up unless they have a message loop and are prepared to deal with the (I think) WM_WININICHANGE message and reload the environment.
So none of your custom actions are going to pick up the new variables because they haven't been broadcast to the system yet and "committed". And yes, it's better to find another way to pass the data to the programs.
Phil is not wrong.
But here is my solution, if anyone will ever have the same problem:
Even though as Phil says: "system variables are not set during an installation:
Windows Installer doesn't send the environment variables have changed broadcast message until the end of the install, they are stored inside variable ( "DIRR" in this example) when you are reading the registry:
<Property Id="DIRR">
<RegistrySearch Id="aaa" Root="HKCU"
Key="Software\corp\Tango"
Name="Directory"
Type="directory"/>
</Property>
So you can run a script and pass them as argument:
<CustomAction Id="Tango_db" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" ExeCommand="[INSTALLFOLDER]create-tangodb.bat ****"[DIRR]bin"****" Return="ignore" />
These way your batch file has access to the system variables, despite the fact that ther are not yet set in the system.
Hope that this helps :)
We've been using Wix to create our website msi for awhile and it install fine.
Issue (Little annoyance) -
If I install my msi, it will show up in add/remove programs but if Person B goes on the server, my msi entry will not show up for them in Add/Remove programs.
I'm assuming it's a property to set in the wix product.wxs page but google hasn't been friendly to me in that regard.
I wasn't sure if it was a win2k3 issue only but we just did a test on a win2k8R2 and the same issue occured.
Here's my product.wxs file
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">
<Product Id="*"
Name="!(loc.ProductName)"
Language="!(loc.LANG)"
Version="1.0.0.0"
Manufacturer="!(loc.CompanyName)"
UpgradeCode="1bf00ad4-a8a1-407b-8a07-0d3046cb7214">
<Package InstallerVersion="200" Compressed="yes" Manufacturer="!(loc.CompanyName)" Description="!(loc.Description)" />
<?include Settings.wxi ?>
<?include Conditions.wxi ?>
<?include WebSites.wxi ?>
<iis:WebAppPool Id="AppPool" Name="[APP_POOL_NAME]"/>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="IISMain" Name='WebSites'>
<Directory Id="WWWMain" Name='SigappsTest'
ComponentGuidGenerationSeed='5A8C3E4A-0AA2-488C-80EC-91921A1A36CC'>
<Directory Id='INSTALLLOCATION' Name='!(loc.VirtualDirectory)'>
<!-- The component to define the Virtual Directory.-->
<Component Id="WebVirtualDirComponent" Guid="8AD62CCC-3FD5-4121-8370-DFB466482E61">
<iis:WebVirtualDir Id="VDir" Alias="[VD]" Directory="INSTALLLOCATION" WebSite="SelectedWebSite">
<iis:WebApplication Id="MyWebAppApplication" WebAppPool="AppPool" Name="[VD]" />
</iis:WebVirtualDir>
<CreateFolder/>
<!-- Need to have to ensure created -->
</Component>
<Component Id="EnableASPNet4Extension" Permanent="yes" Guid="73FA6E54-2B0C-4AA7-A2A0-BDD432FECC62">
<CreateFolder/>
</Component>
<Component Id="PersistWebSiteValues" Guid="F249ADCB-B638-4E2B-9350-0421CEC5A803">
<RegistryKey Action="create" Root="HKLM" Key="SOFTWARE\!(loc.CompanyName)\!(loc.VirtualDirectory)\Install">
<RegistryValue Name="WebSiteDescription" Type="string" Value="[WEBSITE_DESCRIPTION]"/>
<RegistryValue Name="WebSiteID" Type="string" Value="[WEBSITE_ID]"/>
<RegistryValue Name="WebSitePath" Type="string" Value="[WEBSITE_PATH]"/>
<RegistryValue Name="WebSiteVD" Type="string" Value="[VD]"/>
<RegistryValue Name="WebSiteAppPoolName" Type="string" Value="[APP_POOL_NAME]"/>
</RegistryKey>
</Component>
</Directory>
</Directory>
</Directory>
</Directory>
<iis:WebSite Id='SelectedWebSite' Description='[WEBSITE_DESCRIPTION]' Directory='INSTALLLOCATION' SiteId='[WEBSITE_ID]'>
<!-- This element has to be here or WiX does not compile. -->
<iis:WebAddress Id="AllUnassigned" Port="80"/>
</iis:WebSite>
<!-- Define our custom actions -->
<Binary Id="IISCA" SourceFile="$(var.IISCA.TargetDir)$(var.IISCA.TargetName).CA.dll" />
<CustomAction Id="GetIISWebSites" BinaryKey="IISCA" DllEntry="GetWebSites" Execute="immediate" Return="check" />
<CustomAction Id="UpdatePropsWithSelectedWebSite" BinaryKey="IISCA" DllEntry="UpdatePropsWithSelectedWebSite" Execute="immediate" Return="check" />
<CustomAction Id="UpdateWebConfigFile" BinaryKey="IISCA" DllEntry="UpdateWebConfig" Execute="immediate" Return="check" />
<CustomAction Id="RegisterScriptMaps" BinaryKey="IISCA" DllEntry="RegisterScriptMaps" Execute="immediate" Return="check" />
<CustomAction Id="SetApplicationRootDirectory" Directory="INSTALLLOCATION" Value="[WEBSITE_PATH]\[VD]" />
<!-- Install UI Sequence - allows us to schedule custom action -->
<InstallUISequence>
<Custom Action="GetIISWebSites" After="CostFinalize" Overridable="yes">NOT Installed</Custom>
</InstallUISequence>
<InstallExecuteSequence>
<Custom Action="GetIISWebSites" After="CostFinalize" Overridable="yes">NOT Installed</Custom>
<Custom Action="UpdatePropsWithSelectedWebSite" After="GetIISWebSites">NOT Installed</Custom>
<Custom Action="SetApplicationRootDirectory" After="UpdatePropsWithSelectedWebSite">NOT Installed</Custom>
<Custom Action="UpdateWebConfigFile" After="InstallFinalize">NOT Installed</Custom>
<!--<Custom Action="UpdateWebAppMapping" After="InstallFinalize">NOT Installed</Custom>-->
<Custom Action="RegisterScriptMaps" After="InstallFinalize">NOT Installed</Custom>
</InstallExecuteSequence>
<Feature Id="ProductFeature" Title="!(loc.ProductName)" Level="1">
<ComponentRef Id='WebVirtualDirComponent' />
<ComponentRef Id='EnableASPNet4Extension'/>
<!--<ComponentGroupRef Id="WebSecurity.Web_Project" />-->
<ComponentGroupRef Id="Product.Generated" />
<ComponentRef Id="PersistWebSiteValues" />
</Feature>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLLOCATION"/>
<UIRef Id="WixUI_WebUI" />
</Product>
</Wix>
Set the Package/#InstallScope attribute to perMachine. The default in Windows Installer is to create per-user packages.
I have a super simple installer to test if a installer can write register entries under HKCU\Software\Classes\Wow6432Node (the msi is target x86 and I'm testing it on a Win7 x64 machine).
The problem is: it just does not want to write anything under Wow6432Node at all. Following is the code:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="f671ee4d-dd0a-4f7f-a4d1-1d181d2f3002" Name="TestWow" Language="1033" Version="1.0.0.0" Manufacturer="X" UpgradeCode="5d030587-0b6f-4a55-b090-c97a4fd22d13">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perUser" InstallPrivileges="limited"/>
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="XWix" Level="1">
<ComponentRef Id="TestWow" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir" />
</Fragment>
<Fragment>
<DirectoryRef Id="TARGETDIR">
<Component Id="TestWow" Guid="f671ee4d-dd0a-4f7f-a4d1-1d181d2f3002">
**<RegistryKey Root="HKCU" Key="Software\Classes\TestWow">
<RegistryValue Name="Test" Value="Wow" Type="string" KeyPath="yes"/>
</RegistryKey>**
</Component>
</DirectoryRef>
</Fragment>
</Wix>
I've even tried to modify the registry part like:
<RegistryKey Root="HKCU" Key="Software\Classes\Wow6432Node\TestWow">
<RegistryValue Name="Test" Value="Wow" Type="string" KeyPath="yes"/>
</RegistryKey>
It still does not work.
Your help is much appreciated!
I don't think hkcu is virtualised in the same way as hklm. You need to ensure your component is marked as a 32 bit one and any virtualization will be taken care of for you.
You can create this key using custom action. Dot NET Framework 4.0 has a special feature (RegistryView) to read the 64 bit registry from 32 bit applications. Refer this document for more information. You need to write another custom action to remove this key in uninstall.
Custom Action:
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
key = key.OpenSubKey(#"Software\Classes\Wow6432Node", true);
key.CreateSubKey("TestWow").SetValue("Test", "Wow", RegistryValueKind.String);
return ActionResult.Success;
}
WiX:
<Binary Id="TestWow" SourceFile="CustomAction\TestProject\TestProject\bin\Release\TestProject.CA.dll" />
<CustomAction Id="TESTWOW" BinaryKey="TestWow" DllEntry="CustomAction1" Return="check" />
<Custom Action="TESTWOW" After="InstallInitialize" >Not Installed</Custom>
How can I make a major upgrade to an installation set (MSI) built with WiX install into the same folder as the original installation?
The installation is correctly detected as an upgrade, but the directory selection screen is still shown and with the default value (not necessarily the current installation folder).
Do I have to do manual work like saving the installation folder in a registry key upon first installing and then read this key upon upgrade? If so, is there any example?
Or is there some easier way to achieve this in MSI or WiX?
As reference, I my current WiX file is below:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2003/01/wi">
<Product Id="a2298d1d-ba60-4c4d-92e3-a77413f54a53"
Name="MyCompany Integration Framework 1.0.0"
Language="1033"
Version="1.0.0"
Manufacturer="MyCompany"
UpgradeCode="9071eacc-9b5a-48e3-bb90-8064d2b2c45d">
<!-- Package information -->
<Package Keywords="Installer"
Id="e85e6190-1cd4-49f5-8924-9da5fcb8aee8"
Description="Installs MyCompany Integration Framework 1.0.0"
Comments="Installs MyCompany Integration Framework 1.0.0"
InstallerVersion="100"
Compressed="yes" />
<Upgrade Id='9071eacc-9b5a-48e3-bb90-8064d2b2c45d'>
<UpgradeVersion Property="PATCHFOUND"
OnlyDetect="no"
Minimum="0.0.1"
IncludeMinimum="yes"
Maximum="1.0.0"
IncludeMaximum="yes"/>
</Upgrade>
<!-- Useless but necessary... -->
<Media Id="1" Cabinet="MyCompany.cab" EmbedCab="yes" />
<!-- Precondition: .NET 2 must be installed -->
<Condition Message='This setup requires the .NET Framework 2 or higher.'>
<![CDATA[MsiNetAssemblySupport >= "2.0.50727"]]>
</Condition>
<Directory Id="TARGETDIR"
Name="SourceDir">
<Directory Id="MyCompany"
Name="MyCompany">
<Directory Id="INSTALLDIR"
Name="Integrat"
LongName="MyCompany Integration Framework">
<Component Id="MyCompanyDllComponent"
Guid="4f362043-03a0-472d-a84f-896522ce7d2b"
DiskId="1">
<File Id="MyCompanyIntegrationDll"
Name="IbIntegr.dll"
src="..\Build\MyCompany.Integration.dll"
Vital="yes"
LongName="MyCompany.Integration.dll" />
<File Id="MyCompanyServiceModelDll"
Name="IbSerMod.dll"
src="..\Build\MyCompany.ServiceModel.dll"
Vital="yes"
LongName="MyCompany.ServiceModel.dll" />
</Component>
<!-- More components -->
</Directory>
</Directory>
</Directory>
<Feature Id="MyCompanyProductFeature"
Title='MyCompany Integration Framework'
Description='The complete package'
Display='expand'
Level="1"
InstallDefault='local'
ConfigurableDirectory="INSTALLDIR">
<ComponentRef Id="MyCompanyDllComponent" />
</Feature>
<!-- Task scheduler application. It has to be used as a property -->
<Property Id="finaltaskexe"
Value="MyCompany.Integration.Host.exe" />
<Property Id="WIXUI_INSTALLDIR"
Value="INSTALLDIR" />
<InstallExecuteSequence>
<!-- command must be executed: MyCompany.Integration.Host.exe /INITIALCONFIG parameters.xml -->
<Custom Action='PropertyAssign'
After='InstallFinalize'>NOT Installed AND NOT PATCHFOUND</Custom>
<Custom Action='LaunchFile'
After='InstallFinalize'>NOT Installed AND NOT PATCHFOUND</Custom>
<RemoveExistingProducts Before='CostInitialize' />
</InstallExecuteSequence>
<!-- execute comand -->
<CustomAction Id='PropertyAssign'
Property='PathProperty'
Value='[INSTALLDIR][finaltaskexe]' />
<CustomAction Id='LaunchFile'
Property='PathProperty'
ExeCommand='/INITIALCONFIG "[INSTALLDIR]parameters.xml"'
Return='asyncNoWait' />
<!-- User interface information -->
<UIRef Id="WixUI_InstallDir" />
<UIRef Id="WixUI_ErrorProgressText" />
</Product>
</Wix>
There's an example in the WiX tutorial: https://www.firegiant.com/wix/tutorial/getting-started/where-to-install/
<Property Id="INSTALLDIR">
<RegistrySearch Id='AcmeFoobarRegistry' Type='raw'
Root='HKLM' Key='Software\Acme\Foobar 1.0' Name='InstallDir' />
</Property>
Of course, you've got to set the registry key as part of the install too. Stick this inside a component that's part of the original install:
<RegistryKey
Key="Software\Software\Acme\Foobar 1.0"
Root="HKLM">
<RegistryValue Id="FoobarRegInstallDir"
Type="string"
Name="InstallDir"
Value="[INSTALLDIR]" />
</RegistryKey>
'Registry' is deprecated. Now that part of code should look like this:
<RegistryKey Id="FoobarRegRoot"
Action="createAndRemoveOnUninstall"
Key="Software\Software\Acme\Foobar 1.0"
Root="HKLM">
<RegistryValue Id="FoobarRegInstallDir"
Type="string"
Name="InstallDir"
Value="[INSTALLDIR]" />
</RegistryKey>
You don't really need to separate RegistryKey from RegistryValue in a simple case like this. Also, using HKMU instead of HKLM takes care of it whether you're doing a machine or user install.
<RegistryValue
Root="HKMU"
Key="Software\[Manufacturer]\[ProductName]"
Name="InstallDir"
Type="string"
Value="[INSTALLDIR]"
KeyPath="yes" />