Thursday, March 04, 2010

Status information for Windows services

When a windows service is running, it sends status notifications to the SCM process. SCM maintains this status information in the service record for each service. SCM tracks this information so that it does not mistakenly send control requests that do not conform to the recipient service's current state.

The service status information includes:

  • Service Type - A service can be a file system driver, device driver, or a Windows service, and can run its own process or share a process with other services. System Attendant is an example of a service that runs its own process. The SMTP service, however, is a service that shares a process with other services that are integrated with Internet Information Services (IIS).
  • Current state - The service state can be starting, running, paused, stopping, or not running.
  • Acceptable control codes - Theses are the control codes that the service is able to accept and process in its handler function, according to the current state.
  • Windows exit code - The service uses this code to report an error that occurs when it is starting or stopping. To return an error code specific to the service, the service must set this value to ERROR_SERVICE_SPECIFIC_ERROR to indicate that additional information can be found in the service exit code. The service sets this value to NO_ERROR when it is running or stopping properly.
  • Service exit code - The service uses this code to report an error when it is starting or stopping. The value is ignored unless the Windows exit code is set to ERROR_SERVICE_SPECIFIC_ERROR.
  • Wait hint - The service uses this code to report the estimated time, in milliseconds, required for a pending start, stop, pause, or continue operation.
  • Checkpoint - The service uses this value to periodically report its progress during a lengthy start, stop, pause, or continue operation. For example, the Services tool uses this value to track the progress of the service during start and stop operations.

Displaying Serivce Exit Codes -

To display the current status for all Windows services, you can use the command sc query

Simply run the command sc query service_name and look for the WIN32_EXIT_CODE field in the output of the command.

If this field is zero then the service started properly, and if the service didn't start properly then WIN32_EXIT_CODE will display a non-zero exit code specific to the service.

For example, when I run the command sc query vss to query the status of the Volume Shadow Copy service on a Windows XP machine, the WIN32_EXIT_CODE value returned is 1077 (0x435).

To find out what this exit code means, you can type net helpmsg 1077, and the result of doing this is "No attempts to start the service have been made since the last boot."

This likely indicates that the Startup Type for this service is Manual i.e. the service isn't set to start automatically upon reboot.

I hope this tip proves useful for you.

**Information in this post consolidated from several sources including MS TechNet, WindowsNetworking.com, etc.**