Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Starting Services

Visual Studio .NET 2003

After a service is installed, it must be started. Starting calls the OnStart method on the service class. Usually, the OnStart method defines the useful work the service will perform. After a service starts, it remains active until it is manually paused or stopped.

Services can be set up to start automatically or manually. A service that starts automatically will be started when the computer on which it is installed is rebooted or first turned on. A user must start a service that starts manually.

Note   By default, services created with Visual Studio .NET are set to start manually.

There are several ways you can manually start a service — from Server Explorer, from the Services Control Manager, or from code using a component called the ServiceController. For an overview of ServiceController components, see Monitoring Windows Services.

Specifying Manual or Automatic Starting for a Service

You set the StartType property on the ServiceInstaller class to determine whether a service should be started manually or automatically.

To specify how a service should start

  1. After creating your service, add the necessary installers for it. For more information, see Adding Installers to your Service Application.
  2. In the designer, click the service installer for the service you are working with.
  3. In the Properties window, set the StartType property to one of the following:
    To have your service installSet this value
    When the computer is restartedAutomatic
    When an explicit user action starts the serviceManual
    Tip   To prevent your service from being started at all, you can set the StartType property to Disabled. You might do this if you are going to reboot a server several times and want to save time by preventing the services that would normally start from starting up.
    Note   These and other properties can be changed after your service is installed.

Starting the Service Manually

There are several ways you can start a service that has its StartType process set to Manual — from Server Explorer, from the Windows Services Control Manager, or from code. It is important to note that not all of these methods actually start the service in the context of the Services Control Manager; the Server Explorer and programmatic methods of starting the service actually manipulate the controller.

To manually start a service from Server Explorer

  1. In Server Explorer, add the server you want if it is not already listed. For more information, see Accessing and Initializing Server Explorer.
    Note   The Servers node of the Server Explorer is not available in the Standard Edition of Visual Basic and Visual C# .NET. For more information, see Visual Basic Standard Edition Features or Visual C# Standard Edition Features.
  2. Expand the Services node, and then locate the service you want to start.
  3. Right-click the name of the service, and click Start.

To manually start a service from Services Control Manager

  1. Open the Services Control Manager by doing one of the following:
    • In Windows 2000 Professional, right-click My Computer on the desktop, and then click Manage. In the dialog box that appears, expand the Services and Applications node.

      - or -

    • In Windows 2000 Server, click Start, point to Programs, click Administrative Tools, and then click Services.
      Note   In Windows NT version 4.0, you can open this dialog box from Control Panel.

    You should now see your service listed in the Services section of the window.

  2. Select your service in the list, right-click it, and then click Start.

To manually start a service from code

  1. Create an instance of the ServiceController class, and configure it to interact with the service you want to administer. For more information, see Creating ServiceController Component Instances.
  2. Call the Start method to start the service.

See Also

Introduction to Windows Service Applications | Creating Windows Services | Adding Installers to your Service Application | Accessing and Initializing Server Explorer | Performing Administrative Tasks on Services

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft