c# - GetEffectiveRightsFromAcl throws invalid acl error -


I am trying to gain effective rights in the user's C # using the interop. The following code is being used:

  public static fileSystemRights GetFileEffectiveRights (string filename, string username) {IntPtr pDacl, pZero = IntPtr.Zero; Int Mask = 0; UIT ArrayRighton = GetNamedSecurityInfo (filename, SEOOZEETEASEIFIIlOJJCT, SEC., DACL, OutPGro, OutPGro, Out PDACL, OutPGro, OutPGro); If (errorReturn! = 0) {new exception throw ("Win error:" + error return); } Programs. TRUSTEE pTrustee = new TRUSTEE (); Ptrustee.pmultipleTrustee = IntPtr.Zero; Ptrustee.MultipleTrusteeOperation = (int) program. MULTIPLE_TRUSTEE_OPERATION.NO_MULTIPLE_TRUSTEE; PTrustee.ptstrName = Username; Ptrustee.TrusteeForm = (int) program. TRUSTEE_FORM.TRUSTEE_IS_NAME; Ptrustee.TrusteeType = (int) program. TRUSTEE_TYPE.TRUSTEE_IS_USER; ErrorReturn = GetEffectiveRightsFromAcl (PDACL, Ref pTrustee, Ref Mask); If (errorReturn! = 0) {new exception throw ("Win error:" + error return); } Return (filesystems) mask; }  

Unless I start using the FileAccessRule and FileInfo classes to modify the ACL structure, and then I start getting the Windows Error 1336: ERROR_INVALID_ACL. Even if I debug the process, this is what happens: I call GetFileEffectiveRights once, stop the process, change ACL via Windows API, and start over again and getFileEffectiveRights again Call (1st call is successful but second gives 1336).
What's going wrong?
PS: I'm developing on Windows 7 using VS 2008 and .NET 3.5.
Edit: I get an error only, when I try to get the right to a file for which the non-hereditary AE Windows GUI / C # file was added via API.

The problem is in the second part of your problem, changing the ACL through the Windows API

< P> The order of ACE in DACL is very important. For example you will find the full details about the correct AEE order and a code example.

If you remain in the same problem, then just post the code example of the modification of ACL in your question.


Comments