bensam
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.FullContr ol
Dim AccessRule As FileSystemAccessRule = New FileSystemAccessRule(Accou nt, Rights, InheritanceFlags.None, PropagationFlags.NoPropaga teInherit, AccessControlType.Allow)
Dim info As DirectoryInfo = New DirectoryInfo(FileName)
Dim Security1 As DirectorySecurity = info.GetAccessControl(Acce ssControlS ections.Ac cess)
Dim ss As New SecurityIdentifier("S-1-5- 32-544")
Security1.SetOwner(ss)
Dim Result As Boolean = False
Security1.ModifyAccessRule (AccessCon trolModifi cation.Set , AccessRule, Result)
MsgBox(Result)
Dim iFlags As InheritanceFlags = InheritanceFlags.ObjectInh erit
If True Then iFlags = InheritanceFlags.Container Inherit Or InheritanceFlags.ObjectInh erit
AccessRule = New FileSystemAccessRule(Accou nt, Rights, iFlags, PropagationFlags.InheritOn ly + PropagationFlags.NoPropaga teInherit, AccessControlType.Allow)
Result = Security1.ModifyAccessRule (AccessCon trolModifi cation.Add , AccessRule, True)
Security1.SetOwner(ss)
info.SetAccessControl(Secu rity1)
Return True
End Function
error is from this line info.SetAccessControl(Secu rity1)
and says "Unauthorized access" Please give me a right solution for this...Thank you
Private Function check(ByVal FileName As String, ByVal Account As String, ByVal UserRights As String)
Dim Rights As FileSystemRights = FileSystemRights.FullContr
Dim AccessRule As FileSystemAccessRule = New FileSystemAccessRule(Accou
Dim info As DirectoryInfo = New DirectoryInfo(FileName)
Dim Security1 As DirectorySecurity = info.GetAccessControl(Acce
Dim ss As New SecurityIdentifier("S-1-5-
Security1.SetOwner(ss)
Dim Result As Boolean = False
Security1.ModifyAccessRule
MsgBox(Result)
Dim iFlags As InheritanceFlags = InheritanceFlags.ObjectInh
If True Then iFlags = InheritanceFlags.Container
AccessRule = New FileSystemAccessRule(Accou
Result = Security1.ModifyAccessRule
Security1.SetOwner(ss)
info.SetAccessControl(Secu
Return True
End Function
error is from this line info.SetAccessControl(Secu
and says "Unauthorized access" Please give me a right solution for this...Thank you
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?
ASKER
Its windows 7 x86 Ultimate. Its not admin account.....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes...so please tell me is ther anything wrong in my code?
I dont see anything wrong in the code.