Setting Directory Permissions in VB.NET

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I want to be able to take ownership of a folder, but struggling to achieve this.
I can assign a user full control to a folder using:

<pre>Dim FolderPath As String = "C:testmyfolder" [/code]
<pre> Dim UserAccount As String = "domain1testuser" [/code]
<pre>Dim FolderInfo As IO.DirectoryInfo = New IO.DirectoryInfo(FolderPath) [/code]
<pre>Dim FolderAcl As New DirectorySecurity[/code]
<pre> FolderAcl.AddAccessRule(New FileSystemAccessRule(UserAccount, FileSystemRights.FullControl, InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow))[/code]
<pre> FolderInfo.SetAccessControl(FolderAcl)[/code]
I have tried using FileSystemRights.TakeOwnership but to no avail.

Any assistance is much appreciated.
:O)
I am using Win7 PRO and Visual Studio 2010 PRO

View the full article
 
Back
Top