Managing Windows Services with Visual Studio 2005 - Programmatic access using the NET framework
(Page 4 of 5 )
The System.ServiceProcess namespace has classes that help you to work with Windows Services. These long running programs without a user interface can be programmatically implemented, installed, and managed by using these classes. In this tutorial a couple of properties and methods of the ServiceController class will be described. The next picture shows the details of the ServiceController in the Object Browser.

Finding all services running on the machine
The object browser will show you that the getServices() method would find all the services on your machine. Obviously this will create an array consisting of all the services. Services are known by their name. The following code will therefore show all the services. You may use the WriteLine() method of Debug to write to an output window, or use a list box and populate it with the names of services as shown in the next listing. In this listing "Hodentek" is the machine name.
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
Dim mysvcCntrl As ServiceController
Dim myWinSvcs As Array
myWinSvcs = ServiceController.GetServices("Hodentek")
For Each mysvcCntrl In myWinSvcs
Debug.WriteLine(mysvcCntrl.ServiceName)
ListBox1.Items.Add(mysvcCntrl.ServiceName)
Next
End Sub
On similar lines you can access other properties also. The next picture shows the list box populated by the services on the "Hodentek" computer.

Next: Starting, Pausing and Stopping a Service >>
More ASP.NET Articles
More By Jayaram Krishnaswamy