How to: Start Windows Services in C#
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 are set to start manually. |
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
- After creating your service, add the necessary installers for it. For more information, see How to: Add Installers to Your Service Application.
- In the designer, click the service installer for the service you are working with.
- In the Properties window, set the StartType property to one of the following:
To have your service install Set this value When the computer is restarted
Automatic
When an explicit user action starts the service
Manual
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.
To manually start a service from Server Explorer
- In Server Explorer, add the server you want if it is not already listed. For more information, see How to: Access and Initialize Server Explorer/Database Explorer.
Note The Servers node of Server Explorer is not available in the Standard Edition of Visual Studio. For more information, .
- Expand the Services node, and then locate the service you want to start.
- Right-click the name of the service, and click Start.
To manually start a service from Services Control Manager
- Open the Services Control Manager by doing one of the following:
- In Windows XP and 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 Server 2003 and 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.
- In Windows XP and 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.
- Select your service in the list, right-click it, and then click Start.
0 comments:
Post a Comment