Search code examples
pythonfileowner

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?


Solution

  • 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])