Solved

How do I set folder permissions using VB.Net

Posted on 2011-03-21
3
426 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:dmillerpps
3 Comments
 
LVL 4

Accepted Solution

by:
Tuyau2poil earned 500 total points
ID: 35184415
your code is Ok. just add acl for each user.
try this :

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()

 dSecInfo.AddAccessRule(New FileSystemAccessRule(UserName1, FileSystemRights.Modify, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow))
 dInfo.SetAccessControl(dSecInfo)

 dSecInfo.AddAccessRule(New FileSystemAccessRule(UserName2, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow))
 dInfo.SetAccessControl(dSecInfo)
        
 dSecInfo.AddAccessRule(New FileSystemAccessRule(UserName3, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow))
 dInfo.SetAccessControl(dSecInfo)
        
 dSecInfo.AddAccessRule(New FileSystemAccessRule(UserName4, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit Or InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow))
 dInfo.SetAccessControl(dSecInfo)

End If

Open in new window

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Scenario:  You do full backups to a internal hard drive in either product (SBS or Server 2008).  All goes well for a very long time.  One day, backups begin to fail with a message that the disk is full.  Your disk contains many, many more backups th…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question