Autor Tema: listar mi red  (Leído 2819 veces)

0 Usuarios y 1 Visitante están viendo este tema.

k_arlytos

  • Megabyte
  • ***
  • Mensajes: 211
  • Reputación: +2/-4
    • Ver Perfil
listar mi red
« en: Diciembre 08, 2009, 05:37:02 pm »
hola que tal por favor alguien me puede decir como puedo listar o recuperar los nombres de las pc de mi red? estado buscando pero no se como hacerlo espero que alguien me ayude
"Comentar el código es como limpiar el cuarto de baño; nadie quiere hacerlo, pero el resultado es siempre una experiencia más agradable para uno mismo y sus invitados"

ssccaann43

  • Terabyte
  • *****
  • Mensajes: 970
  • Reputación: +97/-58
    • Ver Perfil
    • Sistemas Nuñez, Consultores y Soporte, C.A.
Re:listar mi red
« Respuesta #1 en: Diciembre 09, 2009, 11:14:13 am »
Mira este ejemplito...
Bajar aquí
Miguel Núñez.

ssccaann43

  • Terabyte
  • *****
  • Mensajes: 970
  • Reputación: +97/-58
    • Ver Perfil
    • Sistemas Nuñez, Consultores y Soporte, C.A.
Re:listar mi red
« Respuesta #2 en: Diciembre 09, 2009, 11:25:07 am »
Fijate, tengo problemas para subir archivos y no se si allí podras descargarlos, por tal motivo te explicaré como hacerlo, facil y sencillo.

En un formulario agrega un listview y dejalo con su nombre normal.

Código: [Seleccionar]
Dim Equipos As String
Private Sub Form_Load()
   Form1.Width = 4080
   Form1.Height = 5895
   ListView1.Left = 120
   ListView1.Top = 120
   ListView1.Height = 5175
   ListView1.Width = 3735
   ListView1.LabelEdit = lvwManual
   ListView1.View = lvwReport
   ListView1.ColumnHeaders.Add 1, , "Equipos", 3000
   Call Listar(Equipos, ListView1)
End Sub

Luego en un Modulo Bas

Código: [Seleccionar]
Public Declare Function NetServerEnum Lib "Netapi32" (ByVal servername As Long, ByVal level As Long, buf As Any, ByVal prefmaxlen As Long, entriesread As Long, totalentries As Long, ByVal servertype As Long, ByVal domain As Long, resume_handle As Long) As Long
Public Declare Function NetApiBufferFree Lib "netapi32.dll" (ByVal Buffer As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long)
Public Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long


Public Const MAX_LONG_PREFERIDA As Long = -1
Public Const NOMBRE_SERVIDOR As Long = 0&
Public Const ERROR_EN_DATO As Long = 234&
Public Const SV_TODOS_TIPOS As Long = &HFFFFFFFF
Public Const MAX_NOMBREPC As Long = 16

Public Type INFO_SERVIDOR
  sv100_id_plataforma As Long
  sv100_nombrepc As Long
End Type

Public Function Listar(LocalMachine As String, Lvw As ListView) As Long
Dim bufferproyecto As Long
Dim RegistrosLeidos As Long
Dim TotalRegistros As Long
Dim VolveralManejador As Long
Dim se100 As INFO_SERVIDOR
Dim hacer As Long
Dim tamaño As Long
Dim conteo As Long
Dim temporal As String
   
   tamaño = LenB(se100)
   hacer = NetServerEnum(0&, 100, bufferproyecto, MAX_LONG_PREFERIDA, RegistrosLeidos, TotalRegistros, SV_TODOS_TIPOS, 0&, VolveralManejador)
   temporal = MAX_NOMBREPC
If hacer = NOMBRE_SERVIDOR And hacer <> ERROR_EN_DATO Then
    For conteo = 0 To RegistrosLeidos - 1
        CopyMemory se100, ByVal bufferproyecto + (tamaño * conteo), tamaño
        temporal = Point(se100.sv100_nombrepc)
        Lvw.ListItems.Add , temporal, temporal
    Next
End If
   
   Call NetApiBufferFree(bufferproyecto)

End Function


Public Function Point(ByVal Datos As Long) As String
Dim temporal() As Byte
Dim temporalMemoria As Long

If Datos <> 0 Then
    temporalMemoria = lstrlenW(Datos) * 2
    If temporalMemoria <> 0 Then
        ReDim temporal(0 To (temporalMemoria - 1)) As Byte
        CopyMemory temporal(0), ByVal Datos, temporalMemoria
        Point = temporal
    End If
End If
End Function
Miguel Núñez.