Page 1 of 1

Problem with windows xp sp2

Posted: Tue Nov 23, 2004 6:12 pm
by DominiqueB
I use this code to list all computers present on a LAN, it works ok with w98se, win2k but return an empty list on xp sp2 !

Is there a spécial param to set up on xp to let an app to enum ressources on a LAN ?

Code: Select all

;***********************************************************************************
; List all PC's name presents on the local network.
;***********************************************************************************
;   Params  : None
;   Return  : List of PC's names separated by a TAB, string
Global ListPC.s

Procedure EnumAll(*nr.NETRESOURCE) 
  tempnr.NETRESOURCE 
  hEnum.l 
  Entries.l 
  nSize.l 
  ec.l 
  x.l 
  j.l 
  Entries = -1 
  nSize = 65536 ;16384
  
  ec = WNetOpenEnum_(#RESOURCE_GLOBALNET, #RESOURCETYPE_ANY, #NULL, *nr, @hEnum) 
  *Buffer=AllocateMemory(nSize)
  ec = WNetEnumResource_(hEnum,@Entries,*Buffer,@nSize) 
  
  ;MessageRequester("Nb entrées: ", Str(Entries), 0)
  For x = 1 To Entries 
    j = (x-1)*SizeOf(NETRESOURCE) 
    tempnr\dwDisplayType  = PeekL(*Buffer+j+8) 
    tempnr\dwUsage        = PeekL(*Buffer+j+12) 
    tempnr\lpRemoteName   = PeekL(*Buffer+j+20) 
    RemoteName.s="" 
    
    If tempnr\lpRemoteName And (tempnr\dwDisplayType = #RESOURCEDISPLAYTYPE_SERVER)
      RemoteName = PeekS(tempnr\lpRemoteName)
      ListPC + RemoteName + Chr(9)
      ;MessageRequester("PC trouvé: ", ListPC, 0)
    EndIf
    
    If (tempnr\dwUsage & #RESOURCEUSAGE_CONTAINER) 
      EnumAll(tempnr) 
    EndIf 
  Next 
  
  WNetCloseEnum_(hEnum) 
EndProcedure

ProcedureDLL LitNet()
  ; Ici il faut remettre à vide cette chaine car elle est globale à la DLL et n'est donc créée
  ; qu'au chargement initial de la DLL. Sinon la liste ne fera que s'allonger à chaque appel en
  ; ne perdant pas son contenu !
  ListPC = ""
  EnumAll(#NULL)
  ListPC = Left(ListPC, Len(ListPC) - 1)
  ;MessageRequester("Liste des PCs: ", ListPC, 0)
  ProcedureReturn @ListPC
EndProcedure
Any help is welcome.

Dominique

Posted: Tue Nov 23, 2004 6:27 pm
by GPI
deactivate the internal windows-XP-SP2-Firewall.

Thank's GPI

Posted: Tue Nov 23, 2004 6:57 pm
by DominiqueB
It was not about the FireWall !
It seams the behaviour of xp is <> on w2k or w98se ! I only completed all fields of the structure by doing this:

Code: Select all

    tempnr\dwScope        = PeekL(*Buffer+j+0) 
    tempnr\dwType         = PeekL(*Buffer+j+4) 
    tempnr\dwDisplayType  = PeekL(*Buffer+j+8) 
    tempnr\dwUsage        = PeekL(*Buffer+j+12) 
    tempnr\lpLocalName    = PeekL(*Buffer+j+16) 
    tempnr\lpRemoteName   = PeekL(*Buffer+j+20) 
    tempnr\lpComment      = PeekL(*Buffer+j+24) 
    tempnr\lpProvider     = PeekL(*Buffer+j+28)
Instead of only retreiving a part of it.

All works everywhere now !

Dominique

oops !

Posted: Wed Nov 24, 2004 11:09 am
by DominiqueB
Code corrected, i had to use a &, not an and !

Code: Select all

    If (tempnr\dwUsage & #RESOURCEUSAGE_CONTAINER) 
      EnumAll(tempnr) 
    EndIf
My code was taken from a PowerBasic one, and in this language the and was used !

Dominique