MATLAB Answers

Find out "Owner" of a file as displayed by Windows Explorer

95 views (last 30 days)
I've seen some files on the FEX that allow you to get creation date / last modified date of a particular file
but does anybody know how to get the name of the "Owner" of a file? (Which is another thing displayed by Windows Explorer so it has to be accessible somehow??)


Jan on 8 Jun 2012
Where do you see the owner in the Windows explorer? Do you mean: Context menu -> Properties -> Security -> Advanced -> Owner?
Darin McCoy
Darin McCoy on 8 Jun 2012
You can find details on how to show the Owner column here...
Jan on 9 Jun 2012
Thanks, Darin! Now I understand where you find the owner.

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 9 Jun 2012
Here's one way:
fileName = 'test.m'; % Some file you're interested in.
commandString = sprintf('dir %s /Q > owner_of_%s.txt', ...
fileName, fileName);
filebrowser; % Optional - Show current folder panel
% Now open the txt file you just created
% and parse it to find the owner.


Sign in to comment.

More Answers (1)

Jan on 9 Jun 2012
You can use .NET:
finfo = System.IO.FileInfo(FileName);
dummyAccount = System.Security.Principal.NTAccount('dummy');
Owner = char(finfo.GetAccessControl.GetOwner(GetType(dummyAccount)).Value.ToString);
There must be a more direct method to get the NTAccount type instead of creating a dummy account.
The Windows API methods are not trivial and I hesitate to implement them in a function similar to GetFileTime.


Darin McCoy
Darin McCoy on 11 Jun 2012
not sure how to accept both your answers? but they both worked (so i accepted Image's and voted for yours??)....thanks for the help!
Jan on 11 Jun 2012
The .NET method includes the host name also, such that file owners of network drives are identified uniquely. The DIR approach does not handle this and demands for a complicated parsing of a text file.

Sign in to comment.

Sign in to answer this question.