Newsgroup: it.comp.lang.visual-basic
Titolo: [?] Ottenere l'elenco delle macchine in rete

Ciao
Ho bisogno, dal mio applicativo, di ottenere l'elenco
delle macchine in rete e non trovo un'API che mi dia
questo elenco.
Ho cercato sull'ultima versione di Api Guide ma non
c'e'. Eppure so che si puo'.
Qualcuno mi da una dritta ?
Grazie
Beppe

 ha scritto

www.mvps.org/vbnet
hth, j.
--
www.sundaysw.com


Mi dice 'host not found'.   Avevo gia' guardato
prima di postare la domanda ma non funzia.
Spero sia un problema temporaneo.
Ciao
Beppe

 Spero sia un problema temporaneo.
ho visto. strano.
se continua a non funzionare dimmelo, col codice di birch (due pagine di
vbnet fuse insieme) ho fatto un exe che pinga e risolve le macchine in lan,
printserver compresi. direi funzioni.
solo che birch chiede di non ridistribuire il suo codice, motivo per cui non
l'ho potuto mettere su sundaysw.
ciao, j.

 l'ho potuto mettere su sundaysw.
ehm... il fatto e' che sto lavorando anche di domenica
proprio perche' ho una fretta tremenda.
Magari potresti spedirmelo in email.   A me serve
solo capire che API usa e come.   Devo trovare
l'elenco dei PC in rete come fa Esplora Risorse,
per poi inviare a tutte un messaggio UDP (devo
rilevare le copie dello stesso programma lanciate
sulle macchine in rete.
Grazie anticipate.
Beppe

 ha scritto nel messaggio
news:acr2an$r6vla$1...@ID-56313.news.dfncis.de...

 Prova con quanto segue :
Option Explicit
Private Type RisorseDiRete
   dwScope As Long
   dwType As Long
   dwDisplayType As Long
   dwUsage As Long
   lpLocalName As Long
   lpRemoteName As Long
   lpComment As Long
   lpProvider As Long
End Type
Private Declare Function WNetOpenEnum Lib "mpr.dll" Alias _
  "WNetOpenEnumA" (ByVal dwScope As Long, ByVal dwType As Long, _
  ByVal dwUsage As Long, lpNetResource As Any, lphEnum As Long) As Long
Private Declare Function WNetEnumResource Lib "mpr.dll" Alias _
  "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, _
  ByVal lpBuffer As Long, lpBufferSize As Long) As Long
Private Declare Function WNetCloseEnum Lib "mpr.dll" _
   (ByVal hEnum As Long) As Long
Private Const RESOURCE_CONNECTED = &H1
Private Const RESOURCE_GLOBALNET = &H2
Private Const RESOURCE_REMEMBERED = &H3
Private Const RESOURCETYPE_ANY = &H0
Private Const RESOURCETYPE_DISK = &H1
Private Const RESOURCETYPE_PRINT = &H2
Private Const RESOURCETYPE_UNKNOWN = &HFFFF
Private Const RESOURCEUSAGE_CONNECTABLE = &H1
Private Const RESOURCEUSAGE_CONTAINER = &H2
Private Const RESOURCEUSAGE_RESERVED = &H80000000
Private Const GMEM_FIXED = &H0
Private Const GMEM_ZEROINIT = &H40
Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)
Private Declare Function GlobalAlloc Lib "KERNEL32" _
  (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalFree Lib "KERNEL32" _
  (ByVal hMem As Long) As Long
Private Declare Sub CopyMemory Lib "KERNEL32" Alias _
  "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, _
   ByVal cbCopy As Long)
Private Declare Function CopyPointer2String Lib _
  "KERNEL32" Alias "lstrcpyA" (ByVal NewString As _
  String, ByVal OldString As Long) As Long
Public Sub VisualizzaUtenti(ByRef Controllo As Object)
Dim hEnum As Long, lpBuff As Long, Network As RisorseDiRete
Dim cbBuff As Long, cCount As Long
Dim p As Long, res As Long, i As Long
On Error Resume Next
Controllo.AddItem " "
Controllo.Clear
If Err.Number > 0 Then Exit Sub
On Error GoTo ErrorHandler
Network.lpRemoteName = 0
cbBuff = 10000
cCount = &HFFFFFFFF
res = WNetOpenEnum(RESOURCE_GLOBALNET, _
  RESOURCETYPE_ANY, 0, Network, hEnum)
If res = 0 Then
   lpBuff = GlobalAlloc(GPTR, cbBuff)
   res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff)
   If res = 0 Then
      p = lpBuff
      For i = 1 To cCount
         CopyMemory Network, ByVal p, LenB(Network)
         Controllo.AddItem "Utenti in Rete : " & _
            PointerToString(Network.lpRemoteName)
         RisorseRete Network, Controllo
         p = p + LenB(Network)
      Next i
      End If
ErrorHandler:
On Error Resume Next
   If lpBuff <> 0 Then GlobalFree (lpBuff)
   WNetCloseEnum (hEnum)
   Controllo.AddItem "Nessun Utente Collegato", 9
End If
End Sub
Private Function PointerToString(p As Long) As String
   Dim s As String
   s = String(255, Chr$(0))
   CopyPointer2String s, p
   PointerToString = Left(s, InStr(s, Chr$(0)) - 1)
End Function
Private Sub RisorseRete(Network As RisorseDiRete, Controllo As Object)
   Dim hEnum As Long, lpBuff As Long
   Dim cbBuff As Long, cCount As Long
   Dim p As Long, res As Long, i As Long
   cbBuff = 10000
   cCount = &HFFFFFFFF
   res = WNetOpenEnum(RESOURCE_GLOBALNET, _
     RESOURCETYPE_ANY, 0, Network, hEnum)
   If res = 0 Then
      lpBuff = GlobalAlloc(GPTR, cbBuff)
      res = WNetEnumResource(hEnum, cCount, lpBuff, cbBuff)
      If res = 0 Then
         p = lpBuff
         For i = 1 To cCount
            CopyMemory Network, ByVal p, LenB(Network)
            Controllo.AddItem "Computer in Rete : #" & i & " " &
PointerToString(Network.lpRemoteName)
            p = p + LenB(Network)
         Next i
      End If
      If lpBuff <> 0 Then GlobalFree (lpBuff)
      WNetCloseEnum (hEnum)
   End If
End Sub
By Utente Win2k

 ha scritto
