我試圖採取所有權和更改在C#中的文件的ACL,但即使作爲管理員,我得到異常運行:SetAccessControl「非法操作」,即使以管理員身份
System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
用戶運行該程序有能力通過Windows界面獲取所有權和更改權限。
我的代碼:
string fileName = @"C:\temp\mount\Windows\System32\Boot\en-US\winload.exe.mui";
FileSecurity fileSec = File.GetAccessControl(fileName);
fileSec.SetOwner(WindowsIdentity.GetCurrent().User);
File.SetAccessControl(fileName, fileSec); //exception thrown here
我甚至增加了一個檢查,以確保當前用戶是管理員組的成員:
WindowsIdentity wi = WindowsIdentity.GetCurrent();
WindowsPrincipal wp = new WindowsPrincipal(wi);
bool isAdmin = wp.IsInRole(WindowsBuiltInRole.Administrator); //returns true
背景資料:我創建一個WinPE映像,需要替換winload.exe.mui文件。
此外,此文件的當前權限僅授予對「受信任的安裝程序」的完全訪問權限。
我在Windows 7
Nope.jpg http://en.wikipedia.org/wiki/Windows_Resource_Protection不知道可以用什麼樣的API來解決這個事,但說「的win32」給我。 – Will