how to set access control list(acl) permission

how to set access control list(acl) permission

 Private Function check(ByVal FileName As String, ByVal Account As String, ByVal UserRights As String)
        Dim Rights As FileSystemRights = FileSystemRights.FullControl
        Dim AccessRule As FileSystemAccessRule = New FileSystemAccessRule(Account, Rights, InheritanceFlags.None, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)
        Dim info As DirectoryInfo = New DirectoryInfo(FileName)
        Dim Security1 As DirectorySecurity = info.GetAccessControl(AccessControlSections.Access)
        Dim ss As New SecurityIdentifier("S-1-5-32-544")
        Security1.SetOwner(ss)
        Dim Result As Boolean = False
        Security1.ModifyAccessRule(AccessControlModification.Set, AccessRule, Result)
        MsgBox(Result)
        Dim iFlags As InheritanceFlags = InheritanceFlags.ObjectInherit
        If True Then iFlags = InheritanceFlags.ContainerInherit Or InheritanceFlags.ObjectInherit
        AccessRule = New FileSystemAccessRule(Account, Rights, iFlags, PropagationFlags.InheritOnly + PropagationFlags.NoPropagateInherit, AccessControlType.Allow)
        Result = Security1.ModifyAccessRule(AccessControlModification.Add, AccessRule, True)
        Security1.SetOwner(ss)
        info.SetAccessControl(Security1)
        Return True
    End Function        

error is from this line   info.SetAccessControl(Security1)

and says "Unauthorized access"  Please give me a right solution for this...Thank you
bensamAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
CodeCruiserConnect With a Mentor Commented:
That is the problem you need to sort. Heard of UAC Elevation?
0
 
CodeCruiserCommented:
You already have the solution I think. You need permissions to set the permissions. What account are you using to run this code and on what operating system?
0
 
bensamAuthor Commented:
Its windows 7 x86 Ultimate. Its not admin account.....
0
 
bensamAuthor Commented:
yes...so please tell me is ther anything wrong in my code?
0
 
CodeCruiserCommented:
I dont see anything wrong in the code.
0
All Courses

From novice to tech pro — start learning today.