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

📄 form1.frm

📁 电子书“Visual Basic 6 网络编程实例教程.rar”
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1 
   BackColor       =   &H80000001&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "枚举本地组"
   ClientHeight    =   4050
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5640
   FillColor       =   &H80000001&
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   4050
   ScaleWidth      =   5640
   StartUpPosition =   2  '屏幕中心
   Begin MSComctlLib.ListView ListView1 
      Height          =   2535
      Left            =   360
      TabIndex        =   2
      Top             =   600
      Width           =   4815
      _ExtentX        =   8493
      _ExtentY        =   4471
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
   Begin VB.CommandButton Command1 
      Caption         =   "枚举本地组(&E)"
      Height          =   495
      Left            =   2040
      TabIndex        =   0
      Top             =   3360
      Width           =   1575
   End
   Begin VB.Label Label1 
      BackStyle       =   0  'Transparent
      Caption         =   "Label1"
      ForeColor       =   &H8000000E&
      Height          =   255
      Left            =   480
      TabIndex        =   1
      Top             =   240
      Width           =   4575
   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()
    Dim bServer()  As Byte
   Dim tmp        As String
   
   ListView1.ListItems.Clear
   bServer = "\\tz014" & vbNullChar '计算机名称,清根据自己的计算机进行相应的设置
   tmp = "\\tz014"
   Label1.Caption = "在" & tmp & "上找到" & GetLocalGroups(bServer) & "个组"
End Sub

Private Sub Form_Load()
    With ListView1
      .ColumnHeaders.Add , , "组名"
      .View = lvwReport
      .FullRowSelect = True
   End With
End Sub

Private Function GetLocalGroups(bServer() As Byte) As Long
   Dim bufptr        As Long
   Dim entriesread   As Long
   Dim totalentries  As Long
   Dim success       As Long
   Dim resumehandle  As Long
   Dim nStructSize   As Long
   Dim cnt           As Long
   Dim itmx          As ListItem
   Dim lgis          As LOCALGROUP_INFO_0
   nStructSize = Len(lgis)
   success = NetLocalGroupEnum(bServer(0), _
                               0, bufptr, _
                               MAX_PREFERRED_LENGTH, _
                               entriesread, _
                               totalentries, _
                               resumehandle)
   If success = NERR_SUCCESS And _
      success <> ERROR_MORE_DATA Then
      For cnt = 0 To entriesread - 1
        '获取数据并将其转换为LOCALGROUP_INFO_1格式,然后将数据添加到列表中
         CopyMemory lgis, ByVal bufptr + (nStructSize * cnt), nStructSize
        '将结果添加到列表视中
         Set itmx = ListView1.ListItems.Add(, , GetPointerToByteStringW(lgis.lgrpi1_name))
      Next
   End If
   Call NetApiBufferFree(bufptr)
   GetLocalGroups = entriesread
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 + -