error with win32net, function and unicode

Mark Hammond mhammond at skippinet.com.au
Tue Aug 27 02:39:15 CEST 2002


I'm not sure what this has to do with Unicode.  There are a number of 
things wrong, including use of the "res" param - this must start at zero.

The following works:

wrk_list2,total,res=win32net.NetServerEnum(server,100,win32netcon.SV_TYPE_ALL,domain)

when "server" and "domain" are both None - *not* empty strings.  Start 
with this and move towards the "real" version.

Mark.

mvillain at gosystemes.fr wrote:
> 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