gpt4 book ai didi

vb.net - 网络 VB.Net 上的计算机名称

转载 作者:行者123 更新时间:2023-12-01 08:33:15 26 4
gpt4 key购买 nike

我想在一个列表框中列出所有连接的网络计算机。有人知道怎么做吗?

最佳答案

添加对 System.DirectoryServices 的引用。

添加;

Imports System.DirectoryServices

然后使用;

Private Delegate Sub UpdateDelegate(ByVal s As String)

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

Dim t As New Threading.Thread(AddressOf GetNetworkComputers)
t.IsBackground = True
t.Start()

End Sub

Private Sub AddListBoxItem(ByVal s As String)
ListBox1.Items.Add(s)
End Sub

Private Sub GetNetworkComputers()
Dim alWorkGroups As New ArrayList
Dim de As New DirectoryEntry

de.Path = "WinNT:"
For Each d As DirectoryEntry In de.Children
If d.SchemaClassName = "Domain" Then alWorkGroups.Add(d.Name)
d.Dispose()
Next

For Each workgroup As String In alWorkGroups

de.Path = "WinNT://" & workgroup
For Each d As DirectoryEntry In de.Children

If d.SchemaClassName = "Computer" Then

Dim del As UpdateDelegate = AddressOf AddListBoxItem
Me.Invoke(del, d.Name)

End If

d.Dispose()

Next
Next
End Sub

关于vb.net - 网络 VB.Net 上的计算机名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15318055/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com