📄 form1.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 = 4080
ClientLeft = 45
ClientTop = 330
ClientWidth = 7755
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 4080
ScaleWidth = 7755
StartUpPosition = 2 '屏幕中心
Begin MSComctlLib.ListView ListView1
Height = 2655
Left = 240
TabIndex = 1
Top = 480
Width = 7215
_ExtentX = 12726
_ExtentY = 4683
LabelWrap = -1 'True
HideSelection = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
Begin VB.CommandButton Command1
Caption = "运行(&R)"
Height = 495
Left = 3120
TabIndex = 0
Top = 3360
Width = 1575
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "Label1"
ForeColor = &H00FFFFFF&
Height = 255
Left = 360
TabIndex = 2
Top = 120
Width = 6375
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"
Dim Nums As Long
Nums = GetLocalGroupsAndDescription(bServer)
Label1.Caption = "在" & tmp & "上找到" & Nums & "个组"
End Sub
Private Sub Form_Load()
With ListView1
.ColumnHeaders.Add , , "组名"
.ColumnHeaders.Add , , "描述"
.ColumnHeaders.Item(1).Width = 2000
.ColumnHeaders.Item(2).Width = 3800
.View = lvwReport
.FullRowSelect = True
End With
End Sub
Private Function GetLocalGroupsAndDescription(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_1
nStructSize = Len(lgis)
success = NetLocalGroupEnum(bServer(0), _
1, 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))
itmx.SubItems(1) = GetPointerToByteStringW(lgis.lgrpi1_comment)
Next
End If
GetLocalGroupsAndDescription = 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 + -