gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:39 25 4
gpt4 key购买 nike

我需要哪个 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

关于C# PInvoke 通过 Win32 API 获取文件和文件夹的 ACL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15634475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com