[英]C# get file owner in Windows
我想使用下面的代码获取文件的所有者
File.GetAccessControl(filename).GetOwner(typeof(SecurityIdentifier)).Translate(typeof(NTAccount))
但是,它给了我BUILTIN \\ Administrators作为所有者,但我可以在文件资源管理器中看到所有者是Domain \\ MyUserName。
为什么会发生这种情况以及如何解决?
编辑: 此链接说明发生了什么。 它与管理员组中的用户创建的文件以及Windows如何处理这些文件的所有者有关。
我能够通过这个获得文件的实际所有者...不确定这是否是你需要的。 System.IO.FileInfo Fi = new System.IO.FileInfo(@"path2file");
MessageBox.Show(Fi.GetAccessControl().GetOwner(typeof(System.Security.Principal.SecurityIdentifier)).Translate(typeof(System.Security.Principal.NTAccount)).ToString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.