⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 电子书“Visual Basic 6 网络编程实例教程.rar”
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "枚举域中的服务器及机器"
   ClientHeight    =   2970
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   3735
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2970
   ScaleWidth      =   3735
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command1 
      Caption         =   "运行(&R)"
      Height          =   375
      Left            =   1440
      TabIndex        =   1
      Top             =   2400
      Width           =   1095
   End
   Begin VB.ListBox List1 
      Height          =   2040
      Left            =   840
      TabIndex        =   0
      Top             =   240
      Width           =   2655
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "服务器"
      Height          =   180
      Left            =   240
      TabIndex        =   2
      Top             =   240
      Width           =   540
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub Command1_Click()
    Call GetServers(vbNullString)
End Sub

Private Function GetServers(sDomain As String) As Long

  '列举域中可见的指定类型的服务器
   Dim bufptr          As Long
   Dim dwEntriesread   As Long
   Dim dwTotalentries  As Long
   Dim dwResumehandle  As Long
   Dim se100           As SERVER_INFO_100
   Dim success         As Long
   Dim nStructSize     As Long
   Dim cnt             As Long
   nStructSize = LenB(se100)
'使用MAX_PREFERRED_LENGTH,以让函数为返回的数据分配足够的空间
  '调用函数列举网络中的所有机器(SV_TYPE_ALL),
  '可以通过组合掩码位来列举几种类型的服务器。
  '例如,0X00000003就是SV_TYPE_WORKSTATION(0X00000001)
  '和SV_TYPE_SERVER(0X00000002)的组合。
  '参数dwServerName必须为Null. 参数level的值(这里为100)
  '指定了函数使用的数据结构(此为SERVER_INFO_100)
  '成员domain的值为Null,以返回域中的所有的机器。
   success = NetServerEnum(0&, _
                           100, _
                           bufptr, _
                           MAX_PREFERRED_LENGTH, _
                           dwEntriesread, _
                           dwTotalentries, _
                           SV_TYPE_ALL, _
                           0&, _
                           dwResumehandle)
   If success = NERR_SUCCESS And _
      success <> ERROR_MORE_DATA Then
    '提取返回的数据,并添加到列表中
    For cnt = 0 To dwEntriesread - 1
        '获取数据,并将其转换为SERVER_INFO_100结构类型
         CopyMemory se100, ByVal bufptr + (nStructSize * cnt), nStructSize
         List1.AddItem GetPointerToByteStringW(se100.sv100_name)
      Next
   End If
  '释放bufptr
   Call NetApiBufferFree(bufptr)
  '返回入口
   GetServers = dwEntriesread
End Function

Public Function GetPointerToByteStringW(ByVal dwData As Long) As String
  
   Dim tmp() As Byte
   Dim tmplen As Long
   If dwData <> 0 Then
      tmplen = lstrlenW(dwData) * 2
      If tmplen <> 0 Then
         ReDim tmp(0 To (tmplen - 1)) As Byte
         CopyMemory tmp(0), ByVal dwData, tmplen
         GetPointerToByteStringW = tmp
     End If
   End If
End Function

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -