C#PInvoke通过Win32 API获取文件和文件夹的ACL

C#PInvoke通过Win32 API获取文件和文件夹的ACL,c#,winapi,pinvoke,acl,.net,C#,Winapi,Pinvoke,Acl,.net,我需要哪个PInvoke来验证UNC路径(\UNC\?\或\?\,文件和文件夹)的权限(CanRead、CanWrite、CanExecute…)。 对于System.IO,我将使用fileInfo.GetAccessControll().GetAccessRules获取AuthorizationRuleCollection,但我无法使用System.IO,因为此命名空间不支持长路径 我知道如何找到所有者,但我没有找到其他信息的解决方案。我想我也必须使用GetNamedSecurityInfo,

我需要哪个PInvoke来验证UNC路径(\UNC\?\或\?\,文件和文件夹)的权限(CanRead、CanWrite、CanExecute…)。 对于System.IO,我将使用
fileInfo.GetAccessControll().GetAccessRules
获取
AuthorizationRuleCollection
,但我无法使用System.IO,因为此命名空间不支持长路径

我知道如何找到所有者,但我没有找到其他信息的解决方案。我想我也必须使用GetNamedSecurityInfo,但是信息非常稀少


谢谢。

解决方案是使用GetNamedSecurityInfo和参数pSecurityDescriptor以及DACL信息请求

// Get Length
var securityDescriptorLength = /* Win32 Call */ GetSecurityDescriptorLength( pSecurityDescriptor );

// Define array to copy
var securityDescriptorDataArray = new byte[ securityDescriptorLength ];

// Copy by marshal to defined array
/* Win32 Call */ Marshal.Copy( pSecurityDescriptor, securityDescriptorDataArray, 0, ( int ) securityDescriptorLength );

// If path is directory
var securityInfo = new DirectorySecurity( );
securityInfo.SetSecurityDescriptorBinaryForm( securityDescriptorDataArray );

现在您可以使用
securityInfo.GetAccessRules()

获取AccessRules文件名有多长???文件名长度不是.NET的一项功能,而是Windows本身的一项功能。您正在寻找AccessCheck Windows API吗?在本例中,请查看:@bash.d:最多2700个字符。System.IO限制为240/256,Win32调用(UNC)限制为32767。我的库可以工作,但我必须在下一个版本中提供访问检查。@SimonMourier:我会检查的。谢谢。@SimonMourier,谢谢,但这不太管用。Directory.GetAccessControl也被限制为240/256个字符(不支持unc长路径)。