Solved

nethood names in a listbox

Posted on 2002-03-15
4
152 Views
Last Modified: 2011-09-20
Hi,
i am developing a project in VB, whereby i want all the computer names(of the LAN)  which are ON in a list box. these names can be seen in the network neighborhood folder but i want these names in a list box.
i would also like to find  the users on these computers which will be listed in a separate list box.
i tried using the BrowseForFolder() function but did not succeed.
0
Comment
Question by:RanjiniPraba
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 30 total points
ID: 6867566
Check out this API:

Const ERROR_SUCCESS = 0
Const ERROR_MORE_DATA = 234
Const SV_TYPE_SERVER = &H0   'Server type mask, all types of servers

Const SIZE_SI_101 = 24

Private Type SERVER_INFO_101
 dwPlatformId As Long
 lpszServerName As Long
 dwVersionMajor As Long
 dwVersionMinor As Long
 dwType As Long
 lpszComment As Long
End Type
 
Private Declare Function NetServerEnum Lib "netapi32.dll" ( _
     ByVal servername As String, _
     ByVal level As Long, _
     buffer As Long, _
     ByVal prefmaxlen As Long, _
     entriesread As Long, _
     totalentries As Long, _
     ByVal ServerType As Long, _
     ByVal Domain As String, _
     resumehandle As Long) As Long

Private Declare Function NetApiBufferFree Lib "netapi32.dll" ( _
  BufPtr As Any) As Long
 
Private Declare Sub RtlMoveMemory Lib "KERNEL32" ( _
  hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
 
Private Declare Function lstrcpyW Lib "KERNEL32" ( _
  ByVal lpszDest As String, ByVal lpszSrc As Long) As Long

Private Function PointerToString(lpszString As Long) As String
  Dim lpszStr1 As String, lpszStr2 As String, nRes As Long
  lpszStr1 = String(1000, "*")
  nRes = lstrcpyW(lpszStr1, lpszString)
  lpszStr2 = (StrConv(lpszStr1, vbFromUnicode))
  PointerToString = Left(lpszStr2, InStr(lpszStr2, Chr$(0)) - 1)
End Function




Public Sub SearchOnDomain(Optional Domain As String = vbNullString)
 Dim vntData As SERVER_INFO_101
 Dim lngRead As Long
 Dim lngTotal As Long
 Dim strDomain As String
 Dim strServer As String
 Dim lngLevel As Long
 Dim lngMaxLen As Long
 Dim lngResume As Long
 Dim BufPtr As Long
 
 Dim tmpPtr As Long
 Dim i As Long
 
 strServer = vbNullString
 If Domain = vbNullString Or Domain = "" Then
   strDomain = vbNullString
 Else
   strDomain = StrConv(Domain, vbUnicode)
 End If
 
 lngLevel = 101
 lngMaxLen = -1
 lngRead = 0
 lngTotal = 0
 lngResume = 0
 
 Call NetServerEnum(strServer, lngLevel, BufPtr, lngMaxLen, _
   lngRead, lngTotal, SV_TYPE_SERVER, strDomain, lngResume)
 
 tmpPtr = BufPtr
 For i = 1 To lngRead
   RtlMoveMemory vntData, tmpPtr, SIZE_SI_101
   strServer = PointerToString(vntData.lpszServerName)
   tmpPtr = tmpPtr + SIZE_SI_101
   
   debug.Print strServer
 Next i

End Sub


CHeers
0
 

Author Comment

by:RanjiniPraba
ID: 6879425
hi
i get the following error message on running the code

Runtime error "453"
cant find DLL entry point NetServerEnum in netapi32.dll

I cant find this function in win32api either
please help
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6879460
Depending on the OS:

Private Declare Function NetServerEnum Alias "NetServerEnumA" Lib "netapi32.dll"

or

Private Declare Function NetServerEnum Alias "NetServerEnumB" Lib "netapi32.dll"

The same applies of course to
NetApiBufferFree

Cheers
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6879462
sorry for a typo:

or

Private Declare Function NetServerEnum Alias "NetServerEnumW" Lib "netapi32.dll"

CHeers
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question