API calls for retrieving all the Workgroup/Domain/Computer names on the network 
Author Message
 API calls for retrieving all the Workgroup/Domain/Computer names on the network

API calls for retrieving all the Workgroup/Domain/Computer names on the
network

I need to do two things I need to get a list of all the Workgroups/Domains
on the network and place all those names into an array. The second thing I
need to do is to get all the computer names on a specific Workgroup/Domain
and place them into an array. Does anyone now the APIs to do this?



Sun, 02 Mar 2003 03:46:29 GMT  
 API calls for retrieving all the Workgroup/Domain/Computer names on the network
Here's some VB code that should help.  It's an example I found, not
something I've used myself.  You'll have to modify it it a few places to use
in VBScript.  GetAdministrators()  is the function you would call.  You
could obviously modify this code to any group of users.  This example just
gets the administrators.  You'll the Net API functions are found in
NETAPI32.DLL.  I suggest you study the Win32 API doc for more info on this
DLL.

Regards,
Dan

'Start of Code

Option Explicit

'---------------------------
Declarations---------------------------------------
Private Declare Function NetLocalGroupGetMembers Lib "NETAPI32.DLL" (ByVal _
psServer As String, ByVal psLocalGroup As Long, ByVal lLevel As Long, _
ByRef pBuffer As Long, ByVal lMaxLength As Long, plEntriesRead As Long, _
plTotalEntries As Long, ByVal phResume As Long) As Long

Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest
As Any, _
pSource As Any, ByVal dwLength As Long)
Private Declare Function lstrlenW Lib "kernel32" (lpString As Any) As Long
Private Declare Function WideCharToMultiByte Lib "kernel32" _
                            (ByVal codepage As Long, _
                            ByVal dwFlags As Long, _
                            lpWideCharStr As Any, _
                            ByVal cchWideChar As Long, _
                            lpMultiByteStr As Any, _
                            ByVal cchMultiByte As Long, _
                            ByVal lpDefaultChar As String, _
                            ByVal lpUsedDefaultChar As Long) As Long
Private Declare Function NetAPIBufferFree Lib "NETAPI32.DLL" Alias _
"NetApiBufferFree" (ByVal Ptr As Long) As Long
'-----------------------------------
CODE ----------------------------------------
Private Function GetAdministrators() As String

    Dim aLocalGroups As Long
    Dim tGroup() As Long
    Dim lEntriesRead As Long
    Dim lTotalEntries As Long
    Dim lResume As Long
    Dim sGroupName As String
    Dim EntryNum As Long
    Dim Result As String
    sGroupName = "Administrators"
    Do
        Call NetLocalGroupGetMembers("", StrPtr(sGroupName), 3, _
        aLocalGroups, -1, lEntriesRead, lTotalEntries, lResume)
        ReDim tGroup(lEntriesRead)
        For EntryNum = 0 To lEntriesRead - 1
            Call MoveMemory(tGroup(EntryNum), ByVal aLocalGroups + 4 *
EntryNum, Len(tGroup(EntryNum)))
            Debug.Print GetStrFromPtrW(tGroup(EntryNum))
            Result = Result & GetStrFromPtrW(tGroup(EntryNum)) & ", "
        Next EntryNum
        NetAPIBufferFree (aLocalGroups)
    Loop While lResume
    GetAdministrators = Result
    Debug.Print Result
End Function

'Here are the remaining function:

' Returns an ANSI string from a pointer to a Unicode string.
Public Function GetStrFromPtrW(lpszW As Long) As String

  Dim sRtn As String
  sRtn = String$(lstrlenW(ByVal lpszW) * 2, 0)   ' 2 bytes/char
  Call WideCharToMultiByte(0, 0, ByVal lpszW, -1, ByVal sRtn, Len(sRtn), 0,
0)
  If InStr(sRtn, vbNullChar) Then
    GetStrFromPtrW = Left$(sRtn, InStr(sRtn, vbNullChar) - 1)
  Else
    GetStrFromPtrW = sRtn
  End If

End Function


Quote:

> API calls for retrieving all the Workgroup/Domain/Computer names on the
> network

> I need to do two things I need to get a list of all the Workgroups/Domains
> on the network and place all those names into an array. The second thing I
> need to do is to get all the computer names on a specific Workgroup/Domain
> and place them into an array. Does anyone now the APIs to do this?



Sun, 02 Mar 2003 13:00:03 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. API calls for retrieving all the Workgroup/Domain/Computer names on the network

2. Retrieving Computer name from Network

3. Retrieving the names of computers on a network

4. How can I retrieve a network computer name

5. Retrieve a network computer name

6. How can I retrieve a network computer name???

7. Retrieve network computer name

8. How to retrieve Domain name from Win95 using API

9. Retrieve network computer name

10. Computers in workgroup/domain/subnet

11. retrieving computername and domains/workgroups

12. HELP!What Domain/Workgroup a computer is a member of

 

 
Powered by phpBB® Forum Software