Set file access rule

The follow function works on Windows XP, now I'm trying it with Windows 7, it returns an IdentityNotMappedException error, what's wrong? I also changed the requestexecutionlevel application to admin.

private static void file_accessdeny(string fileName)
{
    try
    {
        System.Security.AccessControl.FileSecurity accessdeny = System.IO.File.GetAccessControl(fileName);
        accessdeny.SetAccessRule(new System.Security.AccessControl.FileSystemAccessRule("Everyone", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Deny));
        System.IO.File.SetAccessControl(fileName, accessdeny);
    }
    catch (System.Exception E)
    {
        Console.WriteLine(E.Message);
        System.Windows.Forms.MessageBox.Show(E.Message, "access deny");
    }
}

Error: System.Security.Principal.IdentityNotMappedException: some or all identifier references cannot be translated

+5
source share
1 answer

Try this instead of code:

accessdeny.SetAccessRule(
   new System.Security.AccessControl.FileSystemAccessRule(
   new SecurityIdentifier(WellKnownSidType.WorldSid, null),
   System.Security.AccessControl.FileSystemRights.FullControl,
   System.Security.AccessControl.AccessControlType.Deny));

The error message says that “impossible to translate” is Windows telling you that when he tried to find the SID for the Everyone group (that is, translate) ... he could not find it under that name.

, Windows . , "Jeder".

+9

All Articles