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

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 / 6
    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


    WMI Programming with Visual Basic.NET: Tips and Tricks - How does this program work?


    (Page 5 of 5 )

    The program can be divided into three parts, for our convenience. The first part deals with preparing the structure (columns of properties) of the data table. The second part fills the data table with all of the information of logical disks. Finally, the third part displays the information back to the form.

    The following can be considered the first part:

    DimdtAsNewDataTable

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

           DimdiskPropertiesAsPropertyDataCollection = disk.Properties

           DimdiskPropertyAsPropertyData

           ForEachdiskPropertyIndiskProperties

                dt.Columns.Add(diskProperty.Name)

           NextdiskProperty

    The above fragment is almost similar to that of the first program we discussed. The main goal of the above fragment is to create columns of the data table. The columns should be the property names themselves. To retrieve the property names, we need to connect to at least one logical device (which would definitely be present). I am connecting to ‘c:’ in this case. Using the FOR loop, I am retrieving all property names and adding them as columns to the data table.

    The following is the second part:

           '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

    If you carefully observe the above fragment, we are using nested loops. The outer loop works on each logical disk, and the inner loop works with the properties of the current logical disk of the outer loop.  This fragment is almost similar to the examples I provided in part three, except that I am using an inner loop. The inner loop actually assigns the information about all of the properties (of a particular disk) to a data row, which gets added to the data table.

    And I hope you can understand the following third part very easily.

           'displaying

            dt.AcceptChanges()

           Me.DataGrid1.DataSource = dt

    The above just ensures that data table is filled. It finally gets displayed using a data grid.


    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.

     

    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