Hi,
I want to get the file owner on windows machine using python script.
Is there is any way to do that .
Please help

Thanks,
Kamal

What kind of files are you talking about?

Tim Golden is your friend...

http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html

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)

Thank you very much....

It solved my problem.

there was a problem with the codes. it uses open() with a "write" mode. if the input files are in a graphic format like jpg, emf, or pdf, it will make them empty after the process.

Line 6 is there to create a file to report about, if you have preexisting file, you would leave that out, of course.

thanks for clarification. make sense to me now.