Search code examples
c#internet-explorerwixregistrywebbrowser-control

WIX cannot write value to registry if key contains space


I need to enable IE feature for WebBrowser control. To emulate IE11, I need to write a value to registry key

HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION

This manipulation need to be done during installation. Here is my code in WIX script:

<?define var.IEFeatureEmulationKey = "Software\Microsoft\Internet    Explorer\FeatureControl\FEATURE_BROWSER_EMULATION" ?>
....
<Fragment>            
  <DirectoryRef Id="TARGETDIR">            
    <Component Id="registryValues" Guid="{some-guid}" >
      <RegistryKey Root="HKCU" Key="$(var.IEFeatureEmulationKey)" Action="create">
        <RegistryValue Name="MyApp.EXE" Value="11000" Type="integer" Action="write"/>
      </RegistryKey>
    </Component>
</Fragment>      

This code work only if $(var.IEFeatureEmulationKey) contains no spaces. But I need to write a value to this specific key.

Please help, how tell WiX to write value to registry even in registry key contains spaces.

UPD: Added appropriate issue in WiX repository


Solution

  • Still cannot overcome the issue, however I want to show a workaround that helped me.

    I used custom action that allowed in WiX. First of all I added custom .NET assembly with following method within it

    [CustomAction]
    public static ActionResult SetRegistryItems(Session session)
    {
        session.Log("Begin SetRegistryItems");
    
        try
        {
            // this private method actually does manipulation with registry
            SetRegistry();
        }
        catch (Exception e)
        {
            session.Log(e.ToString());
        }
    
        return ActionResult.Success;
    }
    

    Then this method should be referenced in WiX config file (.wxs)

    <Fragment>    
      ...
      <CustomAction Id='SetRegistryItems' BinaryKey='<NameOfTheAssemblyWithoutExtension>' DllEntry='SetRegistryItems' Execute='immediate'/>
      ...
      <InstallExecuteSequence>
        ...
        <Custom Action="SetRegistryItems" Before="LaunchConditions"/> 
        ...
      </InstallExecuteSequence> 
      ...
    </Fragment>