jdemackio Posted October 1, 2004 Posted October 1, 2004 I would like to populate a listbox with the window's networking name (computer name) of all clients within a LAN. Can anyone point me in the right direction? Quote - The only true knowledge is knowing that you know nothing.
blabore Posted October 1, 2004 Posted October 1, 2004 Might want to look at the API function NetServerEnum, which you can use to find all pc names for a given domain name Quote -Ben LaBore
jdemackio Posted October 1, 2004 Author Posted October 1, 2004 Ok, I will look into that, thank you for your quick response. Quote - The only true knowledge is knowing that you know nothing.
blabore Posted October 1, 2004 Posted October 1, 2004 Ok' date=' I will look into that, thank you for your quick response.[/quote'] No problem. If you want some sample code, try downloading the SOSOS application from planet source code. It's probably in the Hall of Fame section (or something like that). Quote -Ben LaBore
jdemackio Posted October 1, 2004 Author Posted October 1, 2004 dude that SOSOS stuff is awesome. Thanks. Quote - The only true knowledge is knowing that you know nothing.
LostProgrammer Posted October 4, 2004 Posted October 4, 2004 use directory services to query active directory. Quote
Mykre Posted October 4, 2004 Posted October 4, 2004 Here is a sample class that lists SQL Servers on the Network, you should be able to moderfy it for all machines. Public Class clsNetAPI32 Private Const SV_TYPE_SQLSERVER = &H4S ' NetServerEnum Return Values Private Const ERR_SUCCESS = 0 Private Const ERROR_MORE_DATA As Int32 = 234 Private Const ERROR_NO_BROWSER_SERVERS_FOUND As Int32 = 6118I Private Structure SERVER_INFO_100 Dim sv100_platform_id As Integer Dim sv100_name As Integer End Structure ' ' level : Specifies the information level of the data ' bufptr : Pointer to the buffer that receives the data ' prefmaxlen : Specifies the preferred maximum length of returned data, in bytes ' entriesread : Pointer to a value that receives the count of elements actually enumerated ' totalentries : Pointer to a value that receives the total number of visible servers and workstations on the network ' servertype : Specifies a value that filters the server entries to return from the enumeration ' domain : Pointer to a constant string that specifies the name of the domain for which a list of servers is to be returned ' resume_handle : Reserved; must be set to zero Private Declare Unicode Function NetServerEnum Lib "netapi32" _ (ByVal servername As IntPtr _ , ByVal level As Integer _ , ByRef bufptr As IntPtr _ , ByVal prefmaxlen As Integer _ , ByRef entriesread As Integer _ , ByRef totalentries As Integer _ , ByVal servertype As Integer _ , ByVal domain As IntPtr _ , ByVal resume_handle As Integer _ ) As Integer Private Declare Function NetApiBufferFree Lib "netapi32" _ (ByVal BufPtr As IntPtr) As Integer Public Function GetListOfServers(ByRef colSQLServers As Collection) As Boolean Dim sServerName As IntPtr = IntPtr.Zero Dim iLevel As Integer = 100 Dim lBufPtr As IntPtr Dim iprefMaxLen As Integer = -1 Dim iEntriesRead As Integer Dim iTotalEntries As Integer Dim sDomain As IntPtr = IntPtr.Zero Dim iResumeHandle As Integer = 0 Dim iReturnValue As Integer Dim sctSrvList As SERVER_INFO_100 Dim nStructSize As Integer = Marshal.SizeOf(sctSrvList) Dim scSQLServers As New Specialized.StringCollection Dim iIndex As Integer colSQLServers = New Collection iReturnValue = NetServerEnum(sServerName _ , iLevel _ , lBufPtr _ , iprefMaxLen _ , iEntriesRead _ , iTotalEntries _ , SV_TYPE_SQLSERVER _ , sDomain _ , iResumeHandle _ ) If iReturnValue = ERR_SUCCESS Then ' Loop through each SQL Server returned by the NetServerEnum call For iIndex = 0 To iEntriesRead - 1 ' Convert each SQL Server entry into a SERVER_INFO_100 structure sctSrvList = DirectCast(Marshal.PtrToStructure(New IntPtr(lBufPtr.ToInt32 + (nStructSize * iIndex)) _ , GetType(SERVER_INFO_100) _ ) _ , SERVER_INFO_100 _ ) ' Add each SQL Server SERVER_INFO_100 structure entry into the StringCollection scSQLServers.Add(Marshal.PtrToStringUni(New IntPtr(sctSrvList.sv100_name))) Next End If ' Clean up regardless of iReturnValue Call NetApiBufferFree(lBufPtr) ' Move from String Collection to Array To Collection ' I only return the list as a collection because ' collections are what I am used to Dim sSQLServers(scSQLServers.Count - 1) As String scSQLServers.CopyTo(sSQLServers, 0) For iIndex = 0 To sSQLServers.GetUpperBound(0) colSQLServers.Add(sSQLServers(iIndex)) Next Return True End Function End Class Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
morrisdotcom Posted November 18, 2004 Posted November 18, 2004 One question, I try to see that example, but the word "Marshal" say that it's not declared. First, what is marshall.. and how can I declare it? Quote
Administrators PlausiblyDamp Posted November 18, 2004 Administrators Posted November 18, 2004 (edited) At the top of the source file you will need to add Imports System.Runtime.InteropServices Edited November 18, 2004 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.