Visual Basic.NET
  Home arrow Visual Basic.NET arrow Getting Hardware Information using Visual ...
Iron Speed
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 
Download TestComplete 
Windows Web Hosting
 
IBM® developerWorks 
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
     
     
    Iron Speed
     
    ADVERTISEMENT

    Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!

    Getting Hardware Information using Visual Basic.NET and VBScript continued
    (Page 1 of 5 )

    This article explains how to retrieve hardware information using both Visual Basic.NET and VBScript. In my previous article, I covered motherboards, onboard devices and processors. In this article, I concentrate on BIOS, BUS, motherboard, memory and audio related information.
    A downloadable file for this article is available here.

    The sample downloadable solution (zip) was entirely developed using Visual Studio.NET 2003 Enterprise Architect on Windows Server 2003 Standard Edition.  But I am confident that it would work with other versions of Windows (which support .NET 1.1) as well.

    I contributed several articles on WMI with VB.NET and VBScript (including the articles on introductory or basic topics of WMI).  I even contributed a series (of about six articles) on “WMI Programming on VB.NET” covering several aspects of WMI.  I strongly suggest you go through the series, before going through this article.

    Listing the “BIOS” information

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

    Public Sub addRow(ByRef dt As DataTable, ByVal p As String, ByVal
    v As String)
            Dim dr As DataRow
            dr = dt.NewRow
            dr("Property") = p
            dr("Value") = v
            dt.Rows.Add(dr)
        End Sub

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

    Public Function getStructure() As DataTable
            Dim dt As New DataTable
            dt.Columns.Add(New DataColumn("Property"))
            dt.Columns.Add(New DataColumn("Value"))
            Return dt
        End Function

    Once you complete the creation of wrapper, the following VB.NET code should support retrieval of some minimum information about the BIOS 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_BIOS")
                Dim dt As DataTable = globals.getStructure
                For Each queryObj As ManagementObject In searcher.Get
    ()
                    If queryObj("BIOSVersion") Is Nothing Then
                        globals.addRow(dt,"BIOSVersion", queryObj
    ("BIOSVersion"))
                    Else
                        Dim arrBIOSVersion As String()
                        arrBIOSVersion = queryObj("BIOSVersion")
                        For Each arrValue As String In arrBIOSVersion
                            globals.addRow(dt, "BIOSVersion",
    arrValue)
                        Next
                    End If
                    globals.addRow(dt, "CurrentLanguage", queryObj
    ("CurrentLanguage"))
                    globals.addRow(dt, "Description", queryObj
    ("Description"))
                    globals.addRow(dt, "Manufacturer", queryObj
    ("Manufacturer"))
                    globals.addRow(dt, "PrimaryBIOS", queryObj
    ("PrimaryBIOS"))
                    globals.addRow(dt, "ReleaseDate", queryObj
    ("ReleaseDate"))
                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_BIOS",,48)
    For Each objItem in colItems
        If isNull(objItem.BIOSVersion) Then
            Wscript.Echo "BIOSVersion: "
        Else
            Wscript.Echo "BIOSVersion: " & Join(objItem.BIOSVersion,
    ",")
        End If
        Wscript.Echo "CurrentLanguage: " & objItem.CurrentLanguage
        Wscript.Echo "Description: " & objItem.Description
        Wscript.Echo "Manufacturer: " & objItem.Manufacturer
        Wscript.Echo "PrimaryBIOS: " & objItem.PrimaryBIOS
        Wscript.Echo "ReleaseDate: " & objItem.ReleaseDate
    Next
     

    VISUAL BASIC.NET ARTICLES

    - 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
    - Manipulating Forms with the Windows Forms Li...
    - Basics of the Windows Forms Library
    - Forms, Controls, and Other Useful Objects
    - Implementing OOP to Develop Database Oriente...
    - Using Themes and Skins for Personalization w...
    - A Deeper Look at Personalization using Visua...




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