Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 2 - WMI Programming with Visual Basic.NET: Com...
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: Combining with Windows Services
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 9
    2005-08-08

    Table of Contents:
  • WMI Programming with Visual Basic.NET: Combining with Windows Services
  • Designing and preparing the essentials
  • Implementing the logic
  • Adding the installers and setup
  • Installing, executing and testing the windows service

  • 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: Combining with Windows Services - Designing and preparing the essentials


    (Page 2 of 5 )

    The application that we are going to design now will actually log all the events (state) of any system service in a database table. We shall subscribe to WMI events through a Windows Service, which runs as a daemon, without the user's knowledge! In this section, we will create the table structure in the database and make ready an empty Windows Service to work with WMI.

    I just wanted to log the event information into a very simple database table which contains only two columns. So, we need to design a table in the SQL Server Database based on the following structure:

    ·        ServiceName     -           varchar(50)

    ·        Status               -           varchar(50)

    And we need to store the above structure in a table named “ServiceHistory”.

    Let’s start creating the Windows Service:

    ·        Open Visual Studio.NET 2003EnterpriseArchitect

    ·        Go to File -> New -> Project

    ·        In the “New Project” dialog box, select Project Type as “Visual Basic Projects” and Templates as “Windows Service”.

    ·        Provide the name of the project as “WMIService” and save it at any location you want.

    ·        You should be able to see “Service1.vb” created in the Solution Explorer.

    ·        Double click on “Service1.vb” to open it. 

    ·        Right click on the design area and go to properties. Modify properties as follows:

    o       Name:   WMISvc

    o       ServiceName:    WMISvc

    ·        Within the Solution Explorer, right click on “Service1.vb” and rename it “WMISvc.vb”.

    ·        Again, right click on the same and go to “View Code”.

    ·        Within the Code editor, unhide the region “Component Designer generated Code”.

    ·        Within the same document, find and replace all the instances where the word “Service1” appears with the word “WMISvc”.  You can use “Find and Replace” in the Edit menu.

    ·        Go to solution explorer, right click on References and choose “Add Reference”.

    ·        Choose “System.Management” within the .NET component list, press the “Select” button and finally click on OK. You should be able to see “System.Management” within the list of “References” in the solution explorer.

    ·        Again right click on “WMISvc.vb” in the Solution Explorer and go to “View Code” (unless you close it).

    ·        Go to menu Project -> WMIService Properties. Change the startup object to “WMISvc”.

    ·        Add the following lines at the top:

    ImportsSystem.Management

    ImportsSystem.Data.SqlClient

    Thus the first part is completed. Your VS.NET IDE should coincide with the following figure (Fig 1).

    More Visual Basic.NET Articles
    More By Jagadish Chaterjee


       · Hello guys, this is my article on working with WMI together with Windows Services....
       · Very well explained and detailed article. I have tried to build services and the...
       · Hi, can you try with some simple windows services and then go for the article!
     

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