Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - 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 
VeriSign Whitepapers 
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 extended information about network adapters using WMI


    (Page 3 of 4 )

    In the previous section, we only displayed preliminary information.  The users may need further extended information like IP address, DHCP information, and so on from network adapters using WMI.  Let us see how to get it using VB.NET:

    Try
                Dim searcher As New ManagementObjectSearcher( _
                    "rootCIMV2", _
                    "SELECT * FROM
    Win32_NetworkAdapterConfiguration")
                For Each queryObj As ManagementObject In searcher.Get
    ()
                    Me.TextBox1.Text &= "Caption: " + queryObj
    ("Caption") & ControlChars.NewLine
                    Me.TextBox1.Text &= "DHCPEnabled: " + (queryObj
    ("DHCPEnabled").ToString) & ControlChars.NewLine
                    Me.TextBox1.Text &= "DHCPServer: " + queryObj
    ("DHCPServer") & ControlChars.NewLine
                    Me.TextBox1.Text &= "DNSDomain: " + queryObj
    ("DNSDomain") & ControlChars.NewLine
                    Me.TextBox1.Text &= "DNSHostName: " + queryObj
    ("DNSHostName") & ControlChars.NewLine
     
                    If queryObj("IPAddress") Is Nothing Then
                        Me.TextBox1.Text &= "IPAddress: " + queryObj
    ("IPAddress") & ControlChars.NewLine
                    Else
                        Dim arrIPAddress As String()
                        arrIPAddress = queryObj("IPAddress")
                        For Each arrValue As String In arrIPAddress
                            Me.TextBox1.Text &= "IPAddress: {0}" +
    arrValue & ControlChars.NewLine
                        Next
                    End If
     
                    If queryObj("IPSubnet") Is Nothing Then
                        Me.TextBox1.Text &= "IPSubnet: " + queryObj
    ("IPSubnet") & ControlChars.NewLine
                    Else
                        Dim arrIPSubnet As String()
                        arrIPSubnet = queryObj("IPSubnet")
                        For Each arrValue As String In arrIPSubnet
                            Me.TextBox1.Text &= "IPSubnet: {0}" +
    arrValue & ControlChars.NewLine
                        Next
                    End If
                    Me.TextBox1.Text &= "MACAddress: {0}" + queryObj
    ("MACAddress") & ControlChars.NewLine
                    Me.TextBox1.Text &=
    "======================================" & ControlChars.NewLine
                Next
     
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for
    WMI data: " & err.Message)
            End Try

    I excluded some of the properties (as it would make the program too long) from the existing WMI class (Win32_NetworkAdapterConfiguration) to give you only the most important ones.  The above program would list the Caption, status of DHCP, DHCP Server IP if available, DNS info, IP address of the adapter and so on. You can further extend the above program with several other properties available in the "Win32_NetworkAdapterConfiguration" class.  You can even refer to MSDN online for further properties.

    You can achieve the same thing with VB Script by using the following code:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & strComputer &
    "rootCIMV2")
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM Win32_NetworkAdapterConfiguration",,48)
    For Each objItem in colItems
        Wscript.Echo "Caption: " & objItem.Caption
        Wscript.Echo "DHCPEnabled: " & objItem.DHCPEnabled
        Wscript.Echo "DHCPServer: " & objItem.DHCPServer
        Wscript.Echo "DNSDomain: " & objItem.DNSDomain
        Wscript.Echo "DNSHostName: " & objItem.DNSHostName
        If isNull(objItem.IPAddress) Then
            Wscript.Echo "IPAddress: "
        Else
            Wscript.Echo "IPAddress: " & Join(objItem.IPAddress, ",")
        End If
        If isNull(objItem.IPSubnet) Then
            Wscript.Echo "IPSubnet: "
        Else
            Wscript.Echo "IPSubnet: " & Join(objItem.IPSubnet, ",")
        End If
        Wscript.Echo "MACAddress: " & objItem.MACAddress
    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

    - 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...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic





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