首页 > 解决方案 > 如何在安装期间将文件夹共享访问权限设置为 MSI 中当前登录的用户(或任何其他本地用户)?

问题描述

使用的包装工具:WIX。

自定义操作是用 C++ 编写的。

在安装过程中,我的 MSI 在 ProgramData 中创建了一个文件夹“X”,在安装结束时,我需要为当前登录的用户(或 PC 中的任何本地用户,此输入将在安装过程中由用户提供)提供文件夹共享访问权限,我找不到任何可以帮助我解决此问题的 WIX 元素或 C++ API。

我发现在 wix 中使用元素我可以为文件夹提供权限(文件夹属性的安全选项卡),但我找不到提供共享权限的 Wix 元素/C++ API。(文件属性的共享选项卡)现在如果你看到“ “每个人”都有读取权限,通过我的 MSI,我应该能够在共享中为任何用户提供完全访问权限(完全控制)。

在此处输入图像描述

标签: c++directorywixwindows-installercustom-action

解决方案


WiX 在其 Util 扩展中具有此功能:

文档:

Util dll 中还有许多其他 WiX 特殊功能:https ://wixtoolset.org/documentation/manual/v3/xsd/util/

一个具体的模型示例:

<?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="*" Name="WixFolderShare" Language="1033" Version="1.0.0.0" Manufacturer="Someone" UpgradeCode="b3d89acb-71d9-48ab-a3df-886d49965ea3">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine"  />
    <MediaTemplate EmbedCab="yes" />
        
    <!--<UIRef Id="WixUI_Mondo" />--> <!-- Diabled main GUI -->
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

    <Feature Id="ProductFeature" Title="WixFolderShare" Level="1" />
    
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="Test Folder">

          <Component Feature="ProductFeature">

            <File Source="$(env.SystemRoot)\notepad.exe" />

            <util:User Id="Everyone" Name="Everyone" />

            <!-- Create Share with share permissions -->
            <util:FileShare Id="TestShare" Name="TestShareName" Description="This is a test share.">
              <util:FileSharePermission User="Everyone" GenericAll="yes"/>
            </util:FileShare>

            <!-- NTFS ACL permissions -->
            <CreateFolder>
              <util:PermissionEx User="Everyone" GenericAll="yes" />
            </CreateFolder>

          </Component>

      </Directory>
      </Directory>
    </Directory>

</Product>
</Wix>

推荐阅读