0
使用資源管理器我可以將我創建的文件的所有者設置爲「NT SERVICE \ TrustedInstaller」,並且它已被設置。我已經通過DIR/Q進行了驗證。無法將文件所有者設置爲NT SERVICE TrustedInstaller
但是當我使用的Windows 7 SP1 X64下面的C#代碼:
FileInfo info = new FileInfo("TrustedFile.txt");
FileSecurity security = info.GetAccessControl();
NTAccount Sid = new NTAccount("NT SERVICE\\TrustedInstaller");
security.SetOwner (Sid);
info.SetAccessControl(security);
我得到下面的異常,事件以管理員權限運行時。
**System.InvalidOperationException: The security identifier is not allowed to be the owner of this object.**
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, SafeHandle handle, AccessControlSections includeSections, Object excepti
onContext)
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections, Object exceptionContext)
at System.Security.AccessControl.NativeObjectSecurity.Persist(String name, AccessControlSections includeSections)
at System.Security.AccessControl.FileSystemSecurity.Persist(String fullPath)
at System.IO.File.SetAccessControl(String path, FileSecurity fileSecurity)
at System.IO.FileInfo.SetAccessControl(FileSecurity fileSecurity)
at SetFileOwner.Program.Main(String[] args)
任何想法我做錯了什麼?
你爲什麼想這樣做?只有系統文件屬於該用戶,我的猜測是你不是系統... – asveikau