无法将文件所有者设置为 NT SERVICE\TrustedInstaller
使用资源管理器,我可以将我创建的文件的所有者设置为“NT SERVICE\TrustedInstaller”,并且它确实得到了设置。我已经用 DIR /Q 验证了。
但是,当我在 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)
知道我做错了什么吗?
Using explorer I can set the owner of a file I have created to "NT SERVICE\TrustedInstaller" and it does get set. I have verified with DIR /Q.
But when I use the following C# code on Windows 7 SP1 X64 :
FileInfo info = new FileInfo("TrustedFile.txt");
FileSecurity security = info.GetAccessControl();
NTAccount Sid = new NTAccount("NT SERVICE\\TrustedInstaller");
security.SetOwner ( Sid );
info.SetAccessControl( security );
I get the following exception, event when running with Administrator privileges.
**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)
Any idea what I am doing wrong ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须模拟一个有权在 ASP.NET 中执行此操作的 Windows 用户。
模拟通常用于 asp.net 中的数据库登录。
You have to impersonate a windows user that will have the rights to do so inside asp.net.
Impersonation is usually done for for Database login inside asp.net.