Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 4 - WMI Programming with Visual Basic.NET: Tip...
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 
Moblin 
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

WMI Programming with Visual Basic.NET: Tips and Tricks
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2005-07-19

    Table of Contents:
  • WMI Programming with Visual Basic.NET: Tips and Tricks
  • Retrieving all properties of a WMI class without knowing their names
  • How does the program work?
  • How can we extend the above program to work with all objects?
  • How does this program work?

  • 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

    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!

    WMI Programming with Visual Basic.NET: Tips and Tricks - How can we extend the above program to work with all objects?


    (Page 4 of 5 )

    The above example demonstrates working with only one instance. How can I work with more than one instance simultaneously? In other words, I would like to have each of the device details presented as a single row of information (columns being all the properties and not the rows, as demonstrated previously).

    It is not a different concept, from the WMI point of view. It is just our logic as to how it is implemented. In the previous example, we added property information as a row. Now all the property names should be the columns of the data table. We need to retrieve the instances of logical devices and present them in different rows of the same data table (separated with property values as column values). The following program example gives an idea of the approach.

    'preparing data table structure

           DimdtAsNewDataTable

           DimdiskAsNewManagementObject("Win32_LogicalDisk.deviceid='c:'")

           DimdiskPropertiesAsPropertyDataCollection = disk.Properties

           DimdiskPropertyAsPropertyData

           ForEachdiskPropertyIndiskProperties

                dt.Columns.Add(diskProperty.Name)

           NextdiskProperty

           'populating with rows

           DimsearcherAsNewManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk")

           DimdisksAsManagementObjectCollection = searcher.Get()

           ForEachdiskIndisks

               DimdrAsDataRow = dt.NewRow

                diskProperties = disk.Properties

               ForEachdiskPropertyIndiskProperties

                    dr(diskProperty.Name) = diskProperty.Value

               NextdiskProperty

                dt.Rows.Add(dr)

           Next

           'displaying

            dt.AcceptChanges()

           Me.DataGrid1.DataSource = dt

    Even though, the above program looks bit lengthy, it is very simple to understand. The next section is dedicated to a detailed discussion of the above program.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


     

    VISUAL BASIC.NET ARTICLES

    - Movement and Player Statistics in a VB.NET T...
    - Creating and Drawing a Game Map in VB.NET
    - 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...





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