1
我试图获取'当前用户'文件夹的访问信息。 但是,此代码始终返回“方法失败,出现意外的错误代码3,InvailedOperationException”。DirectoryInfo.GetAccessControl方法总是失败
这里是我的代码
string CurrentUserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
var Info = new DirectoryInfo("C:\\users\\"+ CurrentUserName);
var Security = Info.GetAccessControl();
“CurrentUserName”的值是什么?在我的机器上,它的形式是'DOMAIN \ username',它给出了一个不存在的文件夹.. – Blorgbeard
无论如何,最好使用'Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)'。 – Blorgbeard
感谢您的评论。我认为'CurrentUserName'应该只有用户名,而不是Domain \ username。 –