Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - Getting Hardware Information using 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 
Moblin 
JMSL Numerical Library 
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

Getting Hardware Information using Visual Basic.NET and VBScript continued
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2006-02-01

    Table of Contents:
  • Getting Hardware Information using Visual Basic.NET and VBScript continued
  • Listing the “BUS” information
  • Listing the “MotherBoard” information
  • Listing the Memory information
  • Listing the “Sound Device” information

  • 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


    Getting Hardware Information using Visual Basic.NET and VBScript continued - Listing the “BUS” information


    (Page 2 of 5 )

    Some scenarios may require some properties of the BUS to be listed. We can retrieve the same information dynamically using VB.NET.  Before trying to retrieve the hardware information, let us create the wrapper with BUS structure:

     Public Function getBusStructure() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("BusType"))
            dt.Columns.Add(New DataColumn("DeviceID"))
            dt.Columns.Add(New DataColumn("PNPDeviceID"))
            dt.Columns.Add(New DataColumn("SystemName"))
            Return dt
        End Function

    The following method “addBus” adds a single row based on the structure you create for the data table using the above method.

         Public Sub addBus(ByRef dt As DataTable, ByVal BusType As String, ByVal DeviceID As String, ByVal PNPDeviceID As String, ByVal SystemName As String)
            Dim dr As DataRow
            dr = dt.NewRow
            dr("BusType") = BusType
            dr("DeviceID") = DeviceID
            dr("PNPDeviceID") = PNPDeviceID
            dr("SystemName") = SystemName
            dt.Rows.Add(dr)
        End Sub

    Once you complete the creation of wrapper, the following VB.NET code should support retrieving some minimum information about the BUS 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_Bus")
                Dim dt As DataTable = globals.getBusStructure
                For Each queryObj As ManagementObject In searcher.Get()
                    globals.addBus(dt, Convert.ToString(queryObj("BusType")), queryObj("DeviceID"), queryObj("PNPDeviceID"), queryObj("SystemName"))
                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

    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_Bus",,48)
    For Each objItem in colItems
        Wscript.Echo "BusType: " & objItem.BusType
        Wscript.Echo "DeviceID: " & objItem.DeviceID
        Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
        Wscript.Echo "SystemName: " & objItem.SystemName
    Next

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hi guys, another contribution on WMI. Have any doubts (or wanted articles)? feel...
     

    VISUAL BASIC.NET ARTICLES

    - 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...
    - Creating and Drawing a Game Map in VB.NET (F...
    - 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 ...





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