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

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

    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: Tips and Tricks
    (Page 1 of 5 )

    In my previous article, part four of this series, we looked into managing OS using WMI methods. In this article, we will look into some tips and tricks for using WMI.


    You can download the zip of entire Visual Studio.NET solution (developed for this article) here.

    The first part of my series gives you the details for creating a Visual Studio.NET solution for WMI from scratch.  It will not be repeated anymore in any of the future articles in this series.

    Can we start another application (process) through WMI?

    In all of my examples in the previous part, we worked with windows services (or system services). Now I will start talking about processes. A process is something like a thread which starts execution in its only memory area (application domain). In general, every application starts in the form of a process. Almost all processes can be viewed using the task manager. Some processes may be system processes which run in the background (without having a user interface). Every process gets identified by a process id internally.  We can get the full list of processes by using WMI class “Win32_process”. You can refer to part three to get an entire example of listing processes.

    Now, the question is, can we start our own process (or even an application) using WMI? I hope anyone who works with .NET would definitely know how to do it using the native .NET framework. But now, I would like to do the same thing using WMI. The following program fragment demonstrates this:

    ' Get the object on which the method will be invoked

           DimprocessClassAsNewManagementClass("Win32_Process")

           ' Get an input parameters object for this method

           DiminParamsAsManagementBaseObject = processClass.GetMethodParameters("Create")

           ' Fill in input parameter values

            inParams("CommandLine") = "calc.exe"

           ' Execute the method

           DimoutParamsAsManagementBaseObject = processClass.InvokeMethod("Create", inParams,Nothing)

           DimobjAsObject= outParams("ReturnValue")

           Ifobj.ToString <> "0"Then

                MessageBox.Show("Could not Start, Returned code:" & obj.ToString)

           EndIf

    A brief explanation of above program is included below.

    We create a new process by using WMI class “Win32_Process”. There exists a method “create” within the class “Win32_Process”. That method creates a process at the OS through WMI and not our application. We provide parameters to that object using "inParams" (such as which application to execute as part of the process).

    We execute the “create” method using the “InvokeMethod” of the “ManagementClass” object (currently the object points to a new process). The result of the “InvokeMethod” is returned into “outParams”. If the result is zero, it has successfully managed to invoke an external process. A non-zero result is a failure which would be shown through a message box. A detailed explanation of every return code is provided in the WMI SDK documentation.

    You can understand the above program very easily, if you go through my previous article (part four).  All information about calling a WMI method (including the “InvokeMethod” member) was discussed in detail in that article. 

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


     

    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...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




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