Link to home
Start Free TrialLog in
Avatar of dmillerpps
dmillerpps

asked on

How do I set folder permissions using VB.Net

The code below is creating personal folders for users in the following format:
\\server\school\username
The server is always the same but the school and username change. The folders are being created exactly the way I want except permissions are not being set on the folders the way I would like. What I would like is for the permissions to be as follows:
domain\username - modify
domain\domain admins - full control
domain\callcenter - full control
nas\administrators - full control

The final result for a folder would be \\nas\school\tsmith1 with permissions being modify for tsmith1 and Full Control for domain admins, callcenter and nas administrators.
If Len(ex1) > 0 Then
            If (DTM.Context("LocationRootFolder") IsNot Nothing) Then
                If (DTM.Context("LocationMap") IsNot Nothing) Then
                    Dim filter1 As String = DTM.Context("LocationRootFolder")
                    Dim locations1 As System.Collections.Hashtable
                    locations1 = DTM.Context("LocationMap")
                    If Len(locations1(ex1)) > 0 Then
                        homeDir = String.Format(filter1, locations1(ex1), existingSam1)
                        Dim CurrentPath as String = homeDir
 Dim UserName1 As String = "domain\" & existingSam1
 Dim UserName2 As String = "domain\Domain Admins"
 Dim UserName3 As String = "domain\CallCenter"
 Dim UserName4 As String = "NAS\Administrators"
 
 Dim dInfo As New DirectoryInfo(CurrentPath)
 Dim dSecInfo As DirectorySecurity = dInfo.GetAccessControl(AccessControlSections.Access)
 Dim myRuleValue As Integer = 0
 
 myRuleValue =  FileSystemRights.Modify   'Add your wanted Access here
 Dim myRule as FileSystemAccessRule
 myRule = New FileSystemAccessRule(UserName1, myRuleValue, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)
 dSecInfo.AddAccessRule(myRule)
 dSecInfo.SetAccessRule(myRule)
 dInfo.SetAccessControl(dSecInfo)
                    End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tuyau2poil
Tuyau2poil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial