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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 15
    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
     
     
    ADVERTISEMENT


    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

    - Clocks and Countdowns
    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 12 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek