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

3

45

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?

Dronski answered 24/11, 2010 at 23:11 Comment(0)
S
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.

Swagerty answered 25/11, 2010 at 7:20 Comment(5)
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. ThanksYila
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>Swagerty
I wrote the response before reading your comment. Thank you very muchYila
Great, helped me. Used it inside a <File> tagUnscrupulous
@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. :)Greet
Y
37

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>
Yila answered 4/12, 2012 at 14:24 Comment(0)
W
28
<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
Wallenstein answered 29/3, 2014 at 19:35 Comment(4)
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.Pameliapamelina
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.Shortstop
Do I need to reference that Component Id INSTALLFOLDER_Permission anywhere?Monophagous
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. (...)Marbleize

© 2022 - 2024 — McMap. All rights reserved.