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.
Top Posts
- LINQ To SQL Tutorial
- LINQ To SQL Join On Multiple Conditions
- Code Sample: Programmatically Download File Using C#
- Windows 7 Control Panel In Classic Mode
- More Details Emerge On Microsoft Master Certification
- Use SqlConnection With LINQ To SQL
- Free Icons And Images With Visual Studio 2008
- Capture XML In WCF Service
- Dynamic Sort With LINQ
- StyleCop Tutorial
Tags
.Net 2010 ADO.NET ASP.NET Azure Blogging Books Browsers C# Certification Cloud Computing Code Snippets Community Data Services Eclipse Entity Framework Google IDE Java LINQ Mac Microsoft Museum NetBeans Office Oracle REST SharePoint Silverlight SQL Server T-SQL Tips Tools Training Visual Studio Visual Studio 2010 WCF Web Windows Windows 7 Windows Forms Windows Live WMI WPF XAML

