Newsgroup: it.comp.lang.visual-basic
Titolo: non mi funge!

ciao io vorrei ricavare i nick degli utenti collegati sui vari pc
nella mia rete, ho modificato questo esempio trovato sul ng, ma non mi
funziona , mi restituisce solo il mio di user mentre negli altri pc
almeno trova il nome del pc qualcuno sa se si puň fare?
Option Explicit
' Costanti per i tipi di computer
Private Const SV_TYPE_WORKSTATION = &H1&
Private Const SV_TYPE_SERVER = &H2&
Private Const SV_TYPE_DOMAIN_CTRL = &H8&
Private Const SV_TYPE_NT = &H1000&
Private Const SV_TYPE_SERVER_NT = &H8000&
Private Const SV_TYPE_WINDOWS = &H400000
Private Const SV_TYPE_ALL = &HFFFF
Private Type WKSTA_USER_INFO_1
    wkui1_username As Long
    wkui1_logon_domain As Long
    wkui1_logon_server As Long
    wkui1_oth_domains As Long
End Type
' Custom Type usato da NetServerEnum
Private Type SERVER_INFO_101
   wki101_platform_id As Long
   wki101_servername As Long
   wki101_langroup As Long
   wki101_ver_major As Long
   wki101_ver_minor As Long
   wki101_lanroot As Long
End Type
' API
Private Declare Function NetServerEnum Lib "Netapi32" _
      (ByVal sServerName As String, _
       ByVal lLevel As Long, _
       vBuffer As Long, _
       lPreferedMaxLen As Long, _
       lEntriesRead As Long, _
       lTotalEntries As Long, _
       ByVal vServerType As Long, _
       ByVal sDomain As String, _
       vResume As Long) As Long
Private Declare Function NetApiBufferFree _
      Lib "Netapi32" _
      (ByVal lBuffer&) As Long
Private Declare Sub lstrcpyW _
      Lib "kernel32" _
      (vDest As Any, ByVal vSrc As Any)
Private Declare Sub RtlMoveMemory _
      Lib "kernel32" _
      (dest As Any, vSrc As Any, ByVal lSize&)
Private Declare Function NetWkstaUserGetInfo& Lib "Netapi32" (Reserved
_
As Any, ByVal lLevel&, pbBuffer As Any)
Public Function GetServers() As Variant
   Dim pstrServerName         As String
   Dim pstrUserName           As String
   Dim pstrComputerName       As String
   Dim pstrDomainName         As String
   Dim pbytBuf(512)           As Byte
   Dim pbytBuf2(512)          As Byte
   Dim plngRtn                As Long
   Dim plngSrvInfoRtn         As Long
   Dim plngPreferedMaxLen     As Long
   Dim plngNumEntriesRead     As Long
   Dim plngTotalEntries       As Long
   Dim plngServerType         As Long
   Dim plngResume             As Long
   Dim plngCnt                As Long
   Dim lSeverInfo101StructPtr As Long
   Dim plngServEnumLevel      As Long
   Dim plngPos                As Long
   Dim plngPos2               As Long
   Dim ptypServerInfo101      As SERVER_INFO_101
   Dim wk1                    As WKSTA_USER_INFO_1
   Dim pwk1                   As Long
   Dim plngLenComputerName    As Long
   Dim pvntComputers()        As Variant
   Dim pvntUsers()            As Variant
 
   'Just in case. Meglio perň una gestione
   'degli errori piů definita.
   On Error Resume Next
   ' Initialize the variables
   pstrUserName = vbNullString
   pstrComputerName = vbNullString
   pstrServerName = vbNullString
   pstrDomainName = vbNullString
   plngServEnumLevel = 101
   'Questa variabile indica il tipo di server che si
   'intende elencare. E' possibile specificare SV_TYPE_ALL,
   'includendo anche Workstation Win95, Win98 ecc.
   'In questo caso cerca server NT Server o NT workstation
   plngServerType = SV_TYPE_NT
   ' NetServerEnum rende una lista dei Server del tipo indicato
   plngRtn = NetServerEnum(pstrServerName, _
         plngServEnumLevel, plngSrvInfoRtn, _
         plngPreferedMaxLen, plngNumEntriesRead, _
         plngTotalEntries, plngServerType, _
         pstrDomainName, plngResume)
   'L'indice inizia da 1. Occorre ciclare fino al numero
   'massimo di entries indicato per ottenere i nomi dei server
   plngCnt = 1
   lSeverInfo101StructPtr = plngSrvInfoRtn
   ReDim pvntComputers(1 To plngTotalEntries)
   ReDim pvntUsers(1 To plngTotalEntries)
 
   For plngCnt = 1 To plngTotalEntries
      pstrComputerName = ""
      pstrUserName = ""
 
      'Rende la struttura leggibile a VB
      RtlMoveMemory ptypServerInfo101, ByVal lSeverInfo101StructPtr,
Len(ptypServerInfo101)
      Call NetWkstaUserGetInfo(ByVal 0&, 1, pwk1)
      RtlMoveMemory wk1, ByVal pwk1, Len(wk1)
      lstrcpyW pbytBuf(0), ptypServerInfo101.wki101_servername
      lstrcpyW pbytBuf2(0), wk1.wkui1_username
      pstrComputerName = pbytBuf
      pstrUserName = pbytBuf2
      plngPos = InStr(pstrComputerName, vbNullChar)
      plngPos2 = InStr(pstrUserName, vbNullChar)
 
      If plngPos > 0 Then
         pstrComputerName = Mid$(pstrComputerName, 1, plngPos - 1)
      End If
      If plngPos2 > 0 Then
         pstrUserName = Mid$(pstrUserName, 1, plngPos2 - 1)
      End If
      pvntComputers(plngCnt) = pstrComputerName 'pc online
      pvntUsers(plngCnt) = pstrUserName 'user online
 
      Form1.List1.AddItem pstrComputerName
      Form1.List1.AddItem pstrUserName
 
      lSeverInfo101StructPtr = lSeverInfo101StructPtr +
Len(ptypServerInfo101)
      pwk1 = pwk1 + Len(wk1)
 
   Next plngCnt
   'Rialscia il buffer
   plngRtn = NetApiBufferFree(plngSrvInfoRtn)
   'GetServers ritorna l'elenco dei server ottenuti
   GetServers = pvntComputers
End Function

non voglio sembrarti polemico, ma cerca di *isolare* il problema.......
non tutti hanno il tempo o la voglia di mettersi lě a provare un programma
di decine e decine di righe.......
oltretutto vedo che ci sono funzioni API, il listato č lungo, insomma,
potrebbe essere piů produttivo per te e per gli altri se tu cominciassi a
fare un po' di debug, cosě da capire dove puň essere il problema....
che ne dici?
:-))
good debugging!!!
--
Igor Damiani
ig...@igordamiani.it
http://www.igordamiani.it
ICQ : 11847262

 fare un po' di debug, così da capire dove può essere il problema....
