Wix: How to set permissions for folder and all sub folders

33,297

Solution 1

First of all, I would recommend you using PermissionEx instead. It is a standard WiX extension and it has one really huge advantage over Permission - it doesn't overwrite, but modifies ACLs. And by default, it applies permissions to the folder and all its descendant files and folders, so you don't have to specify anything extra.

Hope this helps.

Solution 2

I solved: different PermissionEx are defined in Wix and Util schema (Wix PermissionEx and Util Extension PermissionEx)

I used the Util version:

  • Add a reference to WixUtilExtension assembly
  • Add the UtilExtension namespace to the Wix tag:
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  • Specify the Util PermissionEx version:
<CreateFolder Directory="DirectoryToManage">
    <util:PermissionEx User="Users" GenericAll="yes" />
</CreateFolder>

Solution 3

<DirectoryRef Id="INSTALLFOLDER">
        <Component Id="INSTALLFOLDER_Permission" Guid="*">
            <CreateFolder>
                <util:PermissionEx User="Users" GenericAll="yes"/>
            </CreateFolder>
        </Component>
    </DirectoryRef>

The answer above is correct, and you will set the permissions to all the folders and files in this folder.

Please note: The CreateFolder tag should be in a component, and this component must be added to a Feature.

Also, you have to add this to the command line of the compiler and the linker:

-ext WixUIExtension -ext WixUtilExtension
Share:
33,297
Mike
Author by

Mike

Updated on July 09, 2022

Comments

  • Mike
    Mike almost 2 years

    I know how to set the permissions for a folder:

    <DirectoryRef Id="ProgramFilesFolder">
      <Directory Id="PHPFolder" Name="PHP">
        <Component Id="PHP_comp" DiskId="1" Guid="*">
          <CreateFolder>
            <Permission User="Everyone" GenericAll="yes" />
          </CreateFolder>
    

    However I need the permissions to be applied to all subfolders as well. Is this possible with out listing all the folders?

  • Be.St.
    Be.St. over 11 years
    Can you provide an example with PermissionEx? I'm using it inside a CreateFolder tag but I receive the error "The required attribute SDDL is missing". I've also the User and GenericAll attributes with an "attribute is not declared" error. Thanks
  • Yan Sklyarenko
    Yan Sklyarenko over 11 years
    That's because you're using the standard PermissionEx element, which is supported started from MSI 5.0. It has a different signature, and it expects SDDL attribute. You should include the UtilExtension like this: xmlns:util="http://schemas.microsoft.com/wix/UtilExtension and reference it like <util:PermissionEx>
  • Be.St.
    Be.St. over 11 years
    I wrote the response before reading your comment. Thank you very much
  • zagrimsan
    zagrimsan about 9 years
    For using just PermissionEx one doesn't need to add a reference to WixUIExtension, but +1 for giving the command line parameters so that WiX newbies like me understand to add such, too.
  • anhoppe
    anhoppe about 8 years
    Great, helped me. Used it inside a <File> tag
  • Wes
    Wes about 7 years
    He does because he is using PermissionEx specified in the WixUIExtension, not the plain MSI based PermissionEx which takes a SDDL as an attribute. They have same name but are very different.
  • codenamezero
    codenamezero almost 7 years
    Do I need to reference that Component Id INSTALLFOLDER_Permission anywhere?
  • ICTMitchell
    ICTMitchell about 5 years
    @YanSklyarenko Consider updating your answer with extra info from comments. One should not need to read comments to understand the whole picture. Also, your answer is quite terse and an example would help. :)
  • daniol
    daniol about 3 years
    That doesn't compile. Here is the error: The Component/@Guid attribute's value '*' is not valid for this component because it does not meet the criteria for having an automatically generated guid. Components using a Directory as a KeyPath or containing ODBCDataSource child elements cannot use an automatically generated guid. (...)