Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 5 - WMI Programming with Visual Basic.NET: Man...
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: Managing the OS, continued
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 6
    2005-07-12

    Table of Contents:
  • WMI Programming with Visual Basic.NET: Managing the OS, continued
  • Retrieving the list of all services
  • How to know the state of a service
  • How to modify (manage) the state of a service
  • How the above program works
  • How will I know the proper description of the error?

  • 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: Managing the OS, continued - How the above program works


    (Page 5 of 6 )

    I already explained (in previous sections) up until the initialization of object ‘oItem’ with ‘ar(0)’. Proceeding further, we have a comment ‘Execute the method’. From that comment we are actually working with the service to change its state. Let me explain each statement separately.

           DimoutParamsAsManagementBaseObject = oitem.InvokeMethod("StopService",Nothing,Nothing)

    The above statement calls the method ‘StopService’ which exists in the ‘Win32_Service’ class of WMI (through ‘InvokeMethod’ routine) and returns the result into ‘outParams’ of type ‘ManagementBaseObject’.  The first ‘Nothing’ informs that there exist no input parameters to the method ‘StopService’. The second ‘Nothing’ states that no other options (like time to execute, etc.) are necessary to execute it and considers all the defaults.

    DimobjAsObject= outParams("ReturnValue")

    The above statement retrieves the ‘ReturnValue’ of the operation. A zero results in success. A non zero results in failure.

    Ifobj.ToString = "0"Then

                MessageBox.Show("Succesfully stopped..")

                lstServices_SelectedIndexChanged(Nothing,Nothing)

           Else

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

           EndIf

    This is very straightforward. It just displays the proper message based on the return value and finally updates the status using the following statement:

    lstServices_SelectedIndexChanged(Nothing,Nothing)

    The above statement gets the code fragment explained in the second section of this article, which actually fetches the latest status of the selected service.

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


     

    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 3 hosted by Hostway