|
Programmatically Retrieve Information About Windows Services Using ServiceController
ServiceControl can be used to get information about a Windows Service on a machine. In this post I will show you how to retrieve information about a service using ServiceControl.
To begin with lets examine the properties for ServiceControl. Through the designer we can set the ServiceName property. This can be set to the name of a service for which we wish to get more information.

Retrieving details about a service is simply calling the appropriate properties.
private void buttonServiceInfo_Click(object sender, EventArgs e)
{
listBox1.Items.Add("Status: " + serviceController.Status.ToString());
listBox1.Items.Add("ServiceType: " + serviceController.ServiceType.ToString());
listBox1.Items.Add("ServiceHandle: " + serviceController.ServiceHandle.ToString());
listBox1.Items.Add("CanStop: " + serviceController.CanStop.ToString());
listBox1.Items.Add("DisplayName: " + serviceController.DisplayName.ToString());
}

Other than properties ServiceControl can also be used to start or stop a service. ServiceControl IMO is a little hidden gem which at times can be very useful.
Leave a Reply
3161 views, 2 so far
today |
Leave a Reply
Get Updates By Email
Popular Post
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Free Icons And Images With Visual Studio 2008
- Windows 7 Control Panel In Classic Mode
- Dynamic Sort With LINQ
- Use SqlConnection With LINQ To SQL
- StyleCop Tutorial
- Write To Vista Event Log Using C#
- More Details Emerge On Microsoft Master Certification
Tag Cloud
Code Snippets
- Get Current Windows User In C#
- Get Width And Height Of Image In C#
- Get Windows Registry Size With WMI And C#
- Reverse Array Elements Using C#
- Convert Hexadecimal To Number In C#
- Get Free Disk Space Using T-SQL
- SQL Server 2008 – Get All Indexes In A Database
- Get Name Of Current Executing Assembly In C#
- Get CD Or DVD Drive Information Using WMI And C#
- Get Last Row From Table Using LINQ To SQL

