Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ACL AddAccessRule Problems

Status
Not open for further replies.

pkirill

Technical User
Jun 15, 2002
134
0
0
US
I've got a little code that creates some subfolders and then applies some permissions. I've got it working so it creates the first two folders, applies permissions correctly to the first folder but then stops. if I run the same code again specifying the same subfolders, it creates all the folders and applies the permissions correctly. I'd prefer not to have to run the program twice - so any assistance would be appreciated! (Code is below)

Code:
'Create initial subfolder - this folder inherits permissions from a parent folder.
    Private Sub CreateProjectFolder(ByVal strProjectPath As String)
        My.Computer.FileSystem.CreateDirectory(strProjectPath)
        Dim dInfo As New DirectoryInfo(strProjectPath)
        Dim ruleF As FileSystemAccessRule

        ruleF = New FileSystemAccessRule("builtin\users", FileSystemRights.ReadAndExecute, InheritanceFlags.ContainerInherit, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)

        Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl
        dSecurity.AddAccessRule(ruleF)

        dInfo.SetAccessControl(dSecurity)
    End Sub
Code:
'this code uses an array of subfolder names to create and run the AddDirectorySecurity sub...

 Private Sub CreateCommonFolders(ByVal strProjectPath As String)

        Dim arFolderList() As String = {"\_Data", "\_Docs", "\_Financial", "\_PM", "\_Specs", "\_Submissions"}
        Dim strSubfolder As String

        For Each strSubfolder In arFolderList
            Directory.CreateDirectory(strProjectPath & strSubfolder)
            AddDirectorySecurity(strProjectPath, strSubfolder)
        Next strSubfolder
end sub

Code:
 'This is the AddDirectorySecurity sub. It seems to hang when it gets to the AddAccessRule(ruleF) line...

    Sub AddDirectorySecurity(ByVal strProjectPath As String, ByVal strSubFolder As String)
        Dim blnDirExists As Boolean = False

        Dim dInfo As New DirectoryInfo(strProjectPath & strSubFolder)
        Dim ruleF As FileSystemAccessRule

        ruleF = New FileSystemAccessRule("builtin\users", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit + InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)

        Dim dSecurity As DirectorySecurity = dInfo.GetAccessControl

        dSecurity.AddAccessRule(ruleF)
        dInfo.SetAccessControl(dSecurity)

    End Sub
 
As a note: While processing the Second folder ("\data"), when it gets to "dsecurity.AddAccessRule(ruleF)" it throws an "InvalidOperationException was unhandled: This access control list is not in canonical form and therefore cannot be modified."

If I stop the debugger and run it again, it process all the folders with no exceptions...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top