How can I remove a RegistryValue on uninstall without removing the parent RegistryKey with WIX? - wix

If I use the follow code then nothing is removed on uninstall.
<DirectoryRef Id="INSTALLDIR">
<Component Guid="xyz" Id="instance_path" MultiInstance="yes">
<RegistryKey ForceCreateOnInstall="yes" Id="instance_path_reg" Key="Software\i-net software GmbH\i-net Test\Instances" Root="HKLM">
<RegistryValue Name="[INSTANCE_NUMBER]" Type="string" Value="[INSTALLDIR]"/>
</RegistryKey>
</Component>
</DirectoryRef>
If I replace ForceCreateOnInstall="yes" with ForceDeleteOnUninstall="yes" then all is removed on uninstall.
But I want only remove the RegistryValue of this instance. The values of other instances should not removed.

You could try using the RemoveRegistryValue and leave your current entries. It is a little messy but should get the job done.
http://wixtoolset.org/documentation/manual/v3/xsd/wix/removeregistryvalue.html

The problem was that the property INSTANCE_NUMBER was not set on uninstall. The uninstaller has try to delete a not existing key.

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 Installer removes shortcut on upgrade

I am using the WiX Toolkit v3.11 for creating setups of my software. During installation I create startmenu shortcuts with the following code:
<Shortcut Id='startmenuMyProgram'
Name='$(var.MyProgramName)'
Directory='ProgramMenuFolder'
WorkingDirectory='APPLICATIONFOLDER'
Advertise='yes'
Icon='icon.exe'>
<Icon Id='icon.exe' SourceFile='$(var.Setuppath)\MyProgram.exe'/>
</Shortcut>
In this way I also create two shortcuts for other executables. Now for the uninstall I want to remove the shortcuts.
<Component Id="removeStartmenuShortcuts" Guid="803ad14a-feab-4901-b9db-2c4a1298ae8b">
<Condition>(REMOVE=ALL) AND NOT (WIX_UPGRADE_DETECTED OR UPGRADINGPRODUCTCODE)</Condition>
<RemoveFile Id="remove_startmenuProgram1" Name="startmenuMyProgram" On="uninstall" />
<RemoveFile Id="remove_startmenuProgram2" Name="startmenuMyProgram2" On="uninstall"/>
<RemoveFile Id="remove_startmenuProgram3" Name="startmenuMyProgram3" On="uninstall"/>
</Component>
This works without any problems when I uninstall the software. But the shortcuts are also removed when an update is performed. But I want to prevent this behavior, but the condition seems not to work. So all shortcuts like in the Windows task bar are removed when I do an update.
How can I make my update progress work correctly?
Here the behavior after update:
The group with all shortcuts in the right is missing!
You can combine the 2 component. By this you will not need to use condition statements.
The registry value is to set a keypath under component.
<Component Id="cmpstartmenuMyProgram" Guid="{67CB4F7A-5028-4697-A47F-DE99110B9645}">
<Shortcut Id="Shortcut.ApplicationName"
Name="ApplicationName"
Target="[INSTALLDIR]ApplicationName.exe"
WorkingDirectory="INSTALLDIR"
Directory="StartMenuFolder"
Icon="Icon.exe"/>
<RemoveFile Id="RemoveStartMenuShortcut.ApplicationName" Name="ApplicationName" Directory="StartMenuFolder" On="uninstall"/>
<RegistryValue Root="HKCU" Key="Software\Compony\ComponyName" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>

Wix registry key changing

I'm using a WiX installer file to edit a registry entry however when it's uninstalled I want it to be set do a default value of 0.
Here is the code I'm using to set it to 1.
<DirectoryRef Id="TARGETDIR">
<Component Id="RegistryEntries" Guid="PUT-GUID-HERE">
<RegistryKey Root="HKCU"
Key="Software\Microsoft\Windows\CurrentVersion\Policies\System"
Action="createAndRemoveOnUninstall">
<RegistryValue Type="integer" Name="DisableTaskMgr" Value="1" KeyPath="yes"/>
</RegistryKey>
</Component>
I want it so that when it uninstalls that it does not delete the key but just sets it to 0 as I am unsure what the behaviour of the taskmanager would be if the key was deleted.
I'm also assuming Action="createAndRemoveOnUninstall" should be something else?
"Action" has been deprecated and instead you should be using "ForceCreateOnInstall" and/or "ForceDeleteOnUninstall" instead.
You can also use "NeverOverwrite" on the component to make sure that the registry value isn't removed.
To set the value you can use a custom action that is scheduled to run only during the uninstall. Use NOT UPGRADINGPRODUCTCODE as the conditional for your custom action to ensure it only executes during uninstall.
For the custom action under Product AND Package add
<InstallExecuteSequence>
<Custom Action="YourCustomAction" After="InstallInitialize"><![CDATA[(NOT UPGRADINGPRODUCTCODE)]]></Custom>
</InstallExecuteSequence>

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.