Microsoft KB Archive/320789

= Service Control Manager reports Event ID 7016 =

Article ID: 320789

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Win32 Application Programming Interface, when used with:  Microsoft Windows XP Professional

 Microsoft Windows 2000 Standard Edition

 Microsoft Windows NT 4.0 

-

<div class="notice_section">

This article was previously published under Q320789

<div class="symptoms_section">

SYMPTOMS
If a service is not written correctly, the Service Control Manager (SCM) may log the following error in the system event log when you use the net start command to start the service:

Event ID: 7016

Source: Service Control Manager

Type: Error

Category: None

Description: The  service has reported an invalid current state 0.

However, this error message may not be generated if the Services tool in Control Panel (on a Windows NT 4.0-based system) or the Microsoft Management Console (MMC) Services snap-in (on a Windows 2000 or Windows XP-based system) is used to start the service.

<div class="cause_section">

CAUSE
After you use the net start command to start the service, Net.exe interrogates the service by calling the ControlService function with a SERVICE_CONTROL_INTERROGATE control code until the service reports a status of SERVICE_RUNNING or SERVICE_STOPPED. If the service control handler of the corresponding service calls SetServiceStatus with an invalid value for dwCurrentState, the SCM reports the aforementioned error in the system event log.

<div class="resolution_section">

RESOLUTION
To resolve this issue, the service must be fixed (rewritten correctly) so that it reports a valid status when it receives a SERVICE_CONTROL_INTERROGATE (or any other) control code from the SCM.

<div class="moreinformation_section">

MORE INFORMATION
If the Services tool in Control Panel (on a Windows NT 4.0-based system) or the MMC Services snap-in (on a Windows 2000 or Windows XP-based system) is used to start the service, the QueryServiceStatus function is used to track the progress of the service until it reports a status of SERVICE_RUNNING or SERVICE_STOPPED. QueryServiceStatus returns the most recent status information reported to the SCM. The SCM does not call the service control handler in this scenario.

However, Net.exe determines the current service status by interrogating the service periodically by using the ControlService function with a SERVICE_CONTROL_INTERROGATE control code. This control code is delivered to the control handler for the service. In response, the service posts its current status information back to the SCM by calling SetServiceStatus. The service control handler code should report one of the following valid states, which are defined in the winsvc.h header file: // // Service State -- for CurrentState // If a service state not listed in the preceding code sample is reported by the service, the SCM will log an error with Event ID 7016 in the system event log, together with the name of the service.
 * 1) define SERVICE_STOPPED                       0x00000001
 * 2) define SERVICE_START_PENDING                 0x00000002
 * 3) define SERVICE_STOP_PENDING                  0x00000003
 * 4) define SERVICE_RUNNING                       0x00000004
 * 5) define SERVICE_CONTINUE_PENDING              0x00000005
 * 6) define SERVICE_PAUSE_PENDING                 0x00000006
 * 7) define SERVICE_PAUSED                        0x00000007

These same symptoms may occur if any other application interrogates the service to determine its current status.

<div class="references_section">