Receiving wrong file's group when using GetAccessControl().GetGroup()

50 Views Asked by At

I created a text file and removed all the groups except SYSTEM group.
When I am running the following code:

public static void CheckPermissions(string filePath)
{
    FileSecurity acl = new FileInfo(filePath).GetAccessControl();
    IdentityReference group = acl.GetGroup(typeof(SecurityIdentifier));
}

It shows that my group is:

{S-1-5-21-XXXXXXXXXX-XXXXXXXXXX-XXXXXXXXXX-513}

Which according to Microsoft is the group of DOMAIN_USERS.
But when I am looking through the GUI, it seems that it has only the SYSTEM group:
enter image description here

1

There are 1 best solutions below

0
E235 On

According to Microsoft, it because it gets the primary group of the owner, and not the group of the file:

Gets the primary group associated with the specified owner.