简体   繁体   English

无法(尚未)访问SD时,在C#中设置文件/目录所有者

[英]Setting File / Directory Owner in C# when SD can't (yet) be accessed

Gentlement, Gentlement,

following situation. 以下情况。 There are files in a network share to which even Administrators have no permissions, permissions are set for two individual users only. 网络共享中有一些文件,即使管理员也没有权限,仅为两个用户设置权限。 In the process of an operation to detect and fix such issues (because this is not desired) I need to add access to the Administrators. 在检测和修复此类问题的操作过程中(因为这不是必需的),我需要向管理员添加访问权限。

In Windows Explorer that's easy. 在Windows资源管理器中很简单。 Since I am an Administrator, I can take the ownership of a file or folder and then edit the security descriptor. 由于我是管理员,因此我可以拥有文件或文件夹的所有权,然后编辑安全描述符。

The problem is, that using FileSecurity.GetAccessControl() [or rather FileSecurity.GetAccessControl(AccessControlSections.Owner)] does not work, I am getting an UnauthorizedAccessException. 问题是,使用FileSecurity.GetAccessControl()[或更确切地说是FileSecurity.GetAccessControl(AccessControlSections.Owner)]不起作用,我收到了UnauthorizedAccessException。

However I -need- to be able to do this, anyone got a tip? 但是我-需要-能够做到这一点,有人得到了小费吗? Might P/Invoke be a solution here and if so, how would I do that? P / Invoke可能是这里的解决方案,如果可以,我该怎么做?

I am confused by this matter, because I thought it should work, since it does work in the Explorer ... 我对此事感到困惑,因为我认为它应该可以工作,因为它确实可以在资源管理器中工作...

Thanks a bomb! 谢谢炸弹! - Chris - 克里斯

Just in case anyone is interested, I found a solution that uses PInvoke and does in fact work, everything else I have tried, including activating the privilege and using the .Net methods, failed. 以防万一有人感兴趣,我找到了一个使用PInvoke并确实有效的解决方案,而我尝试过的其他所有尝试,包括激活特权和使用.Net方法,都失败了。

http://blog.mikeobrien.net/2009/11/taking-ownership-and-setting-admin.html http://blog.mikeobrien.net/2009/11/taking-ownership-and-setting-admin.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM