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)
[quoted text, click to view] Jeff wrote:
> Sorry, I meant Modify permissions on the parent directory!
>
>
> Jeff wrote:
> > 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 wrote:
> > > 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)