Write to registry if parameter is specified - wix

I have a setup that has an optional parameter which should be written to the registry is supplied. I know that i can write to the registry using this:
<DirectoryRef Id="TARGETDIR">
<Component Id="RegistryEntries" Guid="*">
<RegistryKey Root="HKCU"
Key="Software\Microsoft\Test"
Action="create">
<RegistryValue Type="string" Value="[THEPARAMETER]"/>
</RegistryKey>
</Component>
</DirectoryRef>
But this will override the existing registry entry with an emtpy string, if the parameter is not specified!
I would like to know how to set the registry key ONLY if the parameter is specified. I have looked into custom actions and WriteRegistryValues, but I haven't found anything helpful.

Add the condition like this
<Condition>(THEPARAMETER AND (NOT Installed))</Condition>
<RegistryValue Type="string" Value="[THEPARAMETER]"/>

Related

WIX registry key entry fails using Auto Generated GUID

Im using WIX 3.11.2 and when adding a registry key I get the following error:
“The Component/#Guid attribute's value '' is not valid for this component because it does not meet the criteria for having an automatically generated guid”*
I have created a ‘.wxs’ file which contains the following code that is failing:
<Fragment>
<ComponentGroup Id="myComponentGroup" Directory="TARGETDIR">
<Component Id="cmpRegUrlHandler" Guid="*">
<RegistryKey Root="HKCR" Key="HKEY_CLASSES_ROOT\myAppName\shell\open\command">
<RegistryValue Value="C:\Program Files\\myCompanyName\myProductName" KeyPath="yes" />
</RegistryKey>
</Component>
</ComponentGroup>
I run it using candel.exe/light.exe. However, light.exe gives me the above error.
Any help on this would be much appreciated.
You can't use Guid="*" for a component that has only a RegistryKey. You need to give it a real guid.

Changing registry entry set by WiX

I'm new to WiX. I need to change the following registry-setting element:
<Component Id="BrowserEmulation" Directory="ApplicationProgramsFolder" Guid="*">
<RegistryValue Root="HKCU" Key="Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION" Name="MY_REG_ENTRY" Value="11000" Type="integer" KeyPath="yes"/>
</Component>
So that the registry entry gets installed under HKEY_LOCAL_MACHINE instead of HKEY_CURRENT_USER. I tried changing the Root value and the Key value:
<Component Id="BrowserEmulation" Directory="ApplicationProgramsFolder" Guid="*">
<RegistryValue Root="HKLM" Key="SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION" Name="MY_REG_ENTRY" Value="11000" Type="integer" KeyPath="yes"/>
</Component>
I also tried removing the KeyPath component. But when I try to build the .msi I get the following error:
error LGHT0204: ICE38: Component Browser Emulation installs to user
profile. It's KeyPath registry key must fall under HKCU
I looked at the WiX docs that describe Component KeyPaths but wasn't able to figure out how to get around this.
Directory: Looks like you need to take out the Directory attribute from your component. Maybe try something like this:
<Component Feature="MainApplication">
<RegistryValue Root="HKLM" Key="SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION" Name="MY_REG_ENTRY" Value="11000" Type="integer" KeyPath="yes"/>
</Component>
Bitness: Also be aware of the issue with 32-bit and 64-bit registry hives in HKLM: HKLM\SOFTWARE\WOW6432Node etc... Please see this answer for more details. I have inlined the most important part:
Registry:
64-Bit: HKEY_LOCAL_MACHINE\SOFTWARE
32-Bit: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node
64-Bit: Maybe what you need is to mark your component as a 64-bit component? In order to write under HKEY_LOCAL_MACHINE\SOFTWARE?:
<Component Feature="MainApplication" Win64="yes">
<RegistryValue Root="HKLM" Key="SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION" Name="MY_REG_ENTRY" Value="11000" Type="integer" KeyPath="yes"/>
</Component>

Wix tools Ignore registry fail and continue

I need to insert a registry key in wix but the result is not important
how can I Ignore error.
sometimes because of permission reg creation fails
<Component Id="EXTEND_ADVANCE_TEXT_SERVICE" Guid="*">
<RegistryKey Root="HKLM" Key="SOFTWARE\Microsoft\CTF\SystemShared" Action="createAndRemoveOnUninstall">
<RegistryValue Type="integer" Name="CUAS" Value="1" KeyPath="yes"/>
</RegistryKey>
<Condition><![CDATA[VersionNT >= 501 AND VersionNT <= 502]]></Condition>
</Component>
The RegistryKey element does not have any error handling. Use a custom action and ignore the return code. There are plenty ways to do this, you can either author one in code or use a quiet execution custom action.

Windows Installer not deleting all files on uninstall

I've seen some similar questions asked on here, but none of the solutions given were very clear or worked for me.
I have an installer (created with WiX) which installs certain files and folders. However, when running the installed application, this creates some folders and copies some files into it. These files and folders are not removed on uninstall.
Edited to Show Code so Far:
This INSTALLDIR property:
<Property Id="INSTALLDIR">
<RegistrySearch Id='Registry' Type='raw' Root='HKLM' Key='Software\$(var.Manufacturer)\$(var.ProductName)' Name='Location' />
</Property>
This Component which should set the install location in the registry:
<Component Id="Registry" Guid="*">
<RegistryKey Root="HKMU" Key="Software\$(var.Manufacturer)\$(var.ProductName)">
<RegistryValue Name="Location"
Type="string"
Value="[INSTALLDIR]"
Action="write"
KeyPath="yes" />
</RegistryKey>
<util:RemoveFolderEx On="uninstall" Property="INSTALLDIR" />
</Component>
This does create a record in the registry with the install location, but I'm not sure how to adapt this code to making note of the 'public' directory and removing it - I don't know where the util:RemoveFolderEx should go either (inside which component)
The clearest tutorial I've seen is this one (except that it does have an apparent error).
Replace this block:
<!--
RemoveFolderEx requires that we "remember" the path for uninstall.
Read the path value and set the APPLICATIONFOLDER property with the value.
-->
<Property Id="APPLICATIONFOLDER">
<RegistrySearch Key="SOFTWARE\$(var.Manufacturer)\$(var.SkuName)" Root="HKLM" Type="raw" Id="APPLICATIONFOLDER_REGSEARCH" Name="Path" />
</Property>
with this one:
<!--
RemoveFolderEx requires that we "remember" the path for uninstall.
Read the path value and set the FOLDERTOREMOVE property with the value.
-->
<Property Id="FOLDERTOREMOVE">
<RegistrySearch Key="SOFTWARE\$(var.Manufacturer)\$(var.SkuName)" Root="HKLM" Type="raw" Id="APPLICATIONFOLDER_REGSEARCH" Name="Path" />
</Property>
and this block:
<util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER" />
with this one:
<util:RemoveFolderEx On="uninstall" Property="FOLDERTOREMOVE" />
and you should have a working test.
The reason for using two different properties is given here and here (among with other places).
If you can derive the path from other values you may have set during installation that Windows Installer will preserve for you, such as ARPINSTALLLOCATION, then you can adjust the above implementation to get what you need without having to create your own registry keys.
Builds on B. Murri's answer:
Example: your application installs new files or folders in 'installdir/public'. These files aren't being deleted as they weren't added by the installer.
First, you need to create a registry value which will store where your public directory is installed. This is in case the user changes the install directory.
<!-- Note that the RegistryValue Value is being set to the 'public' directory ID -->
<DirectoryRef Id='INSTALLDIR'>
<Component Id="RemovePublicDir" Guid="your-guid-here">
<RegistryKey Root="HKCU" Key="Software\$(var.Manufacturer)\$(var.ProductName)">
<RegistryValue Name="Location"
Type="string"
Value="[PUBLIC]"
Action="write"
KeyPath="yes" />
</RegistryKey>
<CreateFolder Directory="PUBLIC"/>
<util:RemoveFolderEx Property="FINDPUBLICDIR" On="uninstall"/>
<RemoveFolder Id="PUBLIC" On="uninstall"/>
</Component>
</DirectoryRef>
You now need to add a property which will search for this registry value later on. Make sure your Root value above matches the one below:
<Property Id="FINDPUBLICDIR">
<RegistrySearch Id='Registry' Type='raw' Root='HKCU' Key='Software\$(var.Manufacturer)\$(var.ProductName)' Name='Location' />
</Property>
Add your manufacturer name and product name to variables, like this:
<?define Manufacturer = "My Company"?>
<?define ProductName = "Test Application"?>
Now make sure you call this Component in your Feature tag:
<Feature Id="FeatureId">
<ComponentRef Id="RemovePublicDir" />
</Feature>

Wix - Get user input to create a registry entry

I need to create an installer that gets the user input to create a registry entry. I've looked into Wix tutorials and it's very clear how to install registry entries but I need the user to give some info(in this case it's an url) so that url can be used on the registry entry.
How can I do this?
Duplicate question!?
Please take a look at this answer if it helps: https://stackoverflow.com/a/20679626/1331719
Edit - slightly modifying the answer found in the link:
Start by adding this component, notice the property in Value [USERINPUT]
<DirectoryRef Id="INSTALLDIR">
<Component Id="RegistryEntries" Guid="{YOURGUID}">
<RegistryKey Root="HKLM" Key="Software\Company123\App123" Action="create">
<RegistryValue Type="string" Name="UserInput" Value="[USERINPUT]" />
</RegistryKey>
</Component>
</DirectoryRef>
Reference the component in your feature:
<Feature>
<ComponentRef Id="RegistryEntries" />
...
</Feature>
Get user input when you install using msiexec:
msiexec /i your.msi /qb+ USERINPUT="http://urlYouWantToStoreIn.Registry"
Check registry HKLM\Software\Company123\App123\UserInput, the url should be there.