Wix: How to set permissions for folder and all sub folders
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
Mike
Updated on July 09, 2022Comments
-
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. over 11 yearsCan 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 over 11 yearsThat'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 theUtilExtension
like this:xmlns:util="http://schemas.microsoft.com/wix/UtilExtension
and reference it like<util:PermissionEx>
-
Be.St. over 11 yearsI wrote the response before reading your comment. Thank you very much
-
zagrimsan about 9 yearsFor using just
PermissionEx
one doesn't need to add a reference toWixUIExtension
, but +1 for giving the command line parameters so that WiX newbies like me understand to add such, too. -
anhoppe about 8 yearsGreat, helped me. Used it inside a <File> tag
-
Wes about 7 yearsHe 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 almost 7 yearsDo I need to reference that Component Id
INSTALLFOLDER_Permission
anywhere? -
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 about 3 yearsThat 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. (...)