===================枚举局域网上的所有计算机==================== Dim p_lngRtn As Long Dim p_lngEnumHwnd As Long Dim p_lngCount As Long Dim p_lngLoop As Long Dim p_lngBufSize As Long Dim p_atypNetAPI(0 To MAX_RESOURCES) As NETRESOURCE, p_atypNetAPI1(0 To MAX_RESOURCES) As NETRESOURCE Dim groupuser p_lngEnumHwnd = 0& p_lngRtn = WNetOpenEnum(dwScope:=RESOURCE_GLOBALNET, dwType:=RESOURCETYPE_ANY, dwUsage:=RESOURCEUSAGE_ALL, lpNetResource:=ByVal 0&, lppEnumHwnd:=p_lngEnumHwnd) If p_lngRtn = NO_ERROR Then p_lngCount = RESOURCE_ENUM_ALL p_lngBufSize = UBound(p_atypNetAPI) * Len(p_atypNetAPI(0)) p_lngRtn = WNetEnumResource(pEnumHwnd:=p_lngEnumHwnd, lpcCount:=p_lngCount, lpBuffer:=p_atypNetAPI(0), lpBufferSize:=p_lngBufSize) End If If p_lngEnumHwnd <> 0 Then Call WNetCloseEnum(p_lngEnumHwnd) End If p_lngRtn = WNetOpenEnum(dwScope:=RESOURCE_GLOBALNET, dwType:=RESOURCETYPE_ANY, dwUsage:=RESOURCEUSAGE_ALL, lpNetResource:=p_atypNetAPI(0), lppEnumHwnd:=p_lngEnumHwnd) If p_lngRtn = NO_ERROR Then p_lngCount = RESOURCE_ENUM_ALL p_lngBufSize = UBound(p_atypNetAPI) * Len(p_atypNetAPI(0)) p_lngRtn = WNetEnumResource(pEnumHwnd:=p_lngEnumHwnd, lpcCount:=p_lngCount, lpBuffer:=p_atypNetAPI(0), lpBufferSize:=p_lngBufSize) If p_lngCount > 0 Then For p_lngLoop = 0 To p_lngCount - 1 p_lngRtn = WNetOpenEnum(dwScope:=RESOURCE_GLOBALNET, dwType:=RESOURCETYPE_ANY, dwUsage:=RESOURCEUSAGE_ALL, lpNetResource:=p_atypNetAPI(p_lngLoop), lppEnumHwnd:=p_lngEnumHwnd) If p_lngRtn = NO_ERROR Then p_lngCount = RESOURCE_ENUM_ALL p_lngBufSize = UBound(p_atypNetAPI) * Len(p_atypNetAPI1(0)) p_lngRtn = WNetEnumResource(pEnumHwnd:=p_lngEnumHwnd, lpcCount:=p_lngCount, lpBuffer:=p_atypNetAPI1(0), lpBufferSize:=p_lngBufSize) If p_lngCount > 0 Then Dim i For i = 0 To p_lngCount - 1 '------------------------如计算机机名不同本机名刚加入列表中------------------------------ groupuser = PointerToAsciiStr(p_atypNetAPI1(i).pRemoteName) If Right(groupuser, Len(groupuser) - 2) <> computername Then If lsv1.FindItem(Right(groupuser, Len(groupuser) - 2)) Is Nothing Then lsv1.ListItems.Add lsv1.ListItems.Count + 1, , Right(groupuser, Len(groupuser) - 2), , 2 Else If lsv1.FindItem(Right(groupuser, Len(groupuser) - 2)).SubItems(3) <> " " Then lsv1.FindItem(Right(groupuser, Len(groupuser) - 2)).SmallIcon = 1 End If End If End If Next i End If End If Next p_lngLoop End If End If If p_lngEnumHwnd <> 0 Then Call WNetCloseEnum(p_lngEnumHwnd) End If
|