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 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

SC_HANDLE OpenSCManager( _In_opt_ LPCTSTR lpMachineName, _In_opt_ LPCTSTR lpDatabaseName, _In_ DWORD dwDesiredAccess );

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

BOOL CloseServiceHandle( _In_ SC_HANDLE grabación );

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

BOOL StartService( _In_ SC_HANDLE hService, _In_opt_ DWORD dwNumServiceArgs, _In_opt_ LPCTSTR *lpServiceArgVectors );

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 the lpServiceArgVectors array.
  • 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

BOOL ControlService( _In_ SC_HANDLE hService, _In_ DWORD dwControl, _Out_ LPSERVICE_STATUS lpServiceStatus );

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 a SERVICE_STATUS structure 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

BOOL QueryServiceStatus( _In_ SC_HANDLE hService, _Out_ LPSERVICE_STATUS lpServiceStatus );

Description

Retrieves status information for a specified service.

Parameters

  • hService: A handle to the service.
  • lpServiceStatus: A pointer to a SERVICE_STATUS structure 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