Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - 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 network connection information using WMI


    (Page 4 of 4 )

    Before going into 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 getNetworkConnectionStructure() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("Caption"))
            dt.Columns.Add(New DataColumn("ConnectionState"))
            dt.Columns.Add(New DataColumn("ConnectionType"))
            dt.Columns.Add(New DataColumn("Description"))
            dt.Columns.Add(New DataColumn("Name"))
            dt.Columns.Add(New DataColumn("RemoteName"))
            dt.Columns.Add(New DataColumn("RemotePath"))
            Return dt
        End Function
     
        Public Sub addNetworkConnectionRow(ByRef dt As DataTable,
    ByVal Caption As String, ByVal ConnectionState As String, ByVal
    ConnectionType As String, ByVal Description As String, ByVal Name
    As String, ByVal RemoteName As String, ByVal RemotePath As
    String)
            Dim dr As DataRow
            dr = dt.NewRow
            dr("Caption") = Caption
            dr("ConnectionState") = ConnectionState
            dr("ConnectionType") = ConnectionType
            dr("Description") = Description
            dr("Name") = Name
            dr("RemoteName") = RemoteName
            dr("RemotePath") = RemotePath
            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_NetworkConnection")
                Dim dt As DataTable =
    globals.getNetworkConnectionStructure
                For Each queryObj As ManagementObject In searcher.Get
    ()
                    globals.addNetworkConnectionRow(dt, queryObj
    ("Caption"), queryObj("ConnectionState"), queryObj
    ("ConnectionType"), queryObj("Description"), queryObj("Name"),
    queryObj("RemoteName"), queryObj("RemotePath"))
                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_NetworkConnection) to give you only the most important ones.  The above program would list  the Caption, State of Connection, Type of Connection, Remote Name, Remote Path, and so on. You can further extend the above program with several other properties available in the "Win32_NetworkConnection" class.  You can even refer to MSDN online for further properties.

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

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & strComputer &
    "rootCIMV2")
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM Win32_NetworkConnection",,48)
    For Each objItem in colItems
        Wscript.Echo "Caption: " & objItem.Caption
        Wscript.Echo "ConnectionState: " & objItem.ConnectionState
        Wscript.Echo "ConnectionType: " & objItem.ConnectionType
        Wscript.Echo "Description: " & objItem.Description
        Wscript.Echo "Name: " & objItem.Name
        Wscript.Echo "RemoteName: " & objItem.RemoteName
        Wscript.Echo "RemotePath: " & objItem.RemotePath
    Next

    Summary

    You can further delve into the classes of WMI and design your own application to retrieve almost every important aspect of network adapters.  If you extend your skills to ASP.NET, then you can develop a web application which can retrieve your network information on the fly, without your presence in the office itself!  I think you can imagine a similar application at the Pocket PC level!  Good luck.

    If you need articles on any particular topic of WMI, do not hesitate to post in the discussion.  I shall definitely help you out. 

    Any comments, suggestions, bugs, errors, feedback etc. are highly appreciated at jag_chat@yahoo.com.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · 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 1 hosted by Hostway