44

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?

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Mike
  • 463
  • 2
  • 5
  • 5

3 Answers3

42

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.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • 3
    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 – Be.St. Dec 04 '12 at 13:44
  • 8
    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 `` – Yan Sklyarenko Dec 04 '12 at 14:06
  • I wrote the response before reading your comment. Thank you very much – Be.St. Dec 04 '12 at 14:34
  • 1
    Great, helped me. Used it inside a tag – anhoppe Feb 15 '16 at 15:55
  • @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. :) – Macke Apr 01 '19 at 14:48
36

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>
Be.St.
  • 4,101
  • 3
  • 25
  • 35
27
<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
shox
  • 677
  • 1
  • 5
  • 19
cdytoby
  • 839
  • 10
  • 26
  • 2
    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. – zagrimsan Apr 21 '15 at 10:50
  • 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. – Wes Apr 06 '17 at 13:42
  • Do I need to reference that Component Id `INSTALLFOLDER_Permission` anywhere? – codenamezero Jun 29 '17 at 22:04
  • 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. (...) – daniol Feb 19 '21 at 11:21