Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Vista Newsgroups > Vista file management

How to change 'Group' permissions on existing folder?

Closed Thread
 
Thread Tools Display Modes
Old 05-23-2007   #1 (permalink)
Jason
Guest


 

How to change 'Group' permissions on existing folder?

I have a similar issue to Bob Eaton's previous post in that I have an app
that stores data in [CommonAppData]/Company/Application. I need to give the
local/users group 'modify' rights to this folder and have the modify right
propagate to child files and folders.

By the way, 'local/Users' also inherits special permissions on this folder
which allow users to create files/objects and append data. So the first time
a file is saved to this folder by a LUA user it works just fine. However,
they can't edit the content of the files or overwrite them later.

I can set the permissions as part of an installation custom action that runs
with elevated priviledges but I'm having trouble setting the actual
permissions.

The code that I'm trying to use is:

Sub Set_Folder_Permissions()
'Retrieve the Directory Security descriptor for the directory
Dim DirectorySecurity As DirectorySecurity =
Directory.GetAccessControl(Settings.CommonAppDataPath,
AccessControlSections.Access)

'Create a new Access Rule
Dim accessrule As New FileSystemAccessRule("users",
FileSystemRights.Modify, InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow)

'Add the access rule to the Directory Security Descriptor
DirectorySecurity.AddAccessRule(accessrule)

'Persist the Directory Security Descriptor to the directory
Directory.SetAccessControl(Settings.CommonAppDataPath,
DirectorySecurity)
End Sub

However, this isn't changing the 'Users' group access rights on the folder.
No exceptions are generated either.

Of course, the Users group is already inheriting Read & Execute, Read, List
folder Contents from the parent folder. I can manually add 'Modify' (which
also turns on 'Write') at this level and it's inherited by lower level
objects correctly. But my code isn't adding the modify right and that's my
main problem.

Second, I'm concerned about hard coding 'Users' as the account. I thought
that 'Users' was locale specific and I should use a well known sid.

My questions are: Am I doing something wrong with the code above? How to I
add the Modify right for the 'Users' group on a folder?

Second, do I need to worry about hard coding 'Users' rather than using a
well known SID? If so, how do I go about using the well known SID?

Thanks,

Jason Eskew
Old 05-23-2007   #2 (permalink)
Adrian Accinelli
Guest


 

Re: How to change 'Group' permissions on existing folder?


"Jason" <Jason@discussions.microsoft.com> wrote in message
news:EB17EB39-00EB-4480-9BA3-1947EC1F936E@microsoft.com...
>I have a similar issue to Bob Eaton's previous post in that I have an app
> that stores data in [CommonAppData]/Company/Application. I need to give
> the
> local/users group 'modify' rights to this folder and have the modify right
> propagate to child files and folders.
>
> By the way, 'local/Users' also inherits special permissions on this folder
> which allow users to create files/objects and append data. So the first
> time
> a file is saved to this folder by a LUA user it works just fine. However,
> they can't edit the content of the files or overwrite them later.
>
> I can set the permissions as part of an installation custom action that
> runs
> with elevated priviledges but I'm having trouble setting the actual
> permissions.
>
> The code that I'm trying to use is:
>
> Sub Set_Folder_Permissions()
> 'Retrieve the Directory Security descriptor for the directory
> Dim DirectorySecurity As DirectorySecurity =
> Directory.GetAccessControl(Settings.CommonAppDataPath,
> AccessControlSections.Access)
>
> 'Create a new Access Rule
> Dim accessrule As New FileSystemAccessRule("users",
> FileSystemRights.Modify, InheritanceFlags.ObjectInherit,
> PropagationFlags.None, AccessControlType.Allow)
>
> 'Add the access rule to the Directory Security Descriptor
> DirectorySecurity.AddAccessRule(accessrule)
>
> 'Persist the Directory Security Descriptor to the directory
> Directory.SetAccessControl(Settings.CommonAppDataPath,
> DirectorySecurity)
> End Sub
>
> However, this isn't changing the 'Users' group access rights on the
> folder.
> No exceptions are generated either.
>
> Of course, the Users group is already inheriting Read & Execute, Read,
> List
> folder Contents from the parent folder. I can manually add 'Modify'
> (which
> also turns on 'Write') at this level and it's inherited by lower level
> objects correctly. But my code isn't adding the modify right and that's
> my
> main problem.
>
> Second, I'm concerned about hard coding 'Users' as the account. I thought
> that 'Users' was locale specific and I should use a well known sid.
>
> My questions are: Am I doing something wrong with the code above? How to
> I
> add the Modify right for the 'Users' group on a folder?
>
> Second, do I need to worry about hard coding 'Users' rather than using a
> well known SID? If so, how do I go about using the well known SID?
>
> Thanks,
>
> Jason Eskew


microsoft.public.platformsdk.msi might be better for this question since
it's really MSI custom action related and there's lots of experience over
there.

1. Make sure your custom action is running as a deferred and
non-impersonated custom action otherwise you won't have the necessary
privileges to edit the ACLs on your CommonAppData folder.

2. Whatever you do don't hard code "users" or any other well known name as a
string. I made that mistake once and spent a great deal of time with
patches for non-english locale systems. I'm not a .NET guy so probably
you'll get a much better response from someone else but FileSystemAccessRule
takes SecurityIdentifier as an argument and that looks like it can use
WellKnownSidType (e.g. BuiltinUsersSid). I hope that's enough to get you in
the right direction with help from msdn/web searches.

Sincerely,
Adrian Accinelli


Old 05-23-2007   #3 (permalink)
Jason
Guest


 

Re: How to change 'Group' permissions on existing folder?

>
> microsoft.public.platformsdk.msi might be better for this question since
> it's really MSI custom action related and there's lots of experience over
> there.
>
> 1. Make sure your custom action is running as a deferred and
> non-impersonated custom action otherwise you won't have the necessary
> privileges to edit the ACLs on your CommonAppData folder.
>
> 2. Whatever you do don't hard code "users" or any other well known name as a
> string. I made that mistake once and spent a great deal of time with
> patches for non-english locale systems. I'm not a .NET guy so probably
> you'll get a much better response from someone else but FileSystemAccessRule
> takes SecurityIdentifier as an argument and that looks like it can use
> WellKnownSidType (e.g. BuiltinUsersSid). I hope that's enough to get you in
> the right direction with help from msdn/web searches.
>
> Sincerely,
> Adrian Accinelli
>


Thanks for the reply. I'm not worried about the msi custom action. I have
other code that is running correctly in the custom action. This question is
specific to the accessrules issue.

On the subject of hard-coding users... That's what I thought. AccessRule
has an overloaded constructor that takes a SecurityIdentifier so I had tried
to use that. But I ran into a problem creating the SecurityIdentifier. The
constructor for it takes a well known sid enumeration and a
SecurityIdentifier. Gee, this means that I need the chicken before I can
create the egg? Specifically, I'm can't create the SecurityIdentifier
because I need to pass it a SecurityIdentifier. If anyone has a suggestion
as to where I could take a reference to an existing identifier, I'd be happy
to try it because supposedly it's ignored unless you are using one of several
specific well known sids (which doesn't include the localuser SID.)

Also, I did try creating a new NTaccount object and use the .translate
method to translate it to a SecurityIdentifier but I couldn't get the
SecurityIdentifier constructor to accept it.
Old 05-23-2007   #4 (permalink)
Adrian Accinelli
Guest


 

Re: How to change 'Group' permissions on existing folder?


"Jason" <Jason@discussions.microsoft.com> wrote in message
news8F064D6-E519-4276-8EB7-534152BE690F@microsoft.com...
>>
>> microsoft.public.platformsdk.msi might be better for this question since
>> it's really MSI custom action related and there's lots of experience over
>> there.
>>
>> 1. Make sure your custom action is running as a deferred and
>> non-impersonated custom action otherwise you won't have the necessary
>> privileges to edit the ACLs on your CommonAppData folder.
>>
>> 2. Whatever you do don't hard code "users" or any other well known name
>> as a
>> string. I made that mistake once and spent a great deal of time with
>> patches for non-english locale systems. I'm not a .NET guy so probably
>> you'll get a much better response from someone else but
>> FileSystemAccessRule
>> takes SecurityIdentifier as an argument and that looks like it can use
>> WellKnownSidType (e.g. BuiltinUsersSid). I hope that's enough to get you
>> in
>> the right direction with help from msdn/web searches.
>>
>> Sincerely,
>> Adrian Accinelli
>>

>
> Thanks for the reply. I'm not worried about the msi custom action. I
> have
> other code that is running correctly in the custom action. This question
> is
> specific to the accessrules issue.

Right - misread your first statement and thought the code was working
outside the custom action so jumped to the obvious issue wrt scheduling and
permissions and why I mentioned the other MSI related newsgroup.

>
> On the subject of hard-coding users... That's what I thought. AccessRule
> has an overloaded constructor that takes a SecurityIdentifier so I had
> tried
> to use that. But I ran into a problem creating the SecurityIdentifier.
> The
> constructor for it takes a well known sid enumeration and a
> SecurityIdentifier. Gee, this means that I need the chicken before I can
> create the egg? Specifically, I'm can't create the SecurityIdentifier
> because I need to pass it a SecurityIdentifier. If anyone has a
> suggestion
> as to where I could take a reference to an existing identifier, I'd be
> happy
> to try it because supposedly it's ignored unless you are using one of
> several
> specific well known sids (which doesn't include the localuser SID.)
>
> Also, I did try creating a new NTaccount object and use the .translate
> method to translate it to a SecurityIdentifier but I couldn't get the
> SecurityIdentifier constructor to accept it.


Again no expert (especially with VB) here but for built in "users" I think
it should be:

Dim sidType As WellKnownSidType
Dim domainSid As SecurityIdentifier
sidType = WellKnownSidType.BuiltinUsersSid
Dim sid As New SecurityIdentifier(sidType, domainSid)

Dim accessrule As New FileSystemAccessRule ( sid,
FileSystemRights.Modify, InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow)

To set permissions explicitly for the user who launched the installation you
can retrieve the UserSID property from MSI. It can then be used to create
another SecurityIdentifier as above (assuming the code works

Sincerely,
Adrian Accinelli


Old 05-23-2007   #5 (permalink)
Jason
Guest


 

Re: How to change 'Group' permissions on existing folder?

> Dim sidType As WellKnownSidType
> Dim domainSid As SecurityIdentifier
> sidType = WellKnownSidType.BuiltinUsersSid
> Dim sid As New SecurityIdentifier(sidType, domainSid)


Thanks Adrian,

That little bit of code helped me change how I was thinking about the
problem enough to help me over the hump. The code below works and the
comments give additional insight into how I got it working and one of the
problems that I ran across.

Sub Set_Folder_Permissions()
'Retrieve the Directory Security descriptor for the directory
Dim dSecurity As DirectorySecurity =
Directory.GetAccessControl(Settings.CommonAppDataPath,
AccessControlSections.Access)

'Build a temp domainSID using the Null SID passed in as a SDDL
string. The constructor will accept the traditional notation or the SDDL
notation interchangeably.
Dim domainSid As New SecurityIdentifier("S-1-0-0")

'Create a security Identifier for the BuiltinUsers Group to be
passed to the new accessrule
Dim ident As New
SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, domainSid)

'Create a new Access Rule.
'ContainerInherit AND ObjectInherit covers both target folder, child
folder and child object.
'However, when using both (combined with AND), the permissions
aren't applied. So just use
'objectinherit and the child objects (even created at a later time
in sub directories) inherit the permission correctly.
'Propagate.none means child and grandchild objects inherit.
Dim accessRule As New FileSystemAccessRule(ident,
FileSystemRights.Modify, InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow)

'Add the access rule to the Directory Security Descriptor
dSecurity.AddAccessRule(accessRule)

'Persist the Directory Security Descriptor to the directory
Directory.SetAccessControl(Settings.CommonAppDataPath, dSecurity)
End Sub
Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
New contacts added to an existing group don''t work Erik van der Heijden Vista mail 4 02-29-2008 12:31 AM
Cannot revert (change back) folder permissions settings Desperato Vista networking & sharing 10 12-04-2007 07:56 AM
Cannot revert (change back) folder permissions settings Desperato Vista account administration 0 12-02-2007 10:19 PM
Change the name of the "File Folder" group in Explorer Detailed Vi mdjake Vista file management 0 10-14-2007 09:52 AM
Permissions on existing drives after install Michael Vista installation & setup 2 01-03-2007 03:16 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50