Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - WMI Programming with Visual Basic.NET: Bre...
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

WMI Programming with Visual Basic.NET: Breaking the Ice
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 14
    2005-06-21

    Table of Contents:
  • WMI Programming with Visual Basic.NET: Breaking the Ice
  • Our first program to connect to WMI (on a local computer)
  • Getting information from WMI
  • Our first program to connect to WMI (on a remote computer)

  • 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
     
    IBM developerWorks
     
    ADVERTISEMENT

    Ajax Application Generator Generate database 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: Breaking the Ice - Our first program to connect to WMI (on a local computer)


    (Page 2 of 4 )

    I just gave you a huge amount of theory without any practical examples. Now we shall create a simple windows application using Visual Basic.NET to get some information from WMI. Let's start by opening Visual Studio.NET 2003 Enterprise Architect.

    • After opening Visual Studio.NET 2003 IDE, go to File menu -> new -> Project.

    • Within the Visual Basic projects, select the "Windows Application" template (as shown in Fig. 1 below) and provide the name as "WMISample" at your own location and finally click OK.



      Figure 1
    • Drag a button and a listbox from the toolbox onto the form.

    • Name them as "btnShowDrives" and "lstDrives" respectively. The form should look like the one in Fig. 2 below.


      Figure 2
    • Go to Project menu -> Add Reference. Choose System.Management in the list of components (of .NET tab) and pressthe  "select" button. Finally click OK. You should be able to see System.Management as part of "references" in the solution explorer.

    • Modify your code so that it looks like the following:

      Imports System
      Imports System.Management

      Public Class Form1
      Inherits System.Windows.Forms.Form
      .
      .
      .

        Private Sub btnShowDrives_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowDrives.Click
          'connect to "Win32_LogicalDisk" class of WMI
          Dim diskClass As New ManagementClass("Win32_LogicalDisk")
          'get the information
          Dim disks As ManagementObjectCollection = diskClass.GetInstances()
          'loop the information to store in an array
          Dim disk As ManagementObject
          Dim arDisks As New ArrayList
          For Each disk In disks
            arDisks.Add(disk("deviceid").ToString())
          Next disk
          'populate the listbox
          Me.lstDrives.Items.AddRange(arDisks.ToArray)
        End Sub
      End Class

    • Now, press F5 to execute the program. Click on the "Show Drives" button. And you should be able to see the listbox filled with all the drives attached (logically) to your computer (as in Fig.3).

    Figure 3

    Don't ignore the next section. It not only explains the above program, but also gives you a few tips on some interesting aspects.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · nice article. just what i wanted
     

    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

    Iron Speed




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