Solved

How do I set folder permissions using VB.Net

Posted on 2011-03-21
3
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

The recent Microsoft changes on update philosophy for Windows pre-10 and their impact on existing WSUS implementations.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This tutorial will walk an individual through the steps necessary to configure their installation of BackupExec 2012 to use network shared disk space. Verify that the path to the shared storage is valid and that data can be written to that location:…
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…
Suggested Courses

628 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