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.
使用资源管理器我可以将我创建的文件的所有者设置为“NT SERVICE \ TrustedInstaller”,并且它确实已设置。我已经用DIR / Q验证了。
But when I use the following C# code on Windows 7 SP1 X64 :
但是当我在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 );
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 ?
知道我做错了什么吗?
1 个解决方案
#1
0
You have to impersonate a windows user that will have the rights to do so inside asp.net.
您必须模拟一个Windows用户,该用户有权在asp.net内执行此操作。
Impersonation is usually done for for Database login inside asp.net.
模拟通常是为了在asp.net中进行数据库登录。
#1
0
You have to impersonate a windows user that will have the rights to do so inside asp.net.
您必须模拟一个Windows用户,该用户有权在asp.net内执行此操作。
Impersonation is usually done for for Database login inside asp.net.
模拟通常是为了在asp.net中进行数据库登录。