Enumerating members of a Local Group


This code shows to find all members of a local group on a computer. It uses the NetLocalGroupGetMembers() from the win32net module.


 


Python Example:

# —————————————-
#requires win32 extensions for pythoon

import os
import win32net
import win32netcon
import pprint

def get_members_of_local_group( computername, groupname ) :
resume = 0
level = 2
retval = []
while (1) :
data, total, resume=win32net.NetLocalGroupGetMembers( computername , groupname,2,resume)
retval.extend( data )
if (resume==0) :break
return retval

the_computer = os.environ[‘computername’]
the_group = ‘Administrators’
users = get_members_of_local_group( the_computer, the_group)

pprint.pprint(users)
# —————————————-


Comments (0)