Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - 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 
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

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

    Table of Contents:
  • Getting Hardware Information Using Visual Basic.NET and VBScript
  • The class Win32 OnBoardDevice in detail
  • The class Win32_Processor in detail
  • Digging further into the motherboard's details

  • 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

    Getting Hardware Information Using Visual Basic.NET and VBScript - Digging further into the motherboard's details


    (Page 4 of 4 )

    What about the motherboard? After all, it's the heart of the system! Let us dig up even that information. The following VB.NET code should support retrieving some minimum information on your server.

    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_BaseBoard")
                Dim dt As DataTable = globals.getBaseBoardStructure
                For Each queryObj As ManagementObject In searcher.Get()
                    globals.addBaseBoard(dt, queryObj("HostingBoard"), queryObj("Manufacturer"), queryObj("PoweredOn"), queryObj("Product"), queryObj("SerialNumber"), queryObj("Version"))
                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_BaseBoard",,48)
    For Each objItem in colItems
        Wscript.Echo "HostingBoard: " & objItem.HostingBoard
        Wscript.Echo "Manufacturer: " & objItem.Manufacturer
        Wscript.Echo "PoweredOn: " & objItem.PoweredOn
        Wscript.Echo "Product: " & objItem.Product
        Wscript.Echo "SerialNumber: " & objItem.SerialNumber
        Wscript.Echo "Version: " & objItem.Version
    Next

    As the properties are quite understandable (just from the words), I am not going to explain much. But for further information (or all properties of the class “Win32_BaseBoard”) you can refer to MSDN.

    The wrappers for Win32_Processor, Win32_OnBoardDevice and Win32_BaseBoard

    In all of the above VB.NET programs, you must have observed some statements like the following:

    globals.getOnBoardDeviceStructure
    globals.addOnBoardDevice
    globals.getProcessorStructure
    globals.addProcessorDevice
    etc

    Those are actually the wrapper in-memory tables; I designed them to work flexibly with those classes (“Win32_Processor”, “Win32_OnBoardDevice” and “Win32_BaseBoard”). The wrappers are defined below.

    The following would be the wrapper for “Win32_Processor”:

    Public Function getProcessorStructure() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add (New DataColumn("Availability"))
            dt.Columns.Add (New DataColumn("Caption"))
            dt.Columns.Add (New DataColumn("CpuStatus"))
            dt.Columns.Add (New DataColumn("CurrentClockSpeed"))
            dt.Columns.Add (New DataColumn("DeviceID"))
            dt.Columns.Add (New DataColumn("Level"))
            dt.Columns.Add (New DataColumn("Name"))
            dt.Columns.Add (New DataColumn("ProcessorId"))
            dt.Columns.Add (New DataColumn("ProcessorType"))
            dt.Columns.Add (New DataColumn("SystemName"))
            Return dt
        End Function

    The following would be the wrapper for “Win32_OnBoardDevice”:

    Public Function getOnBoardDeviceStructure() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add (New DataColumn("Description"))
            dt.Columns.Add (New DataColumn("DeviceType"))
            dt.Columns.Add (New DataColumn("Enabled"))
            dt.Columns.Add (New DataColumn("Tag"))
            Return dt
        End Function

    The following would be the wrapper for “Win32_BaseBoard”:

    Public Function getBaseBoardStructure() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("HostingBoard"))
            dt.Columns.Add(New DataColumn("Manufacturer"))
            dt.Columns.Add(New DataColumn("PoweredOn"))
            dt.Columns.Add(New DataColumn("Product"))
            dt.Columns.Add(New DataColumn("SerialNumber"))
            dt.Columns.Add(New DataColumn("Version"))
            Return dt
        End Function

    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 interesting article on WMI with VB.NET and VBScript. Enjoy and...
       · The articles do not give the code for addONBoardDevices and addProcessorDevice ....
       · Hi, I already provided the code in the downloadable. Please download the zip...
     

    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 5 hosted by Hostway