开发者

Cannot set file owner to NT SERVICE\TrustedInstaller

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\\Trusted开发者_运维百科Installer");
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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜