Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27210

[RESOLVED] Setting File/Folder Permissions (No Over Write)

$
0
0
Hi All,

I'm using the following code to set permissions, this is working...however its overwriting any previous permissions on there.

For example my folder has the following Users/Groups attached to it;

CREATOR OWNER
SYSTEM
Administrators
Users
TestUser
Remote Desktop Users

After I run the following VB Code the Users/Groups I'm left with are
CREATOR OWNER
SYSTEM
Administrators
Users
TestUser

As you can see this code is removing all the permissions then adding the Inherited permissions back and adding my specified user

Code:

  Dim FolderPath As String = "C:\Test"
        Dim UserAccount As String = "Domain.com\TestUser"

        Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath)
        Dim FolderAcl As New DirectorySecurity

        Try
            'Dim Rule As FileSystemAccessRule = New FileSystemAccessRule(UserAccount, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)

            FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))
            FolderInfo.SetAccessControl(FolderAcl)
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Test File/Folder Permissions", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try

Thanks

Swain90

Viewing all articles
Browse latest Browse all 27210


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>