18.0.8 Service Object

The Service object represents an installed service. An instance of this object type is created when the service is installed. It is deleted when the service is uninstalled.

The Service object resides within the SCManager object.

The Service object controls accesses to the Service Control Manager in the following manner:

All users have GENERIC_READ access.

Local users have GENERIC_READ and SERVICE_START access.

Administrators have GENERIC_ALL access.

18.0.8.1 Service Access Types

The Service object has the following access types:

Value Meaning

SERVICE_QUERY_CONFIG This access type is needed to query the service configuration.
SERVICE_CHANGE_CONFIG This access type is needed to change the service configuration.
SERVICE_START This access type is needed to start a service.
SERVICE_STOP This access type is needed to stop a service.
SERVICE_PAUSE_CONTINUE This access type is needed to pause or continue a service.
SERVICE_INTERROGATE This access type is needed to ask a service to report its status immediately.
SERVICE_QUERY_STATUS This access type is needed to query the service status.
SERVICE_ENUMERATE_DEPENDENTS This access type is needed to enumerate all the services that are dependent a service.

Generic Access Masks

The Service object publishes the following mappings from generic access types to non-generic access types:

Generic Access Non-Generic Access

GENERIC_READ STANDARD_RIGHTS_READ | SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS
GENERIC_WRITE STANDARD_RIGHTS_WRITE | SERVICE_CHANGE_CONFIG
GENERIC_EXECUTE STANDARD_RIGHTS_EXECUTE | SERVICE_START | SERVICE_STOP | SERVICE_PAUSE_CONTINUE | SERVICE_INTERROGATE

Standard Access Types

This object type does not support the (optional) SYNCHRONIZE standard access type. All required access types are supported.

The mask of all supported access types for this object type is:

SERVICE_ALL_ACCESS

STANDARD_RIGHTS_REQUIRED |
SERVICE_QUERY_CONFIG |
SERVICE_CHANGE_CONFIG |
SERVICE_ENUMERATE_DEPENDENTS |
SERVICE_QUERY_STATUS |
SERVICE_START |
SERVICE_STOP |
SERVICE_PAUSE_CONTINUE |
SERVICE_INTERROGATE

Privileges Defined Or Used

This object type does not define any privileges.

A Win32 program must support the service control interface in order to qualify as a Win32 service. The functions defined in the following sections specify how a service program sets up the communication channel to the Service Control Manager, and updates the Service Control Manager of its current state.

The Service Control Manager sends a control to a service based on the control requested and the current state of the service:

Current State Stop Other Controls

STOPPED (b) (b)
STOP_PENDING (b) (b)
START_PENDING (a) (b)
RUNNING (a) (a)
CONTINUE_PENDING (a) (a)
PAUSE_PENDING (a) (a)
PAUSED (a) (a)

(a) Send control to the service if the service accepts this control. If service does not accept this control ERROR_INVALID_SERVICE_CONTROL is returned.

(b) Do not send the control to the service. Instead return ERROR_SERVICE_CANNOT_ACCEPT_CTRL.

18.0.8.2 Service Program Data Types

The StartServiceCtrlDispatcher function takes an array of SERVICE_TABLE_ENTRY structures as input. Each structure entry specifies a service that runs within the same Win32 process.