Service Manager Sample

To get samples and instructions for installing them, see the following:

  • Click Samples on the Visual Studio Help menu.

    For more information, see Locating Sample Files.

  • The most recent versions and the complete list of samples are available on the Visual Studio 2008 Samples Web site.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied to a folder under \Program Files\Visual Studio 9\Samples\. For Visual Studio Express Editions, all samples are located on the Internet.

To run this sample

  • Press F5.

Demonstrates

Windows Services are long-running programs that perform their tasks without user interaction. This sample uses the ServiceController class from the System.ServiceProcess namespace. This class enables you retrieve a list of the running services through a shared method, GetServices. By using the ServiceController class, you can start, stop, pause, or resume a service.

Using the user interface presented you can start, stop, pause, and resume a service. The application checks the current state of the service to see what buttons should be enabled. The Relist All Services command on the Actions menu calls the GetServices method to fill the ListView control with the processes. The Refresh command on the Actions menu updates the status of each process already listed in the ListView control.