3
我正在開發C#應用程序。如何從不存在的用戶擁有的文件夾中刪除ACL
我需要改變的ACL一個文件夾,這樣做我正在我的程序作爲提升的管理員,一切工作正常。
的問題是,如果擁有該文件夾的用戶得到了從系統中刪除,然後當我試圖把我得到授權例外的文件夾的所有權。
這是失敗的代碼:
using (new PrivilegeEnabler(Process.GetCurrentProcess(), Privilege.TakeOwnership))
{
var directorySecurity = directoryInfo.GetAccessControl();
directorySecurity.SetOwner(WindowsIdentity.GetCurrent().User);
Directory.SetAccessControl(directoryInfo.FullName, directorySecurity);
}
就行發生異常:directoryInfo.GetAccessControl();
PrivilegeEnabler是在Process Privileges中定義的類,它用於獲取文件的所有權。
您可以發佈stacktrace和完整的異常消息嗎? – Luxspes 2012-07-15 10:52:09
[解釋](http://stackoverflow.com/questions/11384220/getnamedsecurityinfo-returns-error-access-denied5-when-writting-owner-of-a-rem/11385551#11385551)。簡而言之,如果您沒有權限讀取權限,您唯一可以做的就是取得所有權。所以你需要擁有所有權,然後讀取和更新ACL。我不知道如果你可以在C#中方便地做到這一點。 – arx 2012-07-15 11:28:57
[這個問題]的答案(http://stackoverflow.com/questions/5241718/taking-ownership-of-files-with-broken-permissions)解釋瞭如何做到這一點。 – arx 2012-07-15 11:34:22