Access Denied returned from CreateService
-
Hello All, When I am executing the following code
SC\_HANDLE schSCManager, schService; TCHAR szPath\[MAX\_PATH\]; GetModuleFileName(NULL, szPath, MAX\_PATH); schSCManager = OpenSCManager(NULL, NULL ,SC\_MANAGER\_ALL\_ACCESS); if ( schSCManager == NULL ) return false; schService = CreateService(schSCManager, USER\_SERVICE\_NAME, USER\_SERVICE\_NAME, SERVICE\_ALL\_ACCESS,SERVICE\_WIN32\_OWN\_PROCESS,SERVICE\_DEMAND\_START,SERVICE\_ERROR\_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);
The
CreateService()
is not returning a proper handle. When I used
GetLastError()
, its throwing a
ERROR_ACCESS_DENIED
error. Please help in solving this issue. Thanks in advance, Neelesh K J Jain.
-
Hello All, When I am executing the following code
SC\_HANDLE schSCManager, schService; TCHAR szPath\[MAX\_PATH\]; GetModuleFileName(NULL, szPath, MAX\_PATH); schSCManager = OpenSCManager(NULL, NULL ,SC\_MANAGER\_ALL\_ACCESS); if ( schSCManager == NULL ) return false; schService = CreateService(schSCManager, USER\_SERVICE\_NAME, USER\_SERVICE\_NAME, SERVICE\_ALL\_ACCESS,SERVICE\_WIN32\_OWN\_PROCESS,SERVICE\_DEMAND\_START,SERVICE\_ERROR\_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);
The
CreateService()
is not returning a proper handle. When I used
GetLastError()
, its throwing a
ERROR_ACCESS_DENIED
error. Please help in solving this issue. Thanks in advance, Neelesh K J Jain.
Are you executing this from an account with administrator access?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Are you executing this from an account with administrator access?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Yes, I have the administrator access. Thanks, Neelesh K J Jain.
-
Yes, I have the administrator access. Thanks, Neelesh K J Jain.
From the documentation[^]:
ERROR_ACCESS_DENIED
The handle to the SCM database does not have the SC_MANAGER_CREATE_SERVICE access right.
That implies that when you called OpenSCManager[^], you didn't ask for the
SC_MANAGER_CREATE_SERVICE
access right.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
From the documentation[^]:
ERROR_ACCESS_DENIED
The handle to the SCM database does not have the SC_MANAGER_CREATE_SERVICE access right.
That implies that when you called OpenSCManager[^], you didn't ask for the
SC_MANAGER_CREATE_SERVICE
access right.Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Hello Stuart, I tried even with
SC_MANAGER_CREATE_SERVICE
access right, then also I am getting same error code as access denied. -
Hello Stuart, I tried even with
SC_MANAGER_CREATE_SERVICE
access right, then also I am getting same error code as access denied.Neelesh K J Jain wrote:
even with
'even with'? That access right (implied by
SC_MANAGER_ALL_ACCESS
) is absolutely necessary for creating a service. And you did include it in your call toOpenSCManager
, right?Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hello All, When I am executing the following code
SC\_HANDLE schSCManager, schService; TCHAR szPath\[MAX\_PATH\]; GetModuleFileName(NULL, szPath, MAX\_PATH); schSCManager = OpenSCManager(NULL, NULL ,SC\_MANAGER\_ALL\_ACCESS); if ( schSCManager == NULL ) return false; schService = CreateService(schSCManager, USER\_SERVICE\_NAME, USER\_SERVICE\_NAME, SERVICE\_ALL\_ACCESS,SERVICE\_WIN32\_OWN\_PROCESS,SERVICE\_DEMAND\_START,SERVICE\_ERROR\_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);
The
CreateService()
is not returning a proper handle. When I used
GetLastError()
, its throwing a
ERROR_ACCESS_DENIED
error. Please help in solving this issue. Thanks in advance, Neelesh K J Jain.
GetModuleFileName(NULL, szPath, MAX_PATH);
CreateService(schSCManager, USER_SERVICE_NAME, USER_SERVICE_NAME, SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,SERVICE_DEMAND_START,SERVICE_ERROR_NORMAL, szPath, NULL, NULL, NULL, NULL, NULL);Try register service from another process
-
Neelesh K J Jain wrote:
even with
'even with'? That access right (implied by
SC_MANAGER_ALL_ACCESS
) is absolutely necessary for creating a service. And you did include it in your call toOpenSCManager
, right?Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
Yes, its implied.