Link to home
Start Free TrialLog in
Avatar of bensam
bensamFlag for India

asked on

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
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

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?
Avatar of bensam

ASKER

Its windows 7 x86 Ultimate. Its not admin account.....
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bensam

ASKER

yes...so please tell me is ther anything wrong in my code?
I dont see anything wrong in the code.