0

I am installing an application to the Program Files folder using WiX. I am using util:XmlFile to update the connectionStrings element but I am getting an error "Failed to open XML file C:\Program Files (x86)\developMENTALmadness\MainApp.exe.config system error -2147024786". I am trying to elevate permissions and set the permissions on the target file and parent folder, but the permissions aren't getting set.

Product.wxs:

<?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="{7A04DDDD-F423-4E81-A42F-6831479ECF15}" Name="Installer" 
             Language="1033" Version="1.0.0.0" 
             Manufacturer="developMENTALmadness" 
             UpgradeCode="a65f51b5-8bf8-4490-8fab-899cc23a8e1b">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" 
                     InstallPrivileges="elevated" />

  <MajorUpgrade DowngradeErrorMessage="A newer version is already installed." />
    <MediaTemplate EmbedCab="yes" />

    <Property Id="SQLSERVER" Value="(local)" />
    <Property Id="SQLDATABASE" Value="OMDatabase" />
    <Property Id="SQLINSTALLUSER" Value="sa" />
    <Property Id="SQLINSTALLPWD" />
    <Property Id="SQLUSER" />
    <Property Id="SQLPWD" />

    <Feature Id="ProductFeature" Title="Installer" Level="1">
        <ComponentGroupRef Id="main_output"/>
    </Feature>

    <!--<UIRef Id="WixUI_Minimal"/>-->
    <UIRef Id="CustomWizard"/>

     <Binary Id="WixUI_Bmp_Banner" 
                 SourceFile="$(var.MainApp.ProjectDir)info.png" />
     <Binary Id="WixUI_Ico_Info" 
                 SourceFile="$(var.MainApp.ProjectDir)favicon.ico"/>
</Product>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="developMENTALmadness">
                <Directory Id="target_root" Name="HelloWiX" >
                </Directory>
            </Directory>
        </Directory>
    </Directory>
</Fragment>

I've generated the component list by using heat.exe and modified it (MainOutput.wxs):

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Fragment>
    <DirectoryRef Id="target_root">
        <Component Id="root_permissions" Guid="{87E634CC-8F0E-4610-961A-9B6C1BBDAEFE}">
            <CreateFolder Directory="target_root">
                <util:PermissionEx User="Users" GenericAll="yes" ChangePermission="yes" />
            </CreateFolder>
        </Component>
    </DirectoryRef>
</Fragment>
<Fragment>
    <ComponentGroup Id="main_output">
        <Component Id="cmp2D913B775A49E24FBD0E4DB1A96F05A7" Directory="target_root" Guid="{6284BD47-6181-4220-8DF8-D76F43A608F4}">
            <File Id="fil115E0DBDE48A315B4A1DABD091FE0184" KeyPath="yes" Source="$(var.MainApp.TargetPath)" />
        </Component>
        <Component Id="cmp1A2EDC339002636FAD729B028E1D726A" Directory="target_root" Guid="{45D6B30C-4C74-4260-B53F-855E5F4681FA}">
            <File Id="filB9D96E3BAC71662F051EA888708285DA" KeyPath="yes" Source="$(var.MainApp.TargetPath).config" Vital="yes">
                <util:PermissionEx User="Users" GenericAll="yes" ChangePermission="yes" />
            </File>
            <util:XmlFile Id="SetSqlConnection" Action="setValue" 
                          ElementPath="/configuration/connectionStrings/add[\[]@name='database'[\]]"
                          File="[INSTALLFOLDER]$(var.MainApp.TargetFileName).config"
                          Value="Server=[SQLSERVER];Database=[SQLDATABASE];uid=[SQLUSER];pwd=[SQLPWD];" 
                          Sequence="1"
                          SelectionLanguage="XPath" Name="connectionString"  />
        </Component>
    </ComponentGroup>
</Fragment>

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Mark J Miller
  • 4,751
  • 5
  • 44
  • 74

2 Answers2

0

You can try the PermissionEx element.

Some similar questions:

Community
  • 1
  • 1
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • I *am* using PermissionEx. That's what's so frustrating, it doesn't seem to be working. Unless I'm using it wrong which would be great if someone could point out something I'm doing wrong. – Mark J Miller Aug 05 '14 at 23:17
  • okay, you meant the MSI 5.0 PermissionEx element. I should have followed the link (to be fair they shouldn't have reused the name). Can you provide an equivalent example based on my example above? I've seen all these posts before I tried posting myself. – Mark J Miller Aug 06 '14 at 01:33
0

Okay, so it would seem that it is better (recommended?) to store my config file in the CommonAppDataFolder (C:\ProgramData). This means I'll need to use the ConfigurationManager.OpenMappedExeConfiguration method to load my config now, like this:

ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = Path.Combine(@"C:\ProgramData\developMENTALmadness", 
    Path.GetFileName(Assembly.GetExecutingAssembly().Location) + ".config");

var config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

var name = config.AppSettings.Settings["FullName"].Value;

And a much more simplified version of what I'm trying to do is this:

<?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="{F15C9D98-5296-417C-847F-1DC1E67C3498}" Name="HelloWiXInstaller" Manufacturer="developMENTALmadness" Language="1033" Version="1.0.0.0" UpgradeCode="a3be08fb-680d-425a-a471-4ab16e4aa805">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MediaTemplate EmbedCab="yes" />

    <Property Id="FULL_NAME" Value="Mark J. Miller (installed)" />

    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="ProgramFilesFolder">
            <Directory Id="INSTALLFOLDER" Name="developMENTALmadness">
                <Component Id="CMP_HelloWiX.exe" Guid="{38FC6E96-37D6-4A2D-A584-F7D84705AC34}">
                    <File Id="EXE_HelloWiX.exe" Source="$(var.HelloWiX.TargetPath)" />
                </Component>
            </Directory>
        </Directory>
        <Directory Id="CommonAppDataFolder">
            <Directory Id="CONFIGFOLDER" Name="developMENTALmadness">
                <Component Id="CMP_HelloWiX.exe.config" Guid="{6D470FDB-BF36-4648-BDBD-63D168F8D085}">
                    <File Id="CONFIG_HelloWiX.exe.config" Source="$(var.HelloWiX.TargetPath).config" />
                    <util:XmlFile Id="SetConfigValue" Action="setValue"
                                  File="[CONFIGFOLDER]$(var.HelloWiX.TargetFileName).config"
                                  ElementPath="/configuration/appSettings/add[\[]@key='FullName'[\]]"
                                  Value="[FULL_NAME]"
                                  SelectionLanguage="XPath"
                                  Name="value"/>
                </Component>
            </Directory>
        </Directory>
    </Directory>

    <Feature Id="HelloWiXProduct" Title="Hello, WiX" Level="1">
        <ComponentRef Id="CMP_HelloWiX.exe" />
        <ComponentRef Id="CMP_HelloWiX.exe.config" />
    </Feature>
</Product>

And that works without any issues, so unless someone knows how to fix the other problem I'll go with this solution.

Here's a link to the full source for this sample on github: https://github.com/developmentalmadness/HelloWiX

Mark J Miller
  • 4,751
  • 5
  • 44
  • 74