OpenService

  SC_HANDLE OpenService(hSCManager, lpServiceName, dwDesiredAccess)    
  SC_HANDLE hSCManager;    
  LPTSTR lpServiceName;    
  DWORD dwDesiredAccess;    

The OpenService function opens a handle to an existing service.

Parameters

hSCManager

Handle obtained from a previous OpenSCManager call.

lpServiceName

Name of the service to open. The name must be NULL-terminated and has a maximum length of 256 characters. Forward-, back-slash, comma, and space are invalid service name characters.

dwDesiredAccess

The access types desired to access the service. These access types will be checked against the Discretionary Access Control list of the service object to determine whether the accesses are granted or denied.

Return Value

Returns a handle to the service. If return value is NULL, an error has occurred. Use GetLastError to determine the cause of the failure.

Errors Value Meaning
  ERROR_ACCESS_DENIED The caller is not allowed requested access to the service.
  ERROR_INVALID_HANDLE The specified handle is invalid.
  ERROR_INVALID_NAME The specified service name is invalid.
  ERROR_SERVICE_DOES_NOT_EXIST The specified service does not exist.

Comments

This call returns a handle to the newly opened service that should be used on future operations on the service. This handle can be closed by calling CloseServiceHandle.