1

ファイルの所有者を に変更し、オブジェクトEveryoneを許可するにはどうすればよいですか?EveryoneFull Access

これに使用できる API はありますか? P/Invoke を使用する必要がありますか?

私はどこでも検索しましたが、これを行うものは何も見つかりません。

4

2 に答える 2

8

実際、これに使用できる API があります。System.IO 名前空間のFile.SetAccessControlメソッドを確認することをお勧めします。

// Read the current ACL details for the file
var fileSecurity = File.GetAccessControl(fileName);

// Create a new rule set, based on "Everyone"
var fileAccessRule = new FileSystemAccessRule(new NTAccount("", "Everyone"),
      FileSystemRights.FullControl, 
      AccessControlType.Allow);

// Append the new rule set to the file
fileSecurity.AddAccessRule(fileAccessRule);

// And persist it to the filesystem
File.SetAccessControl(fileName, fileSecurity);

前述の記事には、ACL に関するすばらしいことがたくさんあります。

于 2013-07-20T15:23:57.567 に答える