Wix: CustomAction to set Folder permissions

故事扮演 提交于 2021-01-28 06:22:12

问题


We're using WiX to bundle up our ASP.NET code into an MSI installer, and we need to set the [ComputerName]\IIS_WPG group to have modify permissions on a folder (named "CO") under the installation directory. The directory structure looks like this after install

C:\inetpub\wwwroot\MyApp\CO

The CO folder is actually part of the .NET solution file, and when the application is bundled into an MSI, the CO folder is included automatically because there are XML files underneath it which are marked as "Content" (this means that I don't need to explicitly use CreateFolder to create the CO folder underneath MyApp). These XML files are updated by the application, which is why the IIS_WPG needs modify permission.

My question is, how do I set the permission on the CO folder? I thought that I might be able to create the folder in an attempt to overwrite whatever permissions are included by default but it doesn't set the permission - I'm guessing that's because the folder I'm creating is overwritten by the actual folder in the MSI, thereby overwriting the permissions that I've set.

I thought that I might need to create a CustomAction which gets executed at some point before InstallFinalize, but I'm lost because I don't understand how to link the folder creation to the CustomAction. I've tried this

<InstallExecuteSequence>
    <Custom Action="SetPermission" Before="InstallFinalize" />    
</InstallExecuteSequence>
<CustomAction Id="SetPermission" Directory="CODIRECTORY">
    <Directory Id="CODIRECTORY" Name="CO" LongName="CO">
        <Component Id="CODIR" Guid="D28C9DA4-D20F-45E6-9C9B-4687177EDF41" DiskId="1">
            <CreateFolder>
                <Permission GenericAll="yes" User="[ComputerName]\IIS_WPG" />
                <Permission GenericAll="yes" User="Administrators" />
                <Permission GenericRead="yes" GenericWrite="yes" User="ASPNET" />
            </CreateFolder>
        </Component>
    </Directory>      
</CustomAction>

But that gives me this error

error CNDL0049 : The CustomAction element's DllEntry, Error, ExeCommand, JScriptCall, Script, Value, or VBScriptCall attribute was not found; one of these is required.
error CNDL0005 : The CustomAction element contains an unexpected child element 'Directory'

I've also tried to use PermissionEx, but I get this error when using that

error CNDL0005 : The CreateFolder element contains an unexpected child element 'util:PermissionEx'.

even though I added xmlns:util="http://schemas.microsoft.com/wix/UtilExtension" at the top of the file.

How do I get the CustomAction to work and Folder Permissions correct?


回答1:


Your settings looks quite similar to mine, there are little differences.

We do not set the permissions in a custom action, but with creating the directory.

This one works for us:

<Directory Name="SourceDir" Id="TARGETDIR"> 
  <Directory Id="CommonAppDataFolder"> 
    <Directory Name="$(var.InstallCompany)" Id="CompanyDir"> 
      <Directory Name="$(var.InstallProduct)" Id="ProductDir"> 
        <Directory Name="$(var.InstallFolder)" Id="INSTALLLOCATION">
          <Component Id="Permission.InstallFolder" Guid="{7C5234ED-EE92-468A-A765-27E5747705DB}"> 
            <CreateFolder>
              <Permission ChangePermission="yes" GenericAll="yes" User="Administrators"/> 
              <Permission User="Everyone" WriteExtendedAttributes="yes" WriteAttributes="yes" CreateFile="yes" CreateChild="yes" GenericWrite="no" GenericRead="yes" GenericExecute="yes"/> 
            </CreateFolder> 
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Directory>
</Directory>



回答2:


I had to create a CustomAction, similar to what is done in this post

Set Permission Using cacls

I know it's not ideal, but it solves the problem. We could potentially upgrade to Wix 3 and use PermissionEx, but that's a battle I'll have to fight another day.

Not sure it helps, but I did some more investigation and found that we're using Wix 2, so I'm guessing that's why we couldn't use PermissionEx.



来源:https://stackoverflow.com/questions/17612634/wix-customaction-to-set-folder-permissions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!