This article was previously published under Q320789
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 ServiceName 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.
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.
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.
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// #define SERVICE_STOPPED 0x00000001#define SERVICE_START_PENDING 0x00000002#define SERVICE_STOP_PENDING 0x00000003#define SERVICE_RUNNING 0x00000004#define SERVICE_CONTINUE_PENDING 0x00000005#define SERVICE_PAUSE_PENDING 0x00000006#define SERVICE_PAUSED 0x00000007
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.
These same symptoms may occur if any other application interrogates the service to determine its current status.
For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:
257509 Hardware Inventory May Cause Third-Party Win32 Services to Stop
257689 Error Message When You Use "Net" Command with Microsoft Exchange Connector for POP3 Mailboxes