接続されているすべてのネットワーク コンピューターをリスト ボックスに一覧表示したいと考えています。誰も方法を知っていますか?
質問する
10583 次
2 に答える
10
への参照を追加します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
于 2013-03-10T20:51:18.307 に答える
0
完璧ではない場合は、これを取得するためにいくつかのコードを切り刻みました(役立つことを願っています)...
Private Sub GetCurrentDevices()
Try
Dim ps As New System.Diagnostics.ProcessStartInfo("arp", "-a ")
ps.RedirectStandardOutput = True
ps.UseShellExecute = False
ps.WindowStyle = ProcessWindowStyle.Hidden
ps.CreateNoWindow = True
Dim sbResults As New StringBuilder
Using proc As New System.Diagnostics.Process()
proc.StartInfo = ps
proc.Start()
Dim sr As System.IO.StreamReader = proc.StandardOutput
While Not proc.HasExited
System.Threading.Thread.Sleep(100)
End While
sbResults.Append(sr.ReadToEnd)
End Using
Dim IP_Address, MAC_Address, Device_Name As String
Dim AllOutputLines() As String = sbResults.ToString.Split(vbCrLf)
sbResults = Nothing
For Each IndividualOutputLine As String In AllOutputLines
Windows.Forms.Application.DoEvents()
If IndividualOutputLine.Contains("dynamic") Then
Dim Entries() As String = IndividualOutputLine.Split(New String() {}, StringSplitOptions.RemoveEmptyEntries)
If Entries.Length = 3 Then
'Here is your info ...
IP_Address = Entries(0)
MAC_Address = Entries(1).ToUpper
Device_Name = GetComputerName(IP_Address)
End If
End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Private Function GetComputerName(ByVal IP_Address As String) As String
Dim ReturnValue As String = cUnknown
Try
Dim myIPs As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry(IP_Address)
ReturnValue = myIPs.HostName
myIPs = Nothing
Catch ex As Exception
End Try
If ReturnValue = IP_Address Then ReturnValue = cUnknown
Return ReturnValue
End Function
于 2013-03-10T20:21:20.243 に答える