0

Same question as here, but for Windows.

This answer works nicely in Linux:

from os import stat
from pwd import getpwuid

def find_owner(filename):
    return getpwuid(stat(filename).st_uid).pw_name

The module pwd doesn't seem to be available in Windows.

How to do that in Windows?

Raf
  • 1,628
  • 3
  • 21
  • 40
  • 1
    Does this help? https://stackoverflow.com/questions/8086412/howto-determine-file-owner-on-windows-using-python-without-pywin32?answertab=active#tab-top – Xenobiologist Nov 06 '19 at 10:20
  • 1
    http://timgolden.me.uk/python/win32_how_do_i/get-the-owner-of-a-file.html – LinPy Nov 06 '19 at 10:21
  • Both solutions tested and work fine, ie, I've managed to pull file owner username using both approaches. Using `win32security` seems a lot simpler. – Raf Nov 06 '19 at 10:32
  • 1
    With ctypes, we have to implement much of the solution at a low level, in terms of data structures, functions/methods, and even some memory management (i.e. calling `LocalFree`). However, it's useful if we wish to avoid depending on PyWin32, which is a rather large dependency. – Eryk Sun Nov 06 '19 at 12:28

0 Answers0