DirectoryInfo.GetAccessControl方法总是失败

本文关键字:失败 方法 GetAccessControl DirectoryInfo | 更新日期: 2023-09-27 18:09:29

我试图获取"当前用户"文件夹的访问信息。但是这个代码总是返回"method failed with unexpected error code 3, InvailedOperationException"。

我的代码

string CurrentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
var Info = new DirectoryInfo("C:''users''"+ CurrentUserName);
var Security = Info.GetAccessControl();

DirectoryInfo.GetAccessControl方法总是失败

谢谢你。这是你告诉我的替代代码。

 string CurrentUserName = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
 var Info = new DirectoryInfo(CurrentUserName);
 var Security = Info.GetAccessControl();