2011-08-01 2 views
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) 

私が間違っていることは何ですか?

+0

なぜこれをやりたいですか?そのシステムのファイルだけがそのユーザーによって所有されています。私はあなたがシステムではないと推測しています... – asveikau

答えて

0

asp.netの中でそうする権利を持つWindowsユーザーに偽装する必要があります。

asp.net内のデータベースログインのために通常偽装が行われます。