SunQuest
 
       Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Digging into Network Adapters with Visual ...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Digging into Network Adapters with Visual Basic.NET and VBScript using WMI
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2006-04-17

    Table of Contents:
  • Digging into Network Adapters with Visual Basic.NET and VBScript using WMI
  • Listing network adapter information using WMI
  • Listing extended information about network adapters using WMI
  • Listing network connection information using WMI

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Digging into Network Adapters with Visual Basic.NET and VBScript using WMI - Listing network adapter information using WMI


    (Page 2 of 4 )

    How do you list all of the network adapters available on your system?  We'll assume that you also want a list of all bridges and other logical network connections as well.

    Before going to the WMI code, we need to define the cache to store that information.  The following are the two routines I declared in "globals.vb" to hold the cache of information.

    Public Function getNetworkAdapterStructure() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("AdapterType"))
            dt.Columns.Add(New DataColumn("MACAddress"))
            dt.Columns.Add(New DataColumn("Manufacturer"))
            Return dt
        End Function
     
        Public Sub addNetworkAdapterRow(ByRef dt As DataTable, ByVal
    AdapterType As String, ByVal MACAddress As String, ByVal
    Manufacturer As String)
            Dim dr As DataRow
            dr = dt.NewRow
            dr("AdapterType") = AdapterType
            dr("MACAddress") = MACAddress
            dr("Manufacturer") = Manufacturer
            dt.Rows.Add(dr)
        End Sub

    The following is the WMI code to retrieve our desired information.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
    As System.EventArgs) Handles Button1.Click
            Try
                Dim searcher As New ManagementObjectSearcher( _
                    "rootCIMV2", _
                    "SELECT * FROM Win32_NetworkAdapter")
                Dim dt As DataTable =
    globals.getNetworkAdapterStructure
                For Each queryObj As ManagementObject In searcher.Get
    ()
                    globals.addNetworkAdapterRow(dt, queryObj
    ("AdapterType"), queryObj("MACAddress"), queryObj
    ("Manufacturer"))
                Next
                Me.DataGrid1.DataSource = dt
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for
    WMI data: " & err.Message)
            End Try
        End Sub

    I excluded some of the properties (as it would make the program too long) from the existing WMI class (Win32_NetworkAdapter) to give you only the most important ones.  The above program would list the MACAddress, Manufacturer and AdapterType. You can further extend the above program with several other properties available in the "Win32_NetworkAdapter" class.  You can even refer to MSDN online for further properties.

    You can achieve the same thing with VBScript using the following code:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & strComputer &
    "rootCIMV2")
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM Win32_NetworkAdapter",,48)
    For Each objItem in colItems
        Wscript.Echo "AdapterType: " & objItem.AdapterType
        Wscript.Echo "MACAddress: " & objItem.MACAddress
        Wscript.Echo "Manufacturer: " & objItem.Manufacturer
    Next

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys. Another contribution on WMI with Visual Basic.NET and VBScript. Now I...
     

    VISUAL BASIC.NET ARTICLES

    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway