Title: FW: Difficulties With win32net APIs

Hi,

I am forwarding you this message that I already sent because I didn't understand that joining the Python mailing list is not the same as joining your web site. I am now officially joined in both areas and I would like the following question posted. Btw, I modified the information below by adding the fact that I am using ActiveState Python 2.1 build 210. Thanks very much.

Mike

 -----Original Message-----
From:   Mike Cravitz 
Sent:   Thursday, May 10, 2001 11:05 AM
To:     ActiveState Python List (E-mail)
Subject:        Difficulties With win32net APIs

I am running on an NT 4.0 network and am attempting to use some of the win32net APIs to help me manage users, groups, and shares.  [Mike Cravitz]   I am using ActiveState Python 2.1 build 210. It appears I am being allowed to perform API operations on the local computer (specifying None for computer). But whenever I attempt to specify a computer name - other than None - (even the name of the computer upon which the script is running), I get the following error.

api_error: (2351, 'NetUserEnum', 'This computer name is invalid.')

One example of where this is happening is in a script that looks like this...

import win32net
import win32api
import win32netcon
import string

def listUsersOnComputer( computer ):
    loopAgain = 0
    retList   = []
    while 1:
        # Get next set of users
        entries, total, loopAgain = win32net.NetUserEnum(
                                     computer,
                                     0,
                                     win32netcon.FILTER_NORMAL_ACCOUNT,
                                     loopAgain,
                                     4096
                                     )
        # Add this set of users to the return list
        for dict in entries:
            d = { 'name': str( dict[ 'name' ] ) }
            retList = retList + [ d ]
           
        if not loopAgain: return retList

When I invoke this function with the name of the computer upon which the script is running or the name of another server in my NT domain, I get the following traceback...

Traceback (most recent call last):
  File "D:\Python21\Pythonwin\pywin\framework\scriptutils.py", line 298, in RunScript
    debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File "D:\Python21\Pythonwin\pywin\debugger\__init__.py", line 60, in run
    _GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File "D:\Python21\Pythonwin\pywin\debugger\debugger.py", line 582, in run
    _doexec(cmd, globals, locals)
  File "D:\Python21\Pythonwin\pywin\debugger\debugger.py", line 924, in _doexec
    exec cmd in globals, locals
  File "D:\MyStuff\ListUsersAndGroups.py", line 41, in ?
    listUsersOnComputer( 'SYSTEMS_MIKEC' )
  File "D:\MyStuff\ListUsersAndGroups.py", line 19, in listUsersOnComputer
    4096
api_error: (2351, 'NetUserEnum', 'This computer name is invalid.')

However, If I temporarily change the win32net.NetUserEnum call to specify None, then this works fine. So the temporary change would look like this...

        entries, total, loopAgain = win32net.NetUserEnum(
                                     None,
                                     0,
                                     win32netcon.FILTER_NORMAL_ACCOUNT,
                                     loopAgain,
                                     4096
                                     )

Please explain any misunderstandings I might have about how this is supposed to work. Thanks very much.

Mike

Reply via email to