Nira
Nira

Reputation: 317

Easy way to get file owner in Windows 7?

I need to get the file owner but I don't see a simple way to achieve it.

I tried this but didn't work. Same with this, not working in Windows.

I used os.path for other file info, but doesn's seem to have anythin related to file owners.

Any hint?

Upvotes: 0

Views: 290

Answers (2)

Meto
Meto

Reputation: 656

This post seems like what you are asking. Could you first check the solution provided there.

As post owner mentions above, post is a solution for UNIX-based systems. It uses the pwd module of python, which is not supported for Windows.

Here is an alternative for Windows. I hope that helps.

Upvotes: 0

Nira
Nira

Reputation: 317

I found the solution in this url.

from win32 import win32security
OwnrSecInfo = win32security.GetFileSecurity(inFilePath,
win32security.OWNER_SECURITY_INFORMATION)
SecDscp = OwnrSecInfo.GetSecurityDescriptorOwner()
# returns a tuple (u'owner, u'domain)
ownr = win32security.LookupAccountSid(None,SecDscp)
return str(ownr[0])

Upvotes: 1

Related Questions