本文整理匯總了Python中win32net.NetUserEnum方法的典型用法代碼示例。如果您正苦於以下問題:Python win32net.NetUserEnum方法的具體用法?Python win32net.NetUserEnum怎麽用?Python win32net.NetUserEnum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類win32net
的用法示例。
在下文中一共展示了win32net.NetUserEnum方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: UserEnum
# 需要導入模塊: import win32net [as 別名]
# 或者: from win32net import NetUserEnum [as 別名]
def UserEnum():
"Enumerates all the local users"
resume = 0
nuser = 0
while 1:
data, total, resume = win32net.NetUserEnum(server, 3, win32netcon.FILTER_NORMAL_ACCOUNT, resume)
verbose("Call to NetUserEnum obtained %d entries of %d total" % (len(data), total))
for user in data:
verbose("Found user %s" % user['name'])
nuser = nuser + 1
if not resume:
break
assert nuser, "Could not find any users!"
print "Enumerated all the local users"
示例2: _get_system_users
# 需要導入模塊: import win32net [as 別名]
# 或者: from win32net import NetUserEnum [as 別名]
def _get_system_users(cls):
"""Return all users defined on the Windows system."""
# XXX - Does Windows allow usernames with chars outside of
# ASCII set? In that case we need to convert this to unicode.
return [entry['name'] for entry in
win32net.NetUserEnum(None, 0)[0]]
示例3: enum_users
# 需要導入模塊: import win32net [as 別名]
# 或者: from win32net import NetUserEnum [as 別名]
def enum_users(self):
usernames = []
resume_handle = 0
while True:
try:
users_info, total, resume_handle = win32net.NetUserEnum(
None, 0, win32netcon.FILTER_NORMAL_ACCOUNT, resume_handle)
except win32net.error as ex:
raise exception.CloudbaseInitException(
"Enumerating users failed: %s" % ex.args[2])
usernames += [u["name"] for u in users_info]
if not resume_handle:
return usernames
示例4: run
# 需要導入模塊: import win32net [as 別名]
# 或者: from win32net import NetUserEnum [as 別名]
def run(self):
silent = positive(self.parameters['SILENT'].value)
activeroot = self.parameters['ACTIVEROOT'].value
import win32net
ip = get_address_from_active_root(activeroot)
if ip is None:
log.err('Cannot get proper address for active root.')
return None
# get all users
rh = 0
while True:
users = win32net.NetUserEnum(ip, 1, rh)
unixusers = [] # prepare list of unix-style values
for user in users[0]:
username = user['name']
uid = str(win32net.NetUserGetInfo(ip, username, 4)['user_sid'])[6:].split('-')[-1]
admin = is_admin(username, self.parameters['ACTIVEROOT'].value)
if not silent:
if admin:
log.ok('User %s - %s (Administrator)' % (uid, username))
else:
log.ok('User %s - %s' % (uid, username))
unixusers.append([username, None, uid, None, None, None, None, admin])
#db['analysis'].add_user(activeroot, uid, username, admin)
result = db['analysis'].add_users(activeroot, unixusers, USERS_UNIXLIKE)
if result == DB_ERROR:
log.err('Cannot insert users into DB.')
else:
if not silent:
log.ok('%d users added/updated.' % (len(unixusers)))
#groups = win32net.NetLocalGroupEnum(ip, 1)
#groups = win32net.NetUserGetLocalGroups(ip, username, 2)
# TODO how to get GID????
#for group in groups[0]:
# print(group)
# print(win32net.NetLocalGroupGetInfo(ip, group['name'], 1))
# insert ug
if rh == 0:
break
return None