Created
September 7, 2013 23:44
-
-
Save jthmiranda/6480504 to your computer and use it in GitHub Desktop.
Get the owner of the file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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