共有フォルダーからアカウントのアクセス許可を削除する小さなプログラムがあります。しかし、一部のフォルダのセキュリティ タブには、「S-1-5-21-2008445439-890656017-1691616715-1589748」のようなアカウントがあります。そのサーバーにログインして手動で削除する権限がありますが、以下のエラーのためにコードを実行できませんでした。これらのアカウントを削除するにはどうすればよいですか。ありがとう。
private void button2_Click(object sender, EventArgs e)
{
var security = Directory.GetAccessControl(txtBoxPath.Text);
var rules = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));
foreach (FileSystemAccessRule rule in rules)
{
if (rule.IdentityReference.Value == listView1.SelectedItems[0].Text)
{
string name = rule.IdentityReference.Value;
RemoveFileSecurity(txtBoxPath.Text, name,
FileSystemRights.FullControl |
FileSystemRights.Modify |
FileSystemRights.Read |
FileSystemRights.ReadAndExecute |
FileSystemRights.ReadPermissions |
FileSystemRights.Synchronize |
FileSystemRights.ListDirectory |
FileSystemRights.ChangePermissions |
FileSystemRights.Delete,
AccessControlType.Allow);
MessageBox.Show("OK");
}
}
}
public static void RemoveFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Remove the FileSystemAccessRule from the security settings.
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
タイプ 'System.Security.Principal.IdentityNotMappedException' の未処理の例外が mscorlib.dll で発生しました
追加情報: 一部またはすべての ID 参照を翻訳できませんでした。