Question

I am trying to determine the user who created a particular file like so:

string path = "C:\\TheFile.dat";
string user = System.IO.File.GetAccessControl(path).GetOwner(typeof(System.Security.Principal.NTAccount)).ToString();

When the file was created by a user who was not a member of the Administrators user group, the user's username was returned. However, when the file was created by someone who was a member of the Administrators user group, "Domain\Administrators" was returned.

Can anyone think why this might happen and how I can ensure that an actual user name is returned?

Thanks.

Was it helpful?

Solution

That is the default behavior of operating system itself. Just created a new file and follow: 'right click > security tab > advanced > owner' and you'll see that if you're the administrator, there will be two entries in the owner tab. First one 'Administrators' second one the user that created the file. If this is the client's computer, this will always be the default behavior. The reason is: If a user is an administrator, then the files they created are considered to be owned by the whole administrators group, not the individual user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top