Lista de pcs en dominio

04/07/2003 - 01:10 por Fernando | Informe spam
Hola

El dia 2 de Julio aparecia un mensaje de alguien que
queria saber como obtener una lista de las pcs que
estaban en determinado dominio y Malaka le dijo que
pegara el siguiente codigo en un formulario:


******************************************************
Option Explicit
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&

Private Const SV_TYPE_WORKSTATION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERVER As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
Private Const SV_TYPE_TIME_SOURCE As Long = &H20
Private Const SV_TYPE_AFP As Long = &H40
Private Const SV_TYPE_NOVELL As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER As Long = &H400
Private Const SV_TYPE_XENIX_SERVER As Long = &H800
Private Const SV_TYPE_SERVER_UNIX As Long =
SV_TYPE_XENIX_SERVER
Private Const SV_TYPE_NT As Long = &H1000
Private Const SV_TYPE_WFW As Long = &H2000
Private Const SV_TYPE_SERVER_MFPN As Long = &H4000
Private Const SV_TYPE_SERVER_NT As Long = &H8000
Private Const SV_TYPE_POTENTIAL_BROWSER As Long =
&H10000
Private Const SV_TYPE_BACKUP_BROWSER As Long =
&H20000
Private Const SV_TYPE_MASTER_BROWSER As Long =
&H40000
Private Const SV_TYPE_DOMAIN_MASTER As Long =
&H80000
Private Const SV_TYPE_SERVER_OSF As Long =
&H100000
Private Const SV_TYPE_SERVER_VMS As Long =
&H200000
Private Const SV_TYPE_WINDOWS As Long =
&H400000
Private Const SV_TYPE_DFS As Long =
&H800000
Private Const SV_TYPE_CLUSTER_NT As Long =
&H1000000
Private Const SV_TYPE_TERMINALSERVER As Long =
&H2000000
Private Const SV_TYPE_DCE As Long =
&H10000000
Private Const SV_TYPE_ALTERNATE_XPORT As Long =
&H20000000
Private Const SV_TYPE_LOCAL_LIST_ONLY As Long =
&H40000000
Private Const SV_TYPE_DOMAIN_ENUM As Long =
&H80000000
Private Const SV_TYPE_ALL As Long =
&HFFFFFFFF

Private Const SV_PLATFORM_ID_OS2 As Long = 400
Private Const SV_PLATFORM_ID_NT As Long = 500

Private Const MAJOR_VERSION_MASK As Long = &HF

Private Type SERVER_INFO_100
sv100_platform_id As Long
sv100_name As Long
End Type

Private 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
Private Declare Function NetApiBufferFree
Lib "netapi32.dll" (ByVal Buffer
As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32"
Alias "RtlMoveMemory" (pTo As
Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal
lpString As Long) As
Long

Private Sub Command1_Click()
Call GetServers(vbNullString)
End Sub

Private Function GetServers(sDomain As String) As Long
Dim bufptr As Long
Dim dwEntriesread As Long
Dim dwTotalentries As Long
Dim dwResumehandle As Long
Dim se100 As SERVER_INFO_100
Dim success As Long
Dim nStructSize As Long
Dim cnt As Long
nStructSize = LenB(se100)
success = NetServerEnum(0&, 100, bufptr,
MAX_PREFERRED_LENGTH,
dwEntriesread, dwTotalentries, SV_TYPE_SQLSERVER, 0&,
dwResumehandle)
If success = NERR_SUCCESS And _
success <> ERROR_MORE_DATA Then
For cnt = 0 To dwEntriesread - 1
CopyMemory se100, ByVal bufptr + (nStructSize *
cnt), nStructSize
List1.AddItem GetPointerToByteStringW
(se100.sv100_name)
Next
End If
Call NetApiBufferFree(bufptr)
GetServers = dwEntriesread
End Function

Public Function GetPointerToByteStringW(ByVal dwData As
Long) As String
Dim tmp() As Byte
Dim tmplen As Long
If dwData <> 0 Then
tmplen = lstrlenW(dwData) * 2
If tmplen <> 0 Then
ReDim tmp(0 To (tmplen - 1)) As Byte
CopyMemory tmp(0), ByVal dwData, tmplen
GetPointerToByteStringW = tmp
End If
End If
End Function

******************************************************

Yo lo copie y lo pegue en un formulario y el problema que
tengo es que solo me muestra la maquina donde estoy
corriendo el programa siendo que tengo dos equipos en ese
dominio.

Alguien sabe por que?

De antemano muchas gracias.

Atte. Fdo. Fdez.
 

Leer las respuestas

#1 Lluís Franco
04/07/2003 - 17:25 | Informe spam
Hola,
Porque en la rutina 'GetServers' estás listando sólo los servidores de SQL
Server (SV_TYPE_SQLSERVER), cambia esto por el valor 'SV_TYPE_WORKSTATION' y
listo...

Un saludo andorrano!
Lluís Franco i Montanyés
Cap de projectes informàtics de serveis financers
FIMARGE, S.A.

Tel.: +376 805 100
Fax: +376 824 500

(Guía de netiquette del foro)
http://perso.wanadoo.es/rubenvigon/foro


"Fernando" escribió en el mensaje
news:054901c341b8$4df44d70$
Hola

El dia 2 de Julio aparecia un mensaje de alguien que
queria saber como obtener una lista de las pcs que
estaban en determinado dominio y Malaka le dijo que
pegara el siguiente codigo en un formulario:


******************************************************
Option Explicit
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&

Private Const SV_TYPE_WORKSTATION As Long = &H1
Private Const SV_TYPE_SERVER As Long = &H2
Private Const SV_TYPE_SQLSERVER As Long = &H4
Private Const SV_TYPE_DOMAIN_CTRL As Long = &H8
Private Const SV_TYPE_DOMAIN_BAKCTRL As Long = &H10
Private Const SV_TYPE_TIME_SOURCE As Long = &H20
Private Const SV_TYPE_AFP As Long = &H40
Private Const SV_TYPE_NOVELL As Long = &H80
Private Const SV_TYPE_DOMAIN_MEMBER As Long = &H100
Private Const SV_TYPE_PRINTQ_SERVER As Long = &H200
Private Const SV_TYPE_DIALIN_SERVER As Long = &H400
Private Const SV_TYPE_XENIX_SERVER As Long = &H800
Private Const SV_TYPE_SERVER_UNIX As Long > SV_TYPE_XENIX_SERVER
Private Const SV_TYPE_NT As Long = &H1000
Private Const SV_TYPE_WFW As Long = &H2000
Private Const SV_TYPE_SERVER_MFPN As Long = &H4000
Private Const SV_TYPE_SERVER_NT As Long = &H8000
Private Const SV_TYPE_POTENTIAL_BROWSER As Long > &H10000
Private Const SV_TYPE_BACKUP_BROWSER As Long > &H20000
Private Const SV_TYPE_MASTER_BROWSER As Long > &H40000
Private Const SV_TYPE_DOMAIN_MASTER As Long > &H80000
Private Const SV_TYPE_SERVER_OSF As Long > &H100000
Private Const SV_TYPE_SERVER_VMS As Long > &H200000
Private Const SV_TYPE_WINDOWS As Long > &H400000
Private Const SV_TYPE_DFS As Long > &H800000
Private Const SV_TYPE_CLUSTER_NT As Long > &H1000000
Private Const SV_TYPE_TERMINALSERVER As Long > &H2000000
Private Const SV_TYPE_DCE As Long > &H10000000
Private Const SV_TYPE_ALTERNATE_XPORT As Long > &H20000000
Private Const SV_TYPE_LOCAL_LIST_ONLY As Long > &H40000000
Private Const SV_TYPE_DOMAIN_ENUM As Long > &H80000000
Private Const SV_TYPE_ALL As Long > &HFFFFFFFF

Private Const SV_PLATFORM_ID_OS2 As Long = 400
Private Const SV_PLATFORM_ID_NT As Long = 500

Private Const MAJOR_VERSION_MASK As Long = &HF

Private Type SERVER_INFO_100
sv100_platform_id As Long
sv100_name As Long
End Type

Private 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
Private Declare Function NetApiBufferFree
Lib "netapi32.dll" (ByVal Buffer
As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32"
Alias "RtlMoveMemory" (pTo As
Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal
lpString As Long) As
Long

Private Sub Command1_Click()
Call GetServers(vbNullString)
End Sub

Private Function GetServers(sDomain As String) As Long
Dim bufptr As Long
Dim dwEntriesread As Long
Dim dwTotalentries As Long
Dim dwResumehandle As Long
Dim se100 As SERVER_INFO_100
Dim success As Long
Dim nStructSize As Long
Dim cnt As Long
nStructSize = LenB(se100)
success = NetServerEnum(0&, 100, bufptr,
MAX_PREFERRED_LENGTH,
dwEntriesread, dwTotalentries, SV_TYPE_SQLSERVER, 0&,
dwResumehandle)
If success = NERR_SUCCESS And _
success <> ERROR_MORE_DATA Then
For cnt = 0 To dwEntriesread - 1
CopyMemory se100, ByVal bufptr + (nStructSize *
cnt), nStructSize
List1.AddItem GetPointerToByteStringW
(se100.sv100_name)
Next
End If
Call NetApiBufferFree(bufptr)
GetServers = dwEntriesread
End Function

Public Function GetPointerToByteStringW(ByVal dwData As
Long) As String
Dim tmp() As Byte
Dim tmplen As Long
If dwData <> 0 Then
tmplen = lstrlenW(dwData) * 2
If tmplen <> 0 Then
ReDim tmp(0 To (tmplen - 1)) As Byte
CopyMemory tmp(0), ByVal dwData, tmplen
GetPointerToByteStringW = tmp
End If
End If
End Function

******************************************************

Yo lo copie y lo pegue en un formulario y el problema que
tengo es que solo me muestra la maquina donde estoy
corriendo el programa siendo que tengo dos equipos en ese
dominio.

Alguien sabe por que?

De antemano muchas gracias.

Atte. Fdo. Fdez.

Preguntas similares