Skip to content Skip to sidebar Skip to footer

Python Get A List Of A File's Group_id Permissions In Windows?

I was able to do this for Linux in a minute, but for the life of me I can't find an answer for Windows. I tried os.stat, but from what I understand the module may not work properly

Solution 1:

After research of internet i have found one solution. (https://sites.google.com/site/hvanbelle/programming/python/python---win32security/python---win32security---list-permissions)

import os, sys
import win32security

dacl = win32security.GetNamedSecurityInfo (path,
win32security.SE_FILE_OBJECT,win32security.DACL_SECURITY_INFORMATION
).GetSecurityDescriptorDacl ()

for n_ace inrange (dacl.GetAceCount ()):
    ace = dacl.GetAce (n_ace)
    sid = ace[-1] 
    name, domain, type = win32security.LookupAccountSid (None, sid)
    

    print("%s \\%s " % (domain, name)

Solution 2:

This seems to get the info that I want.

import win32net
importwin32securitysecurity_descriptor= win32security.GetFileSecurity("my\\path", win32security.GROUP_SECURITY_INFORMATION)

win32security.LookupAccountSid(win32net.NetGetAnyDCName(), security_descriptor.GetSecurityDescriptorGroup())

Post a Comment for "Python Get A List Of A File's Group_id Permissions In Windows?"