error with win32net, function and unicode

mvillain at gosystemes.fr mvillain at gosystemes.fr
Mon Aug 26 12:08:08 EDT 2002


Hi,
I have a look at the Python Windows Network Management: win32net
documentation
The code bellow is especially interesting...

Listing all machines in Domain
If you need to touch every machine in your domain, NetServerEnum can help
you out.
Based off of the constants defined in win32netcon, you can look for
different classes of machines.
For example, win32netcon.SV_TYPE_DOMAIN_BAKCTRL, will single out backup
domain controllers.
Here we use SV_TYPE_ALL to get everything.
def getall_boxes(domain='',server=''):
    res=1
    wrk_lst=[]
    try:
        while res: #loop until res2
          (wrk_list2,total,res2)=win32net.NetServerEnum
('',100,win32netcon.SV_TYPE_ALL,server,res,win32netcon.MAX_PREFERRED_LENGTH)
          wrk_lst.extend(wrk_list2)
          res=res2
    except win32net.error:
        print traceback.format_tb(sys.exc_info()[2]),'\n',sys.exc_type,'
\n',sys.exc_value

    final_lst=[]
    for i in wrk_lst:
      final_lst.append(str(i['name']))
    return final_lst

print getall_boxes('bedrock',r'\\rubble')

.. and run quite well
I would like to put the name of the server in  a text file and then in a
variable named serv
I wrote \\rubble in the text file
and in the code:
...
print getall_boxes(domain,serv)
...
But it doesn't work: "this computer name is not valide"
I tried some other possibilities: \\\\rubble or r\\rubble in the text
file...
But without success.
Thanks for the help
Marc

The complete error message:
['  File "D:\\python\\ManipWMI8.py", line 119, in getall_boxes\n
(wrk_list2,total,res2)=win32net.NetServerEnum(server,100,win32netcon.SV_TYPE_ALL,domain,res,win32netcon.MAX_PREFERRED_LENGTH)

n']
pywintypes.api_error
(2351, 'NetServerEnum', "Ce nom d'ordinateur n'est pas valide.")
[]






More information about the Python-list mailing list