win32net.NetUserEnum

Here are the examples of the python api win32net.NetUserEnum taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

11 Examples 7

Example 1

Project: pysecdump
Source File: users.py
View license
    def get_filtered(self, ):
        if self.users == []:
            #try:
                level = 1
                resume = 0
                while True:
                    userlist, total, resume = win32net.NetUserEnum(wpc.conf.remote_server, level, 0, resume, 999999)
                    #print u
                    for u in userlist:
                        # self.users.append(user['name'])
                        #try:
                            sid, name, type = wpc.conf.cache.LookupAccountName(wpc.conf.remote_server, u['name'])
                            self.users.append(user(sid))
                        #except:
                        #    print "[E] failed to lookup sid of %s" % user['name']
                    if resume == 0:
                        break
        return self.users

Example 2

Project: winsys
Source File: accounts.py
View license
    def __iter__(self):
        resume = 0
        while True:
            users, total, resume = wrapped(win32net.NetUserEnum, self.system, 0, FILTER.NORMAL_ACCOUNT, resume)
            for user in users:
                yield User.from_string(user['name'])
            if resume == 0: break

Example 3

Project: WAPT
Source File: win32netdemo.py
View license
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"

Example 4

Project: WAPT
Source File: accounts.py
View license
    def __iter__(self):
        resume = 0
        while True:
            users, total, resume = wrapped(win32net.NetUserEnum, self.system, 0, FILTER.NORMAL_ACCOUNT, resume)
            for user in users:
                yield User.from_string(user['name'])
            if resume == 0: break

Example 5

Project: TrustRouter
Source File: win32netdemo.py
View license
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")

Example 6

Project: HoneyConnector
Source File: authorizers.py
View license
        @classmethod
        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]]

Example 7

Project: HoneyConnector
Source File: authorizers.py
View license
        @classmethod
        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]]

Example 8

Project: seafdav
Source File: nt_domain_controller.py
View license
    def _isUser(self, username, domain, server):
        resume = "init"
        while resume:
            if resume == "init":
                resume = 0
            try:
                users, _total, resume = win32net.NetUserEnum(server, 0, win32netcon.FILTER_NORMAL_ACCOUNT, 0)
                # Make sure, we compare unicode
                un = username.decode("utf8").lower()
                for userinfo in users:
                    uiname = userinfo.get("name")
                    assert uiname
                    assert isinstance(uiname, unicode)
                    if un == userinfo["name"].lower():
                        return True
            except win32net.error, e:
                _logger.exception("NetUserEnum: %s" % e)
                return False
        _logger.info("User '%s' not found on server '%s'" % (username, server))
        return False

Example 9

Project: pysecdump
Source File: users.py
View license
    def get_all(self):
        if self.users == []:
            #try:
                level = 0
                resume = 0
                while True:
                    userlist, total, resume = win32net.NetUserEnum(wpc.conf.remote_server, level, 0, resume, 999999)
                    #print u
                    for u in userlist:
                        # self.users.append(user['name'])
                        #try:
                            sid, name, type = wpc.conf.cache.LookupAccountName(wpc.conf.remote_server, u['name'])
                            self.users.append(user(sid))
                        #except:
                        #    print "[E] failed to lookup sid of %s" % user['name']
                    if resume == 0:
                        break
            #except:
            #    print "[E] NetUserEnum failed"
        return self.users

Example 10

Project: wsgidav
Source File: nt_domain_controller.py
View license
    def _isUser(self, username, domain, server):
        resume = "init"
        while resume:
            if resume == "init":
                resume = 0
            try:
                users, _total, resume = win32net.NetUserEnum(
                    server, 0, win32netcon.FILTER_NORMAL_ACCOUNT, 0)
                # Make sure, we compare unicode
                un = username.decode("utf8").lower()
                for userinfo in users:
                    uiname = userinfo.get("name")
                    assert uiname
                    assert isinstance(uiname, unicode)
                    if un == userinfo["name"].lower():
                        return True
            except win32net.error as e:
                _logger.exception("NetUserEnum: %s" % e)
                return False
        _logger.info("User '%s' not found on server '%s'" % (username, server))
        return False

Example 11

Project: wsgidav
Source File: nt_domain_controller.py
View license
    def _isUser(self, username, domain, server):
        resume = "init"
        while resume:
            if resume == "init":
                resume = 0
            try:
                users, _total, resume = win32net.NetUserEnum(
                    server, 0, win32netcon.FILTER_NORMAL_ACCOUNT, 0)
                # Make sure, we compare unicode
                un = username.decode("utf8").lower()
                for userinfo in users:
                    uiname = userinfo.get("name")
                    assert uiname
                    assert isinstance(uiname, unicode)
                    if un == userinfo["name"].lower():
                        return True
            except win32net.error as e:
                _logger.exception("NetUserEnum: %s" % e)
                return False
        _logger.info("User '%s' not found on server '%s'" % (username, server))
        return False