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

Next: Implementing the logic >>
More Visual Basic.NET Articles
More By Jagadish Chaterjee