如何在Wix中设置ProgramFilesFolder子文件夹权限?

时间:2014-08-05 21:49:51

标签: wix installer windows-installer wix-extension wix3.8

我正在使用WiX将应用程序安装到Program Files文件夹。我正在使用util:XmlFile来更新connectionStrings元素,但是我收到错误"无法打开XML文件C:\ Program Files(x86)\ developMENTALmadness \ MainApp.exe.config系统错误-2147024786"。我正在尝试提升权限并设置目标文件和父文件夹的权限,但权限未设置。

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>

我已经使用heat.exe生成了组件列表并对其进行了修改(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>

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

好的,所以看起来更好(推荐?)将我的配置文件存储在CommonAppDataFolder(C:\ ProgramData)中。这意味着我现在需要使用ConfigurationManager.OpenMappedExeConfiguration方法加载我的配置,如下所示:

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;

我试图做的更简化的版本是:

<?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>

这没有任何问题,所以除非有人知道如何解决另一个问题,否则我会选择这个解决方案。

这是github上此示例的完整源代码的链接:https://github.com/developmentalmadness/HelloWiX