Home / Programming / Blog article: Programmatically Retrieve Information About Windows Services Using ServiceController

| RSS

Programmatically Retrieve Information About Windows Services Using ServiceController

August 29th, 2008 | No Comments | Posted in Programming

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.

image

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());
}

image

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





Switch to our mobile site