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.

Tagged with:
 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>