How to enum all the users from a windows domain via python win32net module?

Tim Golden mail at timgolden.me.uk
Mon Feb 16 05:00:54 EST 2009


vimuser wrote:
> I tried the command "net user /DOMAIN" in windows console(cmd.exe),
> and it showed me all the usernames in my domain without any problems.
> But when I tried it in python with these commands :
> info=win32net.NetUserEnum("DOMAIN_NAME",1),
> info=win32net.NetUserEnum(r"\\DOMAIN_NAME",1),and
> info=win32net.NetUserEnum("\\\\DOMAIN_NAME",1), I all got the System
> Error 53 (The network path was not found) .
> 
> What should I do, if I intend to enum all the users from a windows
> domain via python win32net module?
> --
> http://mail.python.org/mailman/listinfo/python-list

<code>

import win32net
import win32netcon

dc = win32net.NetGetAnyDCName (None, None)

resume = 0
while 1:
  (_users, total, resume) = \
    win32net.NetUserEnum (
      dc,
      3,
      win32netcon.FILTER_NORMAL_ACCOUNT,
      resume,
      win32netcon.MAX_PREFERRED_LENGTH
    )
  for _user in _users:
    print _user['name'], _user['home_dir'], _user['profile']
  break
  if not resume:
    break


</code>

TJG



More information about the Python-list mailing list