DirectoryInfo.GetAccessControl 方法总是失败

DirectoryInfo.GetAccessControl method always fails

我试图获取 'current user' 文件夹的访问信息。 但是这段代码总是return "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();

谢谢 Blorgbeard。这是您告诉的替代代码。 它完美运行。

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

 var Info = new DirectoryInfo(CurrentUserName);

 var Security = Info.GetAccessControl();