StartService
From Ggl's wiki
Contents |
Description
Starts a service.
Prototype
BOOL WINAPI StartService( SC_HANDLE hService, DWORD dwNumServiceArgs, LPCTSTR* lpServiceArgVectors );
Parameters
- hService
- [in] Handle to the service. This handle is returned by the OpenService or CreateService function, and it must have the SERVICE_START access right. For more information, see Service Security and Access Rights.
- dwNumServiceArgs
- [in] Number of strings in the lpServiceArgVectors array. If lpServiceArgVectors is NULL, this parameter can be zero.
- lpServiceArgVectors
- [in] Pointer to an array of pointers to null-terminated strings to be passed to a service as arguments. Driver services do not receive these arguments. If no arguments are passed to the service, this parameter can be NULL. The service accesses these arguments through its ServiceMain function. The first argument (argv[0]) is the name of the service by default, followed by the arguments, if any, in the lpServiceArgVectors array.
Return Value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
The following error codes can be set by the service control manager. Others can be set by the registry functions that are called by the service control manager.
- ERROR_ACCESS_DENIED
- The handle does not have the SERVICE_START access right.
- ERROR_INVALID_HANDLE
- The handle is invalid.
- ERROR_PATH_NOT_FOUND
- The service binary file could not be found.
- ERROR_SERVICE_ALREADY_RUNNING
- An instance of the service is already running.
- ERROR_SERVICE_DATABASE_LOCKED
- The database is locked.
- ERROR_SERVICE_DEPENDENCY_DELETED
- The service depends on a service that does not exist or has been marked for deletion.
- ERROR_SERVICE_DEPENDENCY_FAIL
- The service depends on another service that has failed to start.
- ERROR_SERVICE_DISABLED
- The service has been disabled.
- ERROR_SERVICE_LOGON_FAILED
- The service did not start due to a logon failure. This error occurs if the service is configured to run under an account that does not have the "Log on as a service" right.
- ERROR_SERVICE_MARKED_FOR_DELETE
- The service has been marked for deletion.
- ERROR_SERVICE_NO_THREAD
- A thread could not be created for the service.
- ERROR_SERVICE_REQUEST_TIMEOUT
- The process for the service was started, but it did not call StartServiceCtrlDispatcher, or the thread that called StartServiceCtrlDispatcher may be blocked in a control handler function.

