0

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

5
Contributors
6
Replies
16
Views
7 Years
Discussion Span
Last Post by AlexWong
0

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)
0

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.

Edited by AlexWong

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.