System Services API Reference
This section provides detailed information on the Windows API functions used to manage and interact with system services. System services are background processes that provide functionality to the operating system and applications.
Core Services Concepts
Understanding the fundamental concepts of Windows services is crucial before delving into the API. This includes:
- Service Control Manager (SCM): The central component responsible for managing services.
- Service Types: Different categories of services (e.g., kernel drivers, file system drivers, service drivers, interactive services).
- Service States: The lifecycle states of a service (e.g., STOPPED, START_PENDING, RUNNING, STOP_PENDING, CONTINUE_PENDING, PAUSE_PENDING, PAUSED).
- Service Dependencies: How services can rely on other services to function correctly.
Service Management
The Service Control Manager (SCM) provides a comprehensive set of functions for managing services from both an administrative and programmatic perspective. You can query service status, start, stop, pause, and configure services.
Key Service APIs
OpenSCManager
Description
Establishes a connection to the service control manager on the local computer or a specified remote computer.
Parameters
lpMachineName: The name of the remote computer.lpDatabaseName: The name of the service database to open.dwDesiredAccess: Access rights to the service control manager.
Return Value
If the function succeeds, the return value is a handle to the service control manager. If the function fails, the return value is NULL.
See Also
CloseServiceHandle
Description
Closes a handle to the service control manager or to a service.
Parameters
hSCObject: A handle to the service control manager or service to be closed.
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE.
See Also
StartService
Description
Starts a service that is either stopped or paused.
Parameters
hService: A handle to the service to be started.dwNumServiceArgs: The number of strings in thelpServiceArgVectorsarray.lpServiceArgVectors: An array of strings that are passed as arguments to the service's entry point.
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE.
See Also
ControlService
Description
Sends a control code to a service.
Parameters
hService: A handle to the service.dwControl: The control code to send to the service.lpServiceStatus: A pointer to aSERVICE_STATUSstructure that receives status information about the service.
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE.
See Also
QueryServiceStatus
Description
Retrieves status information for a specified service.
Parameters
hService: A handle to the service.lpServiceStatus: A pointer to aSERVICE_STATUSstructure that receives status information about the service.
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE.