Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Retrieving Networking Configuration Inform...
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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

Retrieving Networking Configuration Information Using Visual Basic.NET and VBScript
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2006-01-11

    Table of Contents:
  • Retrieving Networking Configuration Information Using Visual Basic.NET and VBScript
  • How to List all IPAddresses of a computer using Visual Basic.NET – the code
  • How to retrieve MAC address and other miscellaneous network information using Visual Basic.NET – preparing the wrapper
  • How to retrieve MAC address and other miscellaneous network information using Visual Basic.NET – the code
  • How to retrieve Network Client Information using Visual Basic.NET
  • How to retrieve Win Proxy Information using Visual Basic.NET

  • 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


    Retrieving Networking Configuration Information Using Visual Basic.NET and VBScript - How to List all IPAddresses of a computer using Visual Basic.NET – the code


    (Page 2 of 6 )

    Once you complete the creation of the wrapper (as specified in the previous section), proceed with the following VB.NET code to list all the details of the network configuration information available on your system.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Try
                Dim searcher As New ManagementObjectSearcher( _
                         "root\CIMV2", _
                         "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
                Dim dt As DataTable = globals.getNetworkInfoStructure
                For Each queryObj As ManagementObject In searcher.Get()
                    Dim IPAddress As String = ""
                    If queryObj("IPAddress") Is Nothing Then
                        IPAddress = queryObj("IPAddress")
                    Else
                        Dim arrIPAddress As String()
                        arrIPAddress = queryObj("IPAddress")
                        For Each arrValue As String In arrIPAddress
                            IPAddress &= arrValue
                        Next
                    End If
                    globals.addNetworkInfo(dt, queryObj("Caption"), queryObj("Description"), queryObj("DHCPEnabled"), queryObj("DHCPServer"), queryObj("DNSDomain"), queryObj("DNSHostName"), IPAddress)
     
                Next
                Me.DataGrid1.DataSource = dt
     
            Catch err As ManagementException
                MessageBox.Show("An error occurred while querying for WMI data: " & err.Message)
            End Try

    You can achieve the same thing with VBScript as follows:

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery( _
        "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48)
    For Each objItem in colItems
        Wscript.Echo "Caption: " & objItem.Caption
        Wscript.Echo "Description: " & objItem.Description
        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
    Next

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · [i]This article explains how to retrieve “Network settings” information dynamically...
       · This is a very good article, but a little insight on adding a reference for...
       · Hello,Actually, within the same article I already added the following...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT