Skip to content

Instantly share code, notes, and snippets.

@jthmiranda
Created September 7, 2013 23:44
Show Gist options
  • Save jthmiranda/6480504 to your computer and use it in GitHub Desktop.
Save jthmiranda/6480504 to your computer and use it in GitHub Desktop.
Get the owner of the file
import win32api
import win32con
import win32security
FILENAME = "temp.txt"
open (FILENAME, "w").close ()
print "I am", win32api.GetUserNameEx (win32con.NameSamCompatible)
sd = win32security.GetFileSecurity (FILENAME, win32security.OWNER_SECURITY_INFORMATION)
owner_sid = sd.GetSecurityDescriptorOwner ()
name, domain, type = win32security.LookupAccountSid (None, owner_sid)
print "File owned by %s\\%s" % (domain, name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment