DirectoryInfo.GetAccessControl method always fails

放肆的年华 提交于 2020-01-16 05:30:07

问题


I tried to get access information of 'current user' folder. But this code always return "method failed with unexpected error code 3, InvailedOperationException".

Here is my code

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

回答1:


Thank you Blorgbeard. Here is the alternative code what you told. It works perfectly.

 string CurrentUserName = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

 var Info = new DirectoryInfo(CurrentUserName);

 var Security = Info.GetAccessControl();


来源:https://stackoverflow.com/questions/39760743/directoryinfo-getaccesscontrol-method-always-fails

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!