Solved

nethood names in a listbox

Posted on 2002-03-15
4
146 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
  • 3
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 30 total points
Comment Utility
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
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
sorry for a typo:

or

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

CHeers
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now