Use netServerEnum.
Sample:
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Declare Function PtrToStr Lib "kernel32" Alias "lstrcpyW" (retVal As Byte, ByVal Ptr As Long) As Long
Public Declare Function StrToPtr Lib "kernel32" Alias "lstrcpyW" (ByVal Ptr As Long, Source As Byte) As Long
Public Declare Function PtrToInt Lib "kernel32" Alias "lstrcpynW" (retVal As Any, ByVal Ptr As Long, ByVal nCharCount As Long) As Long
Public Declare Function StrLen Lib "kernel32" Alias "lstrlenW" (ByVal Ptr As Long) As Long
Public OK As BooleanPrivate Sub Form_Load()
    Dim sBuffer As String
    Dim lSize As Long
    Call FillCboSvrsEnd Sub
Sub FillCboSvrs()
cboSvrs.Clear
Dim tSvrInfo As Server_Info
Dim strDomainName As String
Dim result As Long, bufptr As Long, entriesread As Long, totalentries As Long, resumehandle As Long, BufLen As Long, _
DNArray() As Byte, SNArray(99) As Byte, UNArray() As Byte, _
SName As String, i As Integer, UNPtr As Long, nLevel As Long, nSvrType As Long, _
TempPtr As MungeLong, TempStr As MungeInt
Dim nPlatform_id As Long, strSvrName As String, nVersion_major As Long, nVersion_minor As Long, nType As Long, strComment As String
Dim SvrInfoArray() As Server_Info
nSvrType = SV_TYPE_ALL
 ' UNArray = UName & vbNullChar       ' Move to Byte array
  BufLen = -1                     ' Buffer size
  resumehandle = 0                   ' Start with the first entry
  nLevel = 101
  strDomainName = tUsrInfo.strDomainName
      DNArray = strDomainName & vbNullChar       ' Move to byte array
      Do
         If Len(Trim(strDomainName)) > 0 Then
          result = NetServerEnum(ByVal 0, nLevel, bufptr, BufLen, entriesread, totalentries, nSvrType, DNArray(0), resumehandle)
         Else
           result = NetServerEnum(ByVal 0, nLevel, bufptr, BufLen, entriesread, totalentries, nSvrType, ByVal 0, resumehandle)
         End If
         If result <> ERROR_SUCCESS And result <> ERROR_MORE_DATA Then
                                                   ' required
            MsgBox ("Error " & result & " enumerating group " & entriesread & " of " & totalentries)
            Exit Sub
          End If
          Dim j As Long
          For i = 1 To entriesread
            ' Get pointer to string from beginning of buffer
            ' Copy 4 byte block of memory each time
            j = (i - 1) * 6
            
            result = PtrToInt(TempPtr.X, bufptr + j * 4, 4)
            nPlatform_id = TempPtr.X
            
            result = PtrToInt(TempPtr.X, bufptr + (j + 1) * 4, 4)
            ' Copy string to array and convert to a string
            result = PtrToStr(SNArray(0), TempPtr.X)
            strSvrName = Left(SNArray, StrLen(TempPtr.X))
            
            result = PtrToInt(TempPtr.X, bufptr + (j + 2) * 4, 4)
            nVersion_major = TempPtr.X
            
            result = PtrToInt(TempPtr.X, bufptr + (j + 3) * 4, 4)
            nVersion_minor = TempPtr.X
            
            result = PtrToInt(TempPtr.X, bufptr + (j + 4) * 4, 4)
            nType = TempPtr.X
            
            result = PtrToInt(TempPtr.X, bufptr + (j + 5) * 4, 4)
            result = PtrToStr(SNArray(0), TempPtr.X)
            strComment = Left(SNArray, StrLen(TempPtr.X))
            'Add A Record Into Return Recordset
            
          
            cboSvrs.AddItem strSvrName
            
          Next i
          
          result = NetAPIBufferFree(bufptr)
      Loop Until entriesread = totalentries
    ' The above condition only valid for reading accounts on NT
    ' but not OK for OS/2 or LanMan' result = NetAPIBufferFree(bufptr)         ' Don't leak memory
End Sub

解决方案 »

  1.   

    但是Server_Info 是如何定义的,如果调试通过我肯定给楼上大虾分。
      

  2.   


    Public Type WKSTA_USER_INFO_1
       wkui1_username As Long
       wkui1_logon_domain As Long
       wkui1_oth_domains As Long
       wkui1_logon_server As Long
    End TypePublic Type Server_Info
        Platform_id As Long
        SvrName As String
        Version_major As Long
        Version_minor As Long
        nType As Long
        Comment As String
    End TypePublic Type G_Grp_Info
     GrpName As String
     GrpComment As String
    End TypePublic Type OS_VER_INFO
            dwMajorVersion As Long
            dwMinorVersion As Long
            dwBuildNumber As Long
            dwPlatformId As Long
            szCSDVersion As String
    End TypePublic Type USER_INFO
       strWkstaName As String '工作站名稱
       strLanGrp As String    '所屬的工作組名稱
       strUsrName As String   '用戶名稱
       strDomainName As String  '网域名稱
       strSvrName As String    '网域PDC
       strUsrFullName As String  '用戶全名
       strPassword As String     '保留
    End Type
    Public tUsrInfo As USER_INFO
    Sub Main()
        .....
        tUsrInfo = GetNUsrInfo
    ......
    End Sub
    Public Function GetNUsrInfo() As USER_INFO
    ......
    Dim tdfRetInfo As WKSTA_USER_INFO_1, nPtrRetInfo As Long
    .............
    NetWkstaUserGetInfo ByVal 0&, 1, nPtrRetInfo
    RtlMoveMemory tdfRetInfo, ByVal nPtrRetInfo, Len(tdfRetInfo)
    '將nPtrRetInfo指針指向的內存塊复制到tdfRetInfo中
    lstrcpy bBufferA(0), tdfRetInfo.wkui1_logon_domain
    '將wkui1_logon_domain指針指向的內存塊复制到一個字節數組中
    '***********************************************
    '這段代碼將NT的NULL TERMINATE的UNICODE字符串轉化為VB的字符串
    strDomainName = bBufferA
    strDomainName = Left(strDomainName, InStr(strDomainName, Chr(0)) - 1)
    *this is the USER_INFO.strDomainName
    ........
    END SUB
      

  3.   


    Ha,forget these:    :PPublic Type MungeLong
         X As Long
         dummy As Integer
    End TypePublic Type MungeInt
       XLo As Integer
       XHi As Integer
       dummy As Integer
     End Type