Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting Permissions on Parent Directory

8 views
Skip to first unread message

Jeff

unread,
May 24, 2006, 10:48:17 AM5/24/06
to
I am trying to set Full Control permissions on a directory. I have
tried every combination of InheritanceFlags and PropagationFlags and I
am having no success. After running the below code the parent
directory "C:\Scripts" will have list permissions set, and special
permissions Full Control. I also notice that after setting permissions
the, "Inherit from parent the permission entries that apply to child
objects. include these with entries explicitly defined here." under
advanced is being checked. I have this unchecked before running the
code. Does anyone know why List is being set on the general
permissions and Full Control is set on special permissions?


Dim ThePath = "c:\scripts"
Dim ntAcc As New NTAccount(AccountName)

'Create the access rule
Dim dsar As New FileSystemAccessRule(ntAcc, _
FileSystemRights.FullControl,
InheritanceFlags.ContainerInherit, _
PropagationFlags.None, AccessControlType.Allow)

'Create directory security object
Dim dsec As New DirectorySecurity
dsec.AddAccessRule(dsar)

'Set access
Directory.SetAccessControl(ThePath, dsec)

Jeff

unread,
Jun 1, 2006, 9:36:50 AM6/1/06
to
I got this code from MSDN. Now the user, jblow, has special
permissions - FullControl set on the parent directory "Admin Archives".
Why can I not get FullControl on the general permissions page? Why
does it set special permissions? I have tried this code on different
directories on different servers and get the same results. What am I
missing?


Dim DirectoryName as String = "\\hshshared\shared\Admin Archives"

AddDirectorySecurity(DirectoryName, "hsh\jblown",
FileSystemRights.Modify, _ AccessControlType.Allow)

Sub AddDirectorySecurity(ByVal FileName As String, ByVal Account As
String, ByVal Rights As FileSystemRights, ByVal ControlType As
AccessControlType)
' Create a new DirectoryInfoobject.
Dim dInfo As New DirectoryInfo(FileName)

' Get a DirectorySecurity object that represents the
' current security settings.
Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl()

' Add the FileSystemAccessRule to the security settings.
dSecurity.AddAccessRule(New FileSystemAccessRule(Account,
Rights, ControlType))

' Set the new access settings.
dInfo.SetAccessControl(dSecurity)

End Sub

Jeff

unread,
Jun 1, 2006, 9:39:18 AM6/1/06
to
Sorry, I meant Modify permissions on the parent directory!

Jeff

unread,
Jun 5, 2006, 2:25:31 PM6/5/06
to
I figured out the problem. I needed to set Container Inherit and
Object Inherit for the Inheritance Flags. By not setting any flags the
permissions were only applied onto "this folder only". By setting only
Container Inherit, permissions were only applied onto "this folder and
subfolders. These settings only apply to special permissions. The
only problem I had is that I could not set Container Inherit and Object
Inherit with one command, so I ran the following lines one after the
other and presto the correct permissions were set.

AddDirectorySecurity(DirectoryName, "hsh\jblown",
FileSystemRights.Modify, InheritanceFlags.ContainerInherit,
PropagationFlags.None, AccessControlType.Allow)

AddDirectorySecurity(DirectoryName, "hsh\jblown",
FileSystemRights.Modify, InheritanceFlags.ObjectInherit,
PropagationFlags.None, AccessControlType.Allow)

0 new messages