Opens an existing service.

OpenService(cServiceName [, nAccess [, cServer [, cDatabase]]])

Parameters

cServiceName | nServiceHandle

Either the name of the service or a numeric handle returned from the OpenService function.

nAccess (optional, additiive)

default = SERVICE_ALL_ACCESS

The desired access to the service.

One or a combination of the following values.
Access rightDescription
SERVICE_ALL_ACCESS Includes STANDARD_RIGHTS_REQUIRED in addition to all access rights in this table.
SERVICE_CHANGE_CONFIG Required to call the ChangeServiceConfig or ChangeServiceConfig2 function to change the service configuration. Because this grants the caller the right to change the executable file that the system runs, it should be granted only to administrators.
SERVICE_ENUMERATE_DEPENDENTSRequired to call the ADependentServices function to enumerate all the services dependent on the service.
SERVICE_INTERROGATE Required to call the ControlService function to ask the service to report its status immediately.
SERVICE_PAUSE_CONTINUERequired to call the PauseService and ContinueService functions.
SERVICE_QUERY_CONFIGRequired to call the AServiceConfig function to query the service configuration.
SERVICE_QUERY_STATUSRequired to call the AServiceStatus function to ask the service control manager about the status of the service.
SERVICE_STARTRequired to call the StartService function to start the service.
SERVICE_STOPRequired to call the ControlService function to stop the service.
SERVICE_USER_DEFINED_CONTROLRequired to call the ControlService function to specify a user-defined control code.
cServer (optional)

The server name on which the service is running.
See MSDN help for OpenSCManager.

cDatabase (optional)

The database under which the service is registered.
See MSDN help for OpenSCManager.

Return Value

A handle for the windows service.

See Also

Reference

ADependentServices
AServiceConfig
AServices
AServiceStatus
CloseServiceHandle
ContinueService
ControlService
CreateService
PauseService
StartService
StopService
WaitForServiceStatus

Used WinApi functions

OpenService
OpenSCManager