Login or Sign Up to become a member!

EXPERTS, INFORMATION, IDEAS & KNOWLEDGE

Social bookmarker Add this

VB.Net: Getting a List of Networkconnections on a computer

From Wiki

Jump to: navigation, search

With WMI it is pretty simple to do.

  1. Imports System.Management
  2.  
  3. Module Module1
  4.  
  5.     Sub Main()
  6.         GetNetworkInfo(My.Computer.Name)
  7.         Console.ReadLine()
  8.     End Sub
  9.  
  10.     Public Sub GetNetworkInfo(ByVal Machine As String)
  11.         Dim scope As New System.Management.ManagementScope("\\" + Machine + "\root\cimv2")
  12.         scope.Connect()
  13.         Dim objectQuery As New ObjectQuery("SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionId IS NOT NULL")
  14.         Dim searcher As New ManagementObjectSearcher(scope, objectQuery)
  15.         Dim os As ManagementObject
  16.         Dim moColl As ManagementObjectCollection = searcher.Get()
  17.         Dim _list As String = ""
  18.         For Each os In moColl
  19.             Console.WriteLine(os("NetConnectionId"))
  20.         Next os
  21.     End Sub
  22.  
  23.    
  24. End Module

With this as a result (on my computer)

Local Area Connection
VMware Network Adapter VMnet1
VMware Network Adapter VMnet8

583 Rating: 0.0/5 (0 votes cast)