Get file owner in Windows

R.Marquez ny_r_marquez at yahoo.com
Sat Nov 10 09:53:40 EST 2001


Thak you for the response, but I get an empthy string as a result.
(What is the /q switch supposed to do?).  Any way, I was able to find
that in ActiveState's site there is a way to do this, with Perl.  Here
is the link:

http://aspn.activestate.com/ASPN/Mail/Message/perl-NTAdmins/680179

I was also able to find a solution by Microsoft, in VB.

http://support.microsoft.com/support/kb/articles/Q218/9/65.asp

The summary of that article says:
Retrieving the owner of a file requires obtaining the security
descriptor for the file, then using the security descriptor to get a
pointer to the owner's Security Identifier (SID). Finally, you use the
owner's SID to obtain the owner and domain name of the file.

Someone named Itamar posted this same question to the Python-win32
mailing list:
http://mail.python.org/pipermail/python-win32/2001-May/000053.html
Here is what it says:

	lets say I want to get the security information on a
	file. So I do:
	
	>>> o = win32security.GetFileSecurity(r"c:\mingc.pyd",
	win32security.OWNER_SECURITY_INFORMATION)
	>>> o
	<PySECURITY_DESCRIPTOR object at 010E9350>
	
	
	So what do I do with 'o' now in order to get the
	owner? I tried:
	
	>>> s = win32security.SID(o)
	>>> win32security.LookupAccountSid(None, s)
	Traceback (innermost last):
	  File "<interactive input>", line 1, in ?
	api_error: (1332, 'LookupAccountSid', 'No mapping
	between account names and security IDs was done.')
	
	What am I doing wrong?

No one responded to his post.  I get the same results that he does.  I
have also looked through Mark's "Pyhton Programming on Win32" (good
book, by the way), but it does not seem to have this information
either.  Does anyone have the knowhow to make Itamar's code work? 
Thanks.

PS: <a href="http://linuxtoday.com/">Just testing.</a>



More information about the Python-list mailing list