Api

Necesito un api con un ejemplo de como puedo ver todos los equipos de la red. Como ir por entorno de red pero desde visual basic

1 respuesta

Respuesta
1
Lo mas parecido que conozco es el selector de recursos de la red, un cuadro de diálogo que usa win. Aca te mando el código:
Option Explicit
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)
Private Declare Function lstrcat Lib "kernel32.dll" Alias "lstrcatA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" (ByVal pidList As Long, ByVal lpBuffer As String) As Long
Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal hWndOwner As Long, ByVal nFolder As Long, ListId As Long) As Long
Private Type BrowseInfo
hWndOwner As Long
pIDLRoot As Long
pszDisplayName As Long
lpszTitle As Long
ulFlags As Long
lpfnCallback As Long
lParam As Long
iImage As Long
End Type
Public Enum BrowseType
BrowseForFolders = &H1
BrowseForComputers = &H1000
BrowseForPrinters = &H2000
BrowseForEverything = &H4000
End Enum
Public Enum FolderType
CSIDL_BITBUCKET = 10
CSIDL_CONTROLS = 3
CSIDL_DESKTOP = 0
CSIDL_DRIVES = 17
CSIDL_FONTS = 20
CSIDL_NETHOOD = 18
CSIDL_NETWORK = 19
CSIDL_PERSONAL = 5
CSIDL_PRINTERS = 4
CSIDL_PROGRAMS = 2
CSIDL_RECENT = 8
CSIDL_SENDTO = 9
CSIDL_STARTMENU = 11
End Enum
Private Const MAX_PATH = 260
Public Function BrowseFolders(hWndOwner As Long, sMessage As String, Browse As BrowseType, ByVal RootFolder As FolderType) As String
Dim Nullpos As Integer
Dim lpIDList As Long
Dim res As Long
Dim sPath As String
Dim BInfo As BrowseInfo
Dim RootID As Long
SHGetSpecialFolderLocation hWndOwner, RootFolder, RootID
BInfo.hWndOwner = hWndOwner
BInfo.lpszTitle = lstrcat(sMessage, "")
BInfo.ulFlags = Browse
If RootID <> 0 Then BInfo.pIDLRoot = RootID
lpIDList = SHBrowseForFolder(BInfo)
If lpIDList <> 0 Then
sPath = String(MAX_PATH, 0)
res = SHGetPathFromIDList(lpIDList, sPath)
Call CoTaskMemFree(lpIDList)
Nullpos = InStr(sPath, vbNullChar)
If Nullpos <> 0 Then
sPath = Left(sPath, Nullpos - 1)
End If
End If
BrowseFolders = sPath
End Function
Ejemplo de uso:
MsgBox BrowseFolders(hWnd, "Select a Folder", BrowseForFolders, CSIDL_NETHOOD)
Suerte
.: Gydba :.
Si esta bien,pero como cogo los nombres de los equipos para trabajar con ellos.
Gracias
Eso solo es para los recursos de la red, yo te dije que era la única api simple con que listarlos. Proba con lo siguiente (sobre win NT/XP solo me lista los grupos, lo tendrías que modificar para centrarte solo en un grupo):
Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Declare Function GetNetworkParams Lib "IPHlpApi" (FixedInfo As Any, pOutBufLen As Long) As Long
Declare Function GetAdaptersInfo Lib "IPHlpApi" (IpAdapterInfo As Any, pOutBufLen As Long) As Long
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Declare Function WNetAddConnection Lib "mpr.dll" Alias "WNetAddConnectionA" (ByVal lpszNetPath As String, ByVal lpszPassword As String, ByVal lpszLocalName As String) As Long
Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Long) As Long
Declare Function WNetCancelConnection Lib "mpr.dll" Alias "WNetCancelConnectionA" (ByVal lpszName As String, ByVal bForce As Long) As Long
Declare Function WNetCancelConnection2 Lib "mpr.dll" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Long, ByVal fForce As Long) As Long
Declare Function WNetCloseEnum Lib "mpr.dll" (ByVal hEnum As Long) As Long
Declare Function WNetConnectionDialog Lib "mpr.dll" (ByVal hwnd As Long, ByVal dwType As Long) As Long
Declare Function WNetDisconnectDialog Lib "mpr.dll" (ByVal hwnd As Long, ByVal dwType As Long) As Long
Declare Function WNetEnumResource Lib "mpr.dll" Alias "WNetEnumResourceA" (ByVal hEnum As Long, lpcCount As Long, lpBuffer As Any, lpBufferSize As Long) As Long
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Declare Function WNetGetLastError Lib "mpr.dll" Alias "WNetGetLastErrorA" (lpError As Long, ByVal lpErrorBuf As String, ByVal nErrorBufSize As Long, ByVal lpNameBuf As String, ByVal nNameBufSize As Long) As Long
Declare Function WNetGetUniversalName Lib "mpr.dll" Alias "WNetGetUniversalNameA" (ByVal lpLocalPath As String, ByVal dwInfoLevel As Long, lpBuffer As Any, lpBufferSize As Long) As Long
Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
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
Declare Function WNetGetNetworkInformation Lib "mpr.dll" Alias "WNetGetNetworkInformationA" (ByVal lpProvider As String, lpNetInfoStruct As NETINFOSTRUCT) As Long
Declare Function GetLastError Lib "kernel32" () As Long
Public Const CONNECT_UPDATE_PROFILE = &H1
Public Const RESOURCETYPE_ANY = &H0
Public Const RESOURCETYPE_DISK = &H1
Public Const RESOURCETYPE_PRINT = &H2
Public Const RESOURCETYPE_UNKNOWN = &HFFFF
Public Const RESOURCEUSAGE_CONNECTABLE = &H1
Public Const RESOURCEUSAGE_CONTAINER = &H2
Public Const RESOURCEUSAGE_RESERVED = &H80000000
Public Const RESOURCEDISPLAYTYPE_DOMAIN = &H1
Public Const RESOURCEDISPLAYTYPE_FILE = &H4
Public Const RESOURCEDISPLAYTYPE_GENERIC = &H0
Public Const RESOURCEDISPLAYTYPE_GROUP = &H5
Public Const RESOURCEDISPLAYTYPE_SERVER = &H2
Public Const RESOURCEDISPLAYTYPE_SHARE = &H3
Public Const RESOURCEDISPLAYTYPE_PROVIDER = 6
Public Const RESOURCE_CONNECTED = &H1
Public Const RESOURCE_PUBLICNET = &H2
Public Const RESOURCE_GLOBALNET = RESOURCE_PUBLICNET
Public Const RESOURCE_REMEMBERED = &H3
Public Const NO_ERROR = 0
Public Const ERROR_MORE_DATA = 234
Public Const ERROR_NETWORK_ACCESS_DENIED = 65&
Public Const ERROR_NETWORK_BUSY = 54&
Public Const ERROR_NO_NET_OR_BAD_PATH = 1203&
Public Const ERROR_NO_NETWORK = 1222&
Public Const ERROR_EXTENDED_ERROR = 1208&
Public Const ERROR_BUSY = 170&
Public Const WN_SUCCESS = NO_ERROR
Public Const WN_NO_NETWORK = ERROR_NO_NETWORK
Public Const WN_BUSY = ERROR_BUSY
Public Const NETINFO_DLL16 = &H1
Public Const NETINFO_DISKRED = &H4
Public Const NETINFO_PRINTERRED = &H8
Public Const MAX_HOSTNAME_LEN = 132
Public Const MAX_DOMAIN_NAME_LEN = 132
Public Const MAX_SCOPE_ID_LEN = 260
Public Const MAX_ADAPTER_NAME_LENGTH = 260
Public Const MAX_ADAPTER_ADDRESS_LENGTH = 8
Public Const MAX_ADAPTER_DESCRIPTION_LENGTH = 132
Public Const ERROR_BUFFER_OVERFLOW = 111
Public Const MIB_IF_TYPE_OTHER = 1
Public Const MIB_IF_TYPE_ETHERNET = 6
Public Const MIB_IF_TYPE_TOKENRING = 9
Public Const MIB_IF_TYPE_FDDI = 15
Public Const MIB_IF_TYPE_PPP = 23
Public Const MIB_IF_TYPE_LOOPBACK = 24
Public Const MIB_IF_TYPE_SLIP = 28
Type NETRESOURCE
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As String
lpRemoteName As String
lpComment As String
lpProvider As String
End Type
Type NETRESOURCE2
dwScope As Long
dwType As Long
dwDisplayType As Long
dwUsage As Long
lpLocalName As Long
lpRemoteName As Long
lpComment As Long
lpProvider As Long
buffer As String * 256
End Type
Type NETINFOSTRUCT
cbStructure As Long
dwProviderVersion As Long
dwStatus As Long
dwCharacteristics As Long
dwHandle As Long
wNetType As Integer
dwPrinters As Long
dwDrives As Long
End Type
Type IP_ADDR_STRING
Next As Long
IpAddress As String * 16
IpMask As String * 16
Context As Long
End Type
Type IP_ADAPTER_INFO
Next As Long
ComboIndex As Long
AdapterName As String * MAX_ADAPTER_NAME_LENGTH
Description As String * MAX_ADAPTER_DESCRIPTION_LENGTH
AddressLength As Long
Address(MAX_ADAPTER_ADDRESS_LENGTH - 1) As Byte
Index As Long
Type As Long
DhcpEnabled As Long
CurrentIpAddress As Long
IpAddressList As IP_ADDR_STRING
GatewayList As IP_ADDR_STRING
DhcpServer As IP_ADDR_STRING
HaveWins As Boolean
PrimaryWinsServer As IP_ADDR_STRING
SecondaryWinsServer As IP_ADDR_STRING
LeaseObtained As Long
LeaseExpires As Long
End Type
Type FIXED_INFO
HostName As String * MAX_HOSTNAME_LEN
DomainName As String * MAX_DOMAIN_NAME_LEN
CurrentDnsServer As Long
DnsServerList As IP_ADDR_STRING
NodeType As Long
ScopeId As String * MAX_SCOPE_ID_LEN
EnableRouting As Long
EnableProxy As Long
EnableDns As Long
End Type
Public Sub EnumeraRecursos(Lista As ListBox, Raiz As String, Uso As Long)
Dim IdEnumeracion As Long
Dim DatosRecurso As NETRESOURCE2
Dim DatosInicio As NETRESOURCE
Dim Espacios As String
Dim Codigo As Long, Cadena As String
Cadena = String(256, 0)
If Raiz = "" Then
Codigo = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, ByVal 0, IdEnumeracion)
Else
If Uso = RESOURCEDISPLAYTYPE_PROVIDER Then
DatosInicio.lpProvider = Raiz
Else
DatosInicio.lpRemoteName = Raiz
End If
Codigo = WNetOpenEnum(RESOURCE_GLOBALNET, RESOURCETYPE_ANY, 0, DatosInicio, IdEnumeracion)
End If
If Codigo <> NO_ERROR Then
MsgBox "No es posible obtener información"
Exit Sub
End If
Do While WNetEnumResource(IdEnumeracion, 1, DatosRecurso, Len(DatosRecurso)) = NO_ERROR
With DatosRecurso
Select Case .dwDisplayType
Case RESOURCEDISPLAYTYPE_PROVIDER:
lstrcpy Cadena, .lpProvider
Case RESOURCEDISPLAYTYPE_DOMAIN: ' Grupo
lstrcpy Cadena, .lpRemoteName
Espacios = String(3, 32) & "Grupo "
Case RESOURCEDISPLAYTYPE_SERVER: ' Servidor
lstrcpy Cadena, .lpRemoteName
Espacios = String(6, 32) & "PC "
Case RESOURCEDISPLAYTYPE_GENERIC: ' Otro recurso
Case RESOURCEDISPLAYTYPE_SHARE:
lstrcpy Cadena, .lpRemoteName
Espacios = String(9, 32)
If .dwType = RESOURCETYPE_DISK Then
Espacios = Espacios & "UNIDAD "
ElseIf .dwType = RESOURCETYPE_PRINT Then
Espacios = Espacios & "IMPRESORA "
End If
End Select
End With
Lista.AddItem Espacios & Cadena
If DatosRecurso.dwUsage = RESOURCEUSAGE_CONTAINER Or DatosRecurso.dwUsage = 10 Then
EnumeraRecursos Lista, Cadena, DatosRecurso.dwDisplayType
End If
Loop
WNetCloseEnum IdEnumeracion
End Sub
Modo de uso:
EnumeraRecursos List1, "", 0
msgbox list1.list(list1.listindex)
Espero te ande.
Suerte
.: Gydba :.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas