2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS system libraries
4 * FILE: lib/advapi32/service/scm.c
5 * PURPOSE: Service control manager functions
6 * PROGRAMMER: Emanuele Aliberti
10 /* INCLUDES ******************************************************************/
13 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
18 const struct ustring
*in
,
19 const struct ustring
*key
,
25 IN PVOID ContextHandle
,
26 OUT LPBYTE SessionKey
);
28 /* FUNCTIONS *****************************************************************/
31 SVCCTL_HANDLEA_bind(SVCCTL_HANDLEA szMachineName
)
33 handle_t hBinding
= NULL
;
34 RPC_CSTR pszStringBinding
;
37 TRACE("SVCCTL_HANDLEA_bind(%s)\n",
38 debugstr_a(szMachineName
));
40 status
= RpcStringBindingComposeA(NULL
,
42 (RPC_CSTR
)szMachineName
,
43 (RPC_CSTR
)"\\pipe\\ntsvcs",
46 if (status
!= RPC_S_OK
)
48 ERR("RpcStringBindingCompose returned 0x%x\n", status
);
52 /* Set the binding handle that will be used to bind to the server. */
53 status
= RpcBindingFromStringBindingA(pszStringBinding
,
55 if (status
!= RPC_S_OK
)
57 ERR("RpcBindingFromStringBinding returned 0x%x\n", status
);
60 status
= RpcStringFreeA(&pszStringBinding
);
61 if (status
!= RPC_S_OK
)
63 ERR("RpcStringFree returned 0x%x\n", status
);
71 SVCCTL_HANDLEA_unbind(SVCCTL_HANDLEA szMachineName
,
76 TRACE("SVCCTL_HANDLEA_unbind(%s %p)\n",
77 debugstr_a(szMachineName
), hBinding
);
79 status
= RpcBindingFree(&hBinding
);
80 if (status
!= RPC_S_OK
)
82 ERR("RpcBindingFree returned 0x%x\n", status
);
88 SVCCTL_HANDLEW_bind(SVCCTL_HANDLEW szMachineName
)
90 handle_t hBinding
= NULL
;
91 RPC_WSTR pszStringBinding
;
94 TRACE("SVCCTL_HANDLEW_bind(%s)\n",
95 debugstr_w(szMachineName
));
97 status
= RpcStringBindingComposeW(NULL
,
103 if (status
!= RPC_S_OK
)
105 ERR("RpcStringBindingCompose returned 0x%x\n", status
);
109 /* Set the binding handle that will be used to bind to the server. */
110 status
= RpcBindingFromStringBindingW(pszStringBinding
,
112 if (status
!= RPC_S_OK
)
114 ERR("RpcBindingFromStringBinding returned 0x%x\n", status
);
117 status
= RpcStringFreeW(&pszStringBinding
);
118 if (status
!= RPC_S_OK
)
120 ERR("RpcStringFree returned 0x%x\n", status
);
128 SVCCTL_HANDLEW_unbind(SVCCTL_HANDLEW szMachineName
,
133 TRACE("SVCCTL_HANDLEW_unbind(%s %p)\n",
134 debugstr_w(szMachineName
), hBinding
);
136 status
= RpcBindingFree(&hBinding
);
137 if (status
!= RPC_S_OK
)
139 ERR("RpcBindingFree returned 0x%x\n", status
);
145 ScmRpcStatusToWinError(RPC_STATUS Status
)
147 TRACE("ScmRpcStatusToWinError(%lx)\n",
152 case STATUS_ACCESS_VIOLATION
:
153 case RPC_S_INVALID_BINDING
:
154 case RPC_X_SS_IN_NULL_CONTEXT
:
155 return ERROR_INVALID_HANDLE
;
157 case RPC_X_ENUM_VALUE_OUT_OF_RANGE
:
158 case RPC_X_BYTE_COUNT_TOO_SMALL
:
159 return ERROR_INVALID_PARAMETER
;
161 case RPC_X_NULL_REF_POINTER
:
162 return ERROR_INVALID_ADDRESS
;
165 return (DWORD
)Status
;
173 _In_ PCWSTR pClearTextPassword
,
174 _Out_ PBYTE
*pEncryptedPassword
,
175 _Out_ PDWORD pEncryptedPasswordSize
)
177 struct ustring inData
, keyData
, outData
;
182 /* Get the session key */
183 Status
= SystemFunction028(NULL
,
185 if (!NT_SUCCESS(Status
))
187 ERR("SystemFunction028 failed (Status 0x%08lx)\n", Status
);
188 return RtlNtStatusToDosError(Status
);
191 inData
.Length
= (wcslen(pClearTextPassword
) + 1) * sizeof(WCHAR
);
192 inData
.MaximumLength
= inData
.Length
;
193 inData
.Buffer
= (unsigned char *)pClearTextPassword
;
195 keyData
.Length
= sizeof(SessionKey
);
196 keyData
.MaximumLength
= keyData
.Length
;
197 keyData
.Buffer
= SessionKey
;
200 outData
.MaximumLength
= 0;
201 outData
.Buffer
= NULL
;
203 /* Get the required buffer size */
204 Status
= SystemFunction004(&inData
,
207 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
209 ERR("SystemFunction004 failed (Status 0x%08lx)\n", Status
);
210 return RtlNtStatusToDosError(Status
);
213 /* Allocate a buffer for the encrypted password */
214 pBuffer
= HeapAlloc(GetProcessHeap(), 0, outData
.Length
);
216 return ERROR_OUTOFMEMORY
;
218 outData
.MaximumLength
= outData
.Length
;
219 outData
.Buffer
= pBuffer
;
221 /* Encrypt the password */
222 Status
= SystemFunction004(&inData
,
225 if (!NT_SUCCESS(Status
))
227 ERR("SystemFunction004 failed (Status 0x%08lx)\n", Status
);
228 HeapFree(GetProcessHeap(), 0, pBuffer
);
229 return RtlNtStatusToDosError(Status
);
232 *pEncryptedPassword
= outData
.Buffer
;
233 *pEncryptedPasswordSize
= outData
.Length
;
235 return ERROR_SUCCESS
;
239 /**********************************************************************
240 * ChangeServiceConfig2A
245 ChangeServiceConfig2A(SC_HANDLE hService
,
249 SC_RPC_CONFIG_INFOA Info
;
252 TRACE("ChangeServiceConfig2A(%p %lu %p)\n",
253 hService
, dwInfoLevel
, lpInfo
);
255 if (lpInfo
== NULL
) return TRUE
;
257 /* Fill relevant field of the Info structure */
258 Info
.dwInfoLevel
= dwInfoLevel
;
261 case SERVICE_CONFIG_DESCRIPTION
:
265 case SERVICE_CONFIG_FAILURE_ACTIONS
:
270 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
271 SetLastError(ERROR_INVALID_PARAMETER
);
277 dwError
= RChangeServiceConfig2A((SC_RPC_HANDLE
)hService
,
280 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
282 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
286 if (dwError
!= ERROR_SUCCESS
)
288 TRACE("RChangeServiceConfig2A() failed (Error %lu)\n", dwError
);
289 SetLastError(dwError
);
297 /**********************************************************************
298 * ChangeServiceConfig2W
303 ChangeServiceConfig2W(SC_HANDLE hService
,
307 SC_RPC_CONFIG_INFOW Info
;
310 TRACE("ChangeServiceConfig2W(%p %lu %p)\n",
311 hService
, dwInfoLevel
, lpInfo
);
313 if (lpInfo
== NULL
) return TRUE
;
315 /* Fill relevant field of the Info structure */
316 Info
.dwInfoLevel
= dwInfoLevel
;
319 case SERVICE_CONFIG_DESCRIPTION
:
323 case SERVICE_CONFIG_FAILURE_ACTIONS
:
328 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
329 SetLastError(ERROR_INVALID_PARAMETER
);
335 dwError
= RChangeServiceConfig2W((SC_RPC_HANDLE
)hService
,
338 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
340 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
344 if (dwError
!= ERROR_SUCCESS
)
346 TRACE("RChangeServiceConfig2W() failed (Error %lu)\n", dwError
);
347 SetLastError(dwError
);
355 /**********************************************************************
356 * ChangeServiceConfigA
361 ChangeServiceConfigA(SC_HANDLE hService
,
364 DWORD dwErrorControl
,
365 LPCSTR lpBinaryPathName
,
366 LPCSTR lpLoadOrderGroup
,
368 LPCSTR lpDependencies
,
369 LPCSTR lpServiceStartName
,
371 LPCSTR lpDisplayName
)
374 DWORD dwDependenciesLength
= 0;
377 DWORD dwPasswordSize
= 0;
378 LPWSTR lpPasswordW
= NULL
;
379 LPBYTE lpEncryptedPassword
= NULL
;
381 TRACE("ChangeServiceConfigA(%p %lu %lu %lu %s %s %p %s %s %s %s)\n",
382 hService
, dwServiceType
, dwStartType
, dwErrorControl
, debugstr_a(lpBinaryPathName
),
383 debugstr_a(lpLoadOrderGroup
), lpdwTagId
, debugstr_a(lpDependencies
),
384 debugstr_a(lpServiceStartName
), debugstr_a(lpPassword
), debugstr_a(lpDisplayName
));
386 /* Calculate the Dependencies length*/
387 if (lpDependencies
!= NULL
)
389 lpStr
= lpDependencies
;
392 cchLength
= strlen(lpStr
) + 1;
393 dwDependenciesLength
+= (DWORD
)cchLength
;
394 lpStr
= lpStr
+ cchLength
;
396 dwDependenciesLength
++;
399 if (lpPassword
!= NULL
)
401 /* Convert the password to unicode */
402 lpPasswordW
= HeapAlloc(GetProcessHeap(),
404 (strlen(lpPassword
) + 1) * sizeof(WCHAR
));
405 if (lpPasswordW
== NULL
)
407 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
411 MultiByteToWideChar(CP_ACP
,
416 (int)(strlen(lpPassword
) + 1));
418 /* Encrypt the unicode password */
419 dwError
= ScmEncryptPassword(lpPasswordW
,
420 &lpEncryptedPassword
,
422 if (dwError
!= ERROR_SUCCESS
)
428 dwError
= RChangeServiceConfigA((SC_RPC_HANDLE
)hService
,
432 (LPSTR
)lpBinaryPathName
,
433 (LPSTR
)lpLoadOrderGroup
,
435 (LPBYTE
)lpDependencies
,
436 dwDependenciesLength
,
437 (LPSTR
)lpServiceStartName
,
440 (LPSTR
)lpDisplayName
);
442 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
444 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
449 if (lpPasswordW
!= NULL
)
451 /* Wipe and release the password buffers */
452 SecureZeroMemory(lpPasswordW
, (wcslen(lpPasswordW
) + 1) * sizeof(WCHAR
));
453 HeapFree(GetProcessHeap(), 0, lpPasswordW
);
455 if (lpEncryptedPassword
!= NULL
)
457 SecureZeroMemory(lpEncryptedPassword
, dwPasswordSize
);
458 HeapFree(GetProcessHeap(), 0, lpEncryptedPassword
);
462 if (dwError
!= ERROR_SUCCESS
)
464 TRACE("RChangeServiceConfigA() failed (Error %lu)\n", dwError
);
465 SetLastError(dwError
);
473 /**********************************************************************
474 * ChangeServiceConfigW
479 ChangeServiceConfigW(SC_HANDLE hService
,
482 DWORD dwErrorControl
,
483 LPCWSTR lpBinaryPathName
,
484 LPCWSTR lpLoadOrderGroup
,
486 LPCWSTR lpDependencies
,
487 LPCWSTR lpServiceStartName
,
489 LPCWSTR lpDisplayName
)
492 DWORD dwDependenciesLength
= 0;
495 DWORD dwPasswordSize
= 0;
496 LPBYTE lpEncryptedPassword
= NULL
;
498 TRACE("ChangeServiceConfigW(%p %lu %lu %lu %s %s %p %s %s %s %s)\n",
499 hService
, dwServiceType
, dwStartType
, dwErrorControl
, debugstr_w(lpBinaryPathName
),
500 debugstr_w(lpLoadOrderGroup
), lpdwTagId
, debugstr_w(lpDependencies
),
501 debugstr_w(lpServiceStartName
), debugstr_w(lpPassword
), debugstr_w(lpDisplayName
));
503 /* Calculate the Dependencies length*/
504 if (lpDependencies
!= NULL
)
506 lpStr
= lpDependencies
;
509 cchLength
= wcslen(lpStr
) + 1;
510 dwDependenciesLength
+= (DWORD
)cchLength
;
511 lpStr
= lpStr
+ cchLength
;
513 dwDependenciesLength
++;
514 dwDependenciesLength
*= sizeof(WCHAR
);
517 if (lpPassword
!= NULL
)
519 dwError
= ScmEncryptPassword(lpPassword
,
520 &lpEncryptedPassword
,
522 if (dwError
!= ERROR_SUCCESS
)
524 ERR("ScmEncryptPassword failed (Error %lu)\n", dwError
);
531 dwError
= RChangeServiceConfigW((SC_RPC_HANDLE
)hService
,
535 (LPWSTR
)lpBinaryPathName
,
536 (LPWSTR
)lpLoadOrderGroup
,
538 (LPBYTE
)lpDependencies
,
539 dwDependenciesLength
,
540 (LPWSTR
)lpServiceStartName
,
543 (LPWSTR
)lpDisplayName
);
545 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
547 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
552 if (lpEncryptedPassword
!= NULL
)
554 /* Wipe and release the password buffer */
555 SecureZeroMemory(lpEncryptedPassword
, dwPasswordSize
);
556 HeapFree(GetProcessHeap(), 0, lpEncryptedPassword
);
559 if (dwError
!= ERROR_SUCCESS
)
561 TRACE("RChangeServiceConfigW() failed (Error %lu)\n", dwError
);
562 SetLastError(dwError
);
570 /**********************************************************************
576 CloseServiceHandle(SC_HANDLE hSCObject
)
580 TRACE("CloseServiceHandle(%p)\n",
585 SetLastError(ERROR_INVALID_HANDLE
);
591 dwError
= RCloseServiceHandle((LPSC_RPC_HANDLE
)&hSCObject
);
593 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
595 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
601 TRACE("RCloseServiceHandle() failed (Error %lu)\n", dwError
);
602 SetLastError(dwError
);
606 TRACE("CloseServiceHandle() done\n");
612 /**********************************************************************
618 ControlService(SC_HANDLE hService
,
620 LPSERVICE_STATUS lpServiceStatus
)
624 TRACE("ControlService(%p %lu %p)\n",
625 hService
, dwControl
, lpServiceStatus
);
629 dwError
= RControlService((SC_RPC_HANDLE
)hService
,
633 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
635 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
639 if (dwError
!= ERROR_SUCCESS
)
641 TRACE("RControlService() failed (Error %lu)\n", dwError
);
642 SetLastError(dwError
);
646 TRACE("ControlService() done\n");
652 /**********************************************************************
658 ControlServiceEx(IN SC_HANDLE hService
,
660 IN DWORD dwInfoLevel
,
661 IN OUT PVOID pControlParams
)
663 FIXME("ControlServiceEx(%p %lu %lu %p)\n",
664 hService
, dwControl
, dwInfoLevel
, pControlParams
);
665 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
670 /**********************************************************************
676 CreateServiceA(SC_HANDLE hSCManager
,
677 LPCSTR lpServiceName
,
678 LPCSTR lpDisplayName
,
679 DWORD dwDesiredAccess
,
682 DWORD dwErrorControl
,
683 LPCSTR lpBinaryPathName
,
684 LPCSTR lpLoadOrderGroup
,
686 LPCSTR lpDependencies
,
687 LPCSTR lpServiceStartName
,
690 SC_HANDLE hService
= NULL
;
691 DWORD dwDependenciesLength
= 0;
695 DWORD dwPasswordSize
= 0;
696 LPWSTR lpPasswordW
= NULL
;
697 LPBYTE lpEncryptedPassword
= NULL
;
699 TRACE("CreateServiceA(%p %s %s %lx %lu %lu %lu %s %s %p %s %s %s)\n",
700 hSCManager
, debugstr_a(lpServiceName
), debugstr_a(lpDisplayName
),
701 dwDesiredAccess
, dwServiceType
, dwStartType
, dwErrorControl
,
702 debugstr_a(lpBinaryPathName
), debugstr_a(lpLoadOrderGroup
), lpdwTagId
,
703 debugstr_a(lpDependencies
), debugstr_a(lpServiceStartName
), debugstr_a(lpPassword
));
707 SetLastError(ERROR_INVALID_HANDLE
);
711 /* Calculate the Dependencies length */
712 if (lpDependencies
!= NULL
)
714 lpStr
= lpDependencies
;
717 cchLength
= strlen(lpStr
) + 1;
718 dwDependenciesLength
+= (DWORD
)cchLength
;
719 lpStr
= lpStr
+ cchLength
;
721 dwDependenciesLength
++;
724 if (lpPassword
!= NULL
)
726 /* Convert the password to unicode */
727 lpPasswordW
= HeapAlloc(GetProcessHeap(),
729 (strlen(lpPassword
) + 1) * sizeof(WCHAR
));
730 if (lpPasswordW
== NULL
)
732 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
736 MultiByteToWideChar(CP_ACP
,
741 (int)(strlen(lpPassword
) + 1));
743 /* Encrypt the password */
744 dwError
= ScmEncryptPassword(lpPasswordW
,
745 &lpEncryptedPassword
,
747 if (dwError
!= ERROR_SUCCESS
)
753 dwError
= RCreateServiceA((SC_RPC_HANDLE
)hSCManager
,
754 (LPSTR
)lpServiceName
,
755 (LPSTR
)lpDisplayName
,
760 (LPSTR
)lpBinaryPathName
,
761 (LPSTR
)lpLoadOrderGroup
,
763 (LPBYTE
)lpDependencies
,
764 dwDependenciesLength
,
765 (LPSTR
)lpServiceStartName
,
768 (SC_RPC_HANDLE
*)&hService
);
770 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
772 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
777 if (lpPasswordW
!= NULL
)
779 /* Wipe and release the password buffers */
780 SecureZeroMemory(lpPasswordW
, (wcslen(lpPasswordW
) + 1) * sizeof(WCHAR
));
781 HeapFree(GetProcessHeap(), 0, lpPasswordW
);
783 if (lpEncryptedPassword
!= NULL
)
785 SecureZeroMemory(lpEncryptedPassword
, dwPasswordSize
);
786 HeapFree(GetProcessHeap(), 0, lpEncryptedPassword
);
790 SetLastError(dwError
);
791 if (dwError
!= ERROR_SUCCESS
)
793 TRACE("RCreateServiceA() failed (Error %lu)\n", dwError
);
801 /**********************************************************************
807 CreateServiceW(SC_HANDLE hSCManager
,
808 LPCWSTR lpServiceName
,
809 LPCWSTR lpDisplayName
,
810 DWORD dwDesiredAccess
,
813 DWORD dwErrorControl
,
814 LPCWSTR lpBinaryPathName
,
815 LPCWSTR lpLoadOrderGroup
,
817 LPCWSTR lpDependencies
,
818 LPCWSTR lpServiceStartName
,
821 SC_HANDLE hService
= NULL
;
822 DWORD dwDependenciesLength
= 0;
826 DWORD dwPasswordSize
= 0;
827 LPBYTE lpEncryptedPassword
= NULL
;
829 TRACE("CreateServiceW(%p %s %s %lx %lu %lu %lu %s %s %p %s %s %s)\n",
830 hSCManager
, debugstr_w(lpServiceName
), debugstr_w(lpDisplayName
),
831 dwDesiredAccess
, dwServiceType
, dwStartType
, dwErrorControl
,
832 debugstr_w(lpBinaryPathName
), debugstr_w(lpLoadOrderGroup
), lpdwTagId
,
833 debugstr_w(lpDependencies
), debugstr_w(lpServiceStartName
), debugstr_w(lpPassword
));
837 SetLastError(ERROR_INVALID_HANDLE
);
841 /* Calculate the Dependencies length */
842 if (lpDependencies
!= NULL
)
844 lpStr
= lpDependencies
;
847 cchLength
= wcslen(lpStr
) + 1;
848 dwDependenciesLength
+= (DWORD
)cchLength
;
849 lpStr
= lpStr
+ cchLength
;
851 dwDependenciesLength
++;
852 dwDependenciesLength
*= sizeof(WCHAR
);
855 if (lpPassword
!= NULL
)
857 /* Encrypt the password */
858 dwError
= ScmEncryptPassword(lpPassword
,
859 &lpEncryptedPassword
,
861 if (dwError
!= ERROR_SUCCESS
)
867 dwError
= RCreateServiceW((SC_RPC_HANDLE
)hSCManager
,
877 (LPBYTE
)lpDependencies
,
878 dwDependenciesLength
,
882 (SC_RPC_HANDLE
*)&hService
);
884 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
886 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
891 if (lpEncryptedPassword
!= NULL
)
893 /* Wipe and release the password buffers */
894 SecureZeroMemory(lpEncryptedPassword
, dwPasswordSize
);
895 HeapFree(GetProcessHeap(), 0, lpEncryptedPassword
);
898 SetLastError(dwError
);
899 if (dwError
!= ERROR_SUCCESS
)
901 TRACE("RCreateServiceW() failed (Error %lu)\n", dwError
);
909 /**********************************************************************
915 DeleteService(SC_HANDLE hService
)
919 TRACE("DeleteService(%p)\n",
924 dwError
= RDeleteService((SC_RPC_HANDLE
)hService
);
926 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
928 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
932 if (dwError
!= ERROR_SUCCESS
)
934 TRACE("RDeleteService() failed (Error %lu)\n", dwError
);
935 SetLastError(dwError
);
943 /**********************************************************************
944 * EnumDependentServicesA
949 EnumDependentServicesA(SC_HANDLE hService
,
950 DWORD dwServiceState
,
951 LPENUM_SERVICE_STATUSA lpServices
,
953 LPDWORD pcbBytesNeeded
,
954 LPDWORD lpServicesReturned
)
956 ENUM_SERVICE_STATUSA ServiceStatus
;
957 LPENUM_SERVICE_STATUSA lpStatusPtr
;
962 TRACE("EnumDependentServicesA(%p %lu %p %lu %p %p)\n",
963 hService
, dwServiceState
, lpServices
, cbBufSize
,
964 pcbBytesNeeded
, lpServicesReturned
);
966 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSA
))
968 lpStatusPtr
= &ServiceStatus
;
969 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSA
);
973 lpStatusPtr
= lpServices
;
974 dwBufferSize
= cbBufSize
;
979 dwError
= REnumDependentServicesA((SC_RPC_HANDLE
)hService
,
986 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
988 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
992 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
994 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
996 if (lpStatusPtr
->lpServiceName
)
997 lpStatusPtr
->lpServiceName
=
998 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1000 if (lpStatusPtr
->lpDisplayName
)
1001 lpStatusPtr
->lpDisplayName
=
1002 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1008 if (dwError
!= ERROR_SUCCESS
)
1010 TRACE("REnumDependentServicesA() failed (Error %lu)\n", dwError
);
1011 SetLastError(dwError
);
1015 TRACE("EnumDependentServicesA() done\n");
1021 /**********************************************************************
1022 * EnumDependentServicesW
1027 EnumDependentServicesW(SC_HANDLE hService
,
1028 DWORD dwServiceState
,
1029 LPENUM_SERVICE_STATUSW lpServices
,
1031 LPDWORD pcbBytesNeeded
,
1032 LPDWORD lpServicesReturned
)
1034 ENUM_SERVICE_STATUSW ServiceStatus
;
1035 LPENUM_SERVICE_STATUSW lpStatusPtr
;
1040 TRACE("EnumDependentServicesW(%p %lu %p %lu %p %p)\n",
1041 hService
, dwServiceState
, lpServices
, cbBufSize
,
1042 pcbBytesNeeded
, lpServicesReturned
);
1044 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSW
))
1046 lpStatusPtr
= &ServiceStatus
;
1047 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSW
);
1051 lpStatusPtr
= lpServices
;
1052 dwBufferSize
= cbBufSize
;
1057 dwError
= REnumDependentServicesW((SC_RPC_HANDLE
)hService
,
1059 (LPBYTE
)lpStatusPtr
,
1062 lpServicesReturned
);
1064 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1066 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1070 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1072 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1074 if (lpStatusPtr
->lpServiceName
)
1075 lpStatusPtr
->lpServiceName
=
1076 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1078 if (lpStatusPtr
->lpDisplayName
)
1079 lpStatusPtr
->lpDisplayName
=
1080 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1086 if (dwError
!= ERROR_SUCCESS
)
1088 TRACE("REnumDependentServicesW() failed (Error %lu)\n", dwError
);
1089 SetLastError(dwError
);
1093 TRACE("EnumDependentServicesW() done\n");
1099 /**********************************************************************
1105 EnumServiceGroupW(SC_HANDLE hSCManager
,
1106 DWORD dwServiceType
,
1107 DWORD dwServiceState
,
1108 LPENUM_SERVICE_STATUSW lpServices
,
1110 LPDWORD pcbBytesNeeded
,
1111 LPDWORD lpServicesReturned
,
1112 LPDWORD lpResumeHandle
,
1115 ENUM_SERVICE_STATUSW ServiceStatus
;
1116 LPENUM_SERVICE_STATUSW lpStatusPtr
;
1121 TRACE("EnumServiceGroupW(%p %lu %lu %p %lu %p %p %p %s)\n",
1122 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1123 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
,
1124 lpResumeHandle
, debugstr_w(lpGroup
));
1128 SetLastError(ERROR_INVALID_HANDLE
);
1132 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1134 SetLastError(ERROR_INVALID_ADDRESS
);
1138 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSW
))
1140 lpStatusPtr
= &ServiceStatus
;
1141 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSW
);
1145 lpStatusPtr
= lpServices
;
1146 dwBufferSize
= cbBufSize
;
1151 if (lpGroup
== NULL
)
1153 dwError
= REnumServicesStatusW((SC_RPC_HANDLE
)hSCManager
,
1156 (LPBYTE
)lpStatusPtr
,
1164 dwError
= REnumServiceGroupW((SC_RPC_HANDLE
)hSCManager
,
1167 (LPBYTE
)lpStatusPtr
,
1175 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1177 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1181 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1183 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1185 if (lpStatusPtr
->lpServiceName
)
1186 lpStatusPtr
->lpServiceName
=
1187 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1189 if (lpStatusPtr
->lpDisplayName
)
1190 lpStatusPtr
->lpDisplayName
=
1191 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1197 if (dwError
!= ERROR_SUCCESS
)
1199 TRACE("REnumServiceGroupW() failed (Error %lu)\n", dwError
);
1200 SetLastError(dwError
);
1204 TRACE("EnumServiceGroupW() done\n");
1210 /**********************************************************************
1211 * EnumServicesStatusA
1216 EnumServicesStatusA(SC_HANDLE hSCManager
,
1217 DWORD dwServiceType
,
1218 DWORD dwServiceState
,
1219 LPENUM_SERVICE_STATUSA lpServices
,
1221 LPDWORD pcbBytesNeeded
,
1222 LPDWORD lpServicesReturned
,
1223 LPDWORD lpResumeHandle
)
1225 ENUM_SERVICE_STATUSA ServiceStatus
;
1226 LPENUM_SERVICE_STATUSA lpStatusPtr
;
1231 TRACE("EnumServicesStatusA(%p %lu %lu %p %lu %p %p %p)\n",
1232 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1233 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
, lpResumeHandle
);
1237 SetLastError(ERROR_INVALID_HANDLE
);
1241 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1243 SetLastError(ERROR_INVALID_ADDRESS
);
1247 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSA
))
1249 lpStatusPtr
= &ServiceStatus
;
1250 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSA
);
1254 lpStatusPtr
= lpServices
;
1255 dwBufferSize
= cbBufSize
;
1260 dwError
= REnumServicesStatusA((SC_RPC_HANDLE
)hSCManager
,
1263 (LPBYTE
)lpStatusPtr
,
1269 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1271 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1275 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1277 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1279 if (lpStatusPtr
->lpServiceName
)
1280 lpStatusPtr
->lpServiceName
=
1281 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1283 if (lpStatusPtr
->lpDisplayName
)
1284 lpStatusPtr
->lpDisplayName
=
1285 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1291 if (dwError
!= ERROR_SUCCESS
)
1293 TRACE("REnumServicesStatusA() failed (Error %lu)\n", dwError
);
1294 SetLastError(dwError
);
1298 TRACE("EnumServicesStatusA() done\n");
1304 /**********************************************************************
1305 * EnumServicesStatusW
1310 EnumServicesStatusW(SC_HANDLE hSCManager
,
1311 DWORD dwServiceType
,
1312 DWORD dwServiceState
,
1313 LPENUM_SERVICE_STATUSW lpServices
,
1315 LPDWORD pcbBytesNeeded
,
1316 LPDWORD lpServicesReturned
,
1317 LPDWORD lpResumeHandle
)
1319 ENUM_SERVICE_STATUSW ServiceStatus
;
1320 LPENUM_SERVICE_STATUSW lpStatusPtr
;
1325 TRACE("EnumServicesStatusW(%p %lu %lu %p %lu %p %p %p)\n",
1326 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1327 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
, lpResumeHandle
);
1331 SetLastError(ERROR_INVALID_HANDLE
);
1335 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1337 SetLastError(ERROR_INVALID_ADDRESS
);
1341 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSW
))
1343 lpStatusPtr
= &ServiceStatus
;
1344 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSW
);
1348 lpStatusPtr
= lpServices
;
1349 dwBufferSize
= cbBufSize
;
1354 dwError
= REnumServicesStatusW((SC_RPC_HANDLE
)hSCManager
,
1357 (LPBYTE
)lpStatusPtr
,
1363 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1365 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1369 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1371 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1373 if (lpStatusPtr
->lpServiceName
)
1374 lpStatusPtr
->lpServiceName
=
1375 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1377 if (lpStatusPtr
->lpDisplayName
)
1378 lpStatusPtr
->lpDisplayName
=
1379 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1385 if (dwError
!= ERROR_SUCCESS
)
1387 TRACE("REnumServicesStatusW() failed (Error %lu)\n", dwError
);
1388 SetLastError(dwError
);
1392 TRACE("EnumServicesStatusW() done\n");
1398 /**********************************************************************
1399 * EnumServicesStatusExA
1404 EnumServicesStatusExA(SC_HANDLE hSCManager
,
1405 SC_ENUM_TYPE InfoLevel
,
1406 DWORD dwServiceType
,
1407 DWORD dwServiceState
,
1410 LPDWORD pcbBytesNeeded
,
1411 LPDWORD lpServicesReturned
,
1412 LPDWORD lpResumeHandle
,
1413 LPCSTR pszGroupName
)
1415 ENUM_SERVICE_STATUS_PROCESSA ServiceStatus
;
1416 LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtr
;
1421 TRACE("EnumServicesStatusExA(%p %lu %lu %p %lu %p %p %p %s)\n",
1422 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1423 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
, lpResumeHandle
,
1424 debugstr_a(pszGroupName
));
1426 if (InfoLevel
!= SC_ENUM_PROCESS_INFO
)
1428 SetLastError(ERROR_INVALID_LEVEL
);
1434 SetLastError(ERROR_INVALID_HANDLE
);
1438 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1440 SetLastError(ERROR_INVALID_ADDRESS
);
1444 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUS_PROCESSA
))
1446 lpStatusPtr
= &ServiceStatus
;
1447 dwBufferSize
= sizeof(ENUM_SERVICE_STATUS_PROCESSA
);
1451 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpServices
;
1452 dwBufferSize
= cbBufSize
;
1457 dwError
= REnumServicesStatusExA((SC_RPC_HANDLE
)hSCManager
,
1461 (LPBYTE
)lpStatusPtr
,
1466 (LPSTR
)pszGroupName
);
1468 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1470 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1474 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1476 if (InfoLevel
== SC_ENUM_PROCESS_INFO
)
1478 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1480 if (lpStatusPtr
->lpServiceName
)
1481 lpStatusPtr
->lpServiceName
=
1482 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1484 if (lpStatusPtr
->lpDisplayName
)
1485 lpStatusPtr
->lpDisplayName
=
1486 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1493 if (dwError
!= ERROR_SUCCESS
)
1495 TRACE("REnumServicesStatusExA() failed (Error %lu)\n", dwError
);
1496 SetLastError(dwError
);
1500 TRACE("EnumServicesStatusExA() done\n");
1506 /**********************************************************************
1507 * EnumServicesStatusExW
1512 EnumServicesStatusExW(SC_HANDLE hSCManager
,
1513 SC_ENUM_TYPE InfoLevel
,
1514 DWORD dwServiceType
,
1515 DWORD dwServiceState
,
1518 LPDWORD pcbBytesNeeded
,
1519 LPDWORD lpServicesReturned
,
1520 LPDWORD lpResumeHandle
,
1521 LPCWSTR pszGroupName
)
1523 ENUM_SERVICE_STATUS_PROCESSW ServiceStatus
;
1524 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
1529 TRACE("EnumServicesStatusExW(%p %lu %lu %p %lu %p %p %p %s)\n",
1530 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1531 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
, lpResumeHandle
,
1532 debugstr_w(pszGroupName
));
1534 if (InfoLevel
!= SC_ENUM_PROCESS_INFO
)
1536 SetLastError(ERROR_INVALID_LEVEL
);
1542 SetLastError(ERROR_INVALID_HANDLE
);
1546 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1548 SetLastError(ERROR_INVALID_ADDRESS
);
1552 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUS_PROCESSW
))
1554 lpStatusPtr
= &ServiceStatus
;
1555 dwBufferSize
= sizeof(ENUM_SERVICE_STATUS_PROCESSW
);
1559 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpServices
;
1560 dwBufferSize
= cbBufSize
;
1565 dwError
= REnumServicesStatusExW((SC_RPC_HANDLE
)hSCManager
,
1569 (LPBYTE
)lpStatusPtr
,
1574 (LPWSTR
)pszGroupName
);
1576 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1578 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1582 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1584 if (InfoLevel
== SC_ENUM_PROCESS_INFO
)
1586 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1588 if (lpStatusPtr
->lpServiceName
)
1589 lpStatusPtr
->lpServiceName
=
1590 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1592 if (lpStatusPtr
->lpDisplayName
)
1593 lpStatusPtr
->lpDisplayName
=
1594 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1601 if (dwError
!= ERROR_SUCCESS
)
1603 TRACE("REnumServicesStatusExW() failed (Error %lu)\n", dwError
);
1604 SetLastError(dwError
);
1608 TRACE("EnumServicesStatusExW() done\n");
1614 /**********************************************************************
1615 * GetServiceDisplayNameA
1620 GetServiceDisplayNameA(SC_HANDLE hSCManager
,
1621 LPCSTR lpServiceName
,
1622 LPSTR lpDisplayName
,
1623 LPDWORD lpcchBuffer
)
1627 CHAR szEmptyName
[] = "";
1629 TRACE("GetServiceDisplayNameA(%p %s %p %p)\n",
1630 hSCManager
, debugstr_a(lpServiceName
), lpDisplayName
, lpcchBuffer
);
1634 SetLastError(ERROR_INVALID_HANDLE
);
1638 if (!lpDisplayName
|| *lpcchBuffer
< sizeof(CHAR
))
1640 lpNameBuffer
= szEmptyName
;
1641 *lpcchBuffer
= sizeof(CHAR
);
1645 lpNameBuffer
= lpDisplayName
;
1650 dwError
= RGetServiceDisplayNameA((SC_RPC_HANDLE
)hSCManager
,
1655 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1657 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1661 if (dwError
!= ERROR_SUCCESS
)
1663 TRACE("RGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
1664 SetLastError(dwError
);
1672 /**********************************************************************
1673 * GetServiceDisplayNameW
1678 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
1679 LPCWSTR lpServiceName
,
1680 LPWSTR lpDisplayName
,
1681 LPDWORD lpcchBuffer
)
1684 LPWSTR lpNameBuffer
;
1685 WCHAR szEmptyName
[] = L
"";
1687 TRACE("GetServiceDisplayNameW(%p %s %p %p)\n",
1688 hSCManager
, debugstr_w(lpServiceName
), lpDisplayName
, lpcchBuffer
);
1692 SetLastError(ERROR_INVALID_HANDLE
);
1696 if (!lpDisplayName
|| *lpcchBuffer
< sizeof(WCHAR
))
1698 lpNameBuffer
= szEmptyName
;
1699 *lpcchBuffer
= sizeof(WCHAR
);
1703 lpNameBuffer
= lpDisplayName
;
1708 dwError
= RGetServiceDisplayNameW((SC_RPC_HANDLE
)hSCManager
,
1713 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1715 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1719 if (dwError
!= ERROR_SUCCESS
)
1721 TRACE("RGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1722 SetLastError(dwError
);
1730 /**********************************************************************
1731 * GetServiceKeyNameA
1736 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1737 LPCSTR lpDisplayName
,
1738 LPSTR lpServiceName
,
1739 LPDWORD lpcchBuffer
)
1743 CHAR szEmptyName
[] = "";
1745 TRACE("GetServiceKeyNameA(%p %s %p %p)\n",
1746 hSCManager
, debugstr_a(lpDisplayName
), lpServiceName
, lpcchBuffer
);
1750 SetLastError(ERROR_INVALID_HANDLE
);
1754 if (!lpServiceName
|| *lpcchBuffer
< sizeof(CHAR
))
1756 lpNameBuffer
= szEmptyName
;
1757 *lpcchBuffer
= sizeof(CHAR
);
1761 lpNameBuffer
= lpServiceName
;
1766 dwError
= RGetServiceKeyNameA((SC_RPC_HANDLE
)hSCManager
,
1771 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1773 /* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
1774 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1778 if (dwError
!= ERROR_SUCCESS
)
1780 TRACE("RGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1781 SetLastError(dwError
);
1789 /**********************************************************************
1790 * GetServiceKeyNameW
1795 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1796 LPCWSTR lpDisplayName
,
1797 LPWSTR lpServiceName
,
1798 LPDWORD lpcchBuffer
)
1801 LPWSTR lpNameBuffer
;
1802 WCHAR szEmptyName
[] = L
"";
1804 TRACE("GetServiceKeyNameW(%p %s %p %p)\n",
1805 hSCManager
, debugstr_w(lpDisplayName
), lpServiceName
, lpcchBuffer
);
1809 SetLastError(ERROR_INVALID_HANDLE
);
1813 if (!lpServiceName
|| *lpcchBuffer
< sizeof(WCHAR
))
1815 lpNameBuffer
= szEmptyName
;
1816 *lpcchBuffer
= sizeof(WCHAR
);
1820 lpNameBuffer
= lpServiceName
;
1825 dwError
= RGetServiceKeyNameW((SC_RPC_HANDLE
)hSCManager
,
1830 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1832 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1836 if (dwError
!= ERROR_SUCCESS
)
1838 TRACE("RGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1839 SetLastError(dwError
);
1847 /**********************************************************************
1848 * I_ScGetCurrentGroupStateW
1853 I_ScGetCurrentGroupStateW(SC_HANDLE hSCManager
,
1854 LPWSTR pszGroupName
,
1855 LPDWORD pdwGroupState
)
1859 TRACE("I_ScGetCurrentGroupStateW(%p %s %p)\n",
1860 hSCManager
, debugstr_w(pszGroupName
), pdwGroupState
);
1864 dwError
= RI_ScGetCurrentGroupStateW((SC_RPC_HANDLE
)hSCManager
,
1868 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1870 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1874 if (dwError
!= ERROR_SUCCESS
)
1876 TRACE("RI_ScGetCurrentGroupStateW() failed (Error %lu)\n", dwError
);
1877 SetLastError(dwError
);
1884 /**********************************************************************
1885 * LockServiceDatabase
1890 LockServiceDatabase(SC_HANDLE hSCManager
)
1895 TRACE("LockServiceDatabase(%p)\n",
1900 dwError
= RLockServiceDatabase((SC_RPC_HANDLE
)hSCManager
,
1901 (SC_RPC_LOCK
*)&hLock
);
1903 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1905 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1909 if (dwError
!= ERROR_SUCCESS
)
1911 TRACE("RLockServiceDatabase() failed (Error %lu)\n", dwError
);
1912 SetLastError(dwError
);
1916 TRACE("hLock = %p\n", hLock
);
1923 WaitForSCManager(VOID
)
1927 TRACE("WaitForSCManager()\n");
1929 /* Try to open the existing event */
1930 hEvent
= OpenEventW(SYNCHRONIZE
, FALSE
, SCM_START_EVENT
);
1933 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1936 /* Try to create a new event */
1937 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, SCM_START_EVENT
);
1942 /* Wait for 3 minutes */
1943 WaitForSingleObject(hEvent
, 180000);
1944 CloseHandle(hEvent
);
1946 TRACE("ScmWaitForSCManager() done\n");
1950 /**********************************************************************
1956 OpenSCManagerA(LPCSTR lpMachineName
,
1957 LPCSTR lpDatabaseName
,
1958 DWORD dwDesiredAccess
)
1960 SC_HANDLE hScm
= NULL
;
1963 TRACE("OpenSCManagerA(%s %s %lx)\n",
1964 debugstr_a(lpMachineName
), debugstr_a(lpDatabaseName
), dwDesiredAccess
);
1970 dwError
= ROpenSCManagerA((LPSTR
)lpMachineName
,
1971 (LPSTR
)lpDatabaseName
,
1973 (SC_RPC_HANDLE
*)&hScm
);
1975 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1977 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1981 if (dwError
!= ERROR_SUCCESS
)
1983 TRACE("ROpenSCManagerA() failed (Error %lu)\n", dwError
);
1984 SetLastError(dwError
);
1988 TRACE("hScm = %p\n", hScm
);
1994 /**********************************************************************
2000 OpenSCManagerW(LPCWSTR lpMachineName
,
2001 LPCWSTR lpDatabaseName
,
2002 DWORD dwDesiredAccess
)
2004 SC_HANDLE hScm
= NULL
;
2007 TRACE("OpenSCManagerW(%s %s %lx)\n",
2008 debugstr_w(lpMachineName
), debugstr_w(lpDatabaseName
), dwDesiredAccess
);
2014 dwError
= ROpenSCManagerW((LPWSTR
)lpMachineName
,
2015 (LPWSTR
)lpDatabaseName
,
2017 (SC_RPC_HANDLE
*)&hScm
);
2019 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2021 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2025 if (dwError
!= ERROR_SUCCESS
)
2027 TRACE("ROpenSCManagerW() failed (Error %lu)\n", dwError
);
2028 SetLastError(dwError
);
2032 TRACE("hScm = %p\n", hScm
);
2038 /**********************************************************************
2044 OpenServiceA(SC_HANDLE hSCManager
,
2045 LPCSTR lpServiceName
,
2046 DWORD dwDesiredAccess
)
2048 SC_HANDLE hService
= NULL
;
2051 TRACE("OpenServiceA(%p %s %lx)\n",
2052 hSCManager
, debugstr_a(lpServiceName
), dwDesiredAccess
);
2056 SetLastError(ERROR_INVALID_HANDLE
);
2062 dwError
= ROpenServiceA((SC_RPC_HANDLE
)hSCManager
,
2063 (LPSTR
)lpServiceName
,
2065 (SC_RPC_HANDLE
*)&hService
);
2067 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2069 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2073 SetLastError(dwError
);
2074 if (dwError
!= ERROR_SUCCESS
)
2076 TRACE("ROpenServiceA() failed (Error %lu)\n", dwError
);
2080 TRACE("hService = %p\n", hService
);
2086 /**********************************************************************
2092 OpenServiceW(SC_HANDLE hSCManager
,
2093 LPCWSTR lpServiceName
,
2094 DWORD dwDesiredAccess
)
2096 SC_HANDLE hService
= NULL
;
2099 TRACE("OpenServiceW(%p %s %lx)\n",
2100 hSCManager
, debugstr_w(lpServiceName
), dwDesiredAccess
);
2104 SetLastError(ERROR_INVALID_HANDLE
);
2110 dwError
= ROpenServiceW((SC_RPC_HANDLE
)hSCManager
,
2111 (LPWSTR
)lpServiceName
,
2113 (SC_RPC_HANDLE
*)&hService
);
2115 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2117 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2121 SetLastError(dwError
);
2122 if (dwError
!= ERROR_SUCCESS
)
2124 TRACE("ROpenServiceW() failed (Error %lu)\n", dwError
);
2128 TRACE("hService = %p\n", hService
);
2134 /**********************************************************************
2135 * QueryServiceConfigA
2140 QueryServiceConfigA(SC_HANDLE hService
,
2141 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
2143 LPDWORD pcbBytesNeeded
)
2145 QUERY_SERVICE_CONFIGA ServiceConfig
;
2146 LPQUERY_SERVICE_CONFIGA lpConfigPtr
;
2150 TRACE("QueryServiceConfigA(%p %p %lu %p)\n",
2151 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
2153 if (lpServiceConfig
== NULL
||
2154 cbBufSize
< sizeof(QUERY_SERVICE_CONFIGA
))
2156 lpConfigPtr
= &ServiceConfig
;
2157 dwBufferSize
= sizeof(QUERY_SERVICE_CONFIGA
);
2161 lpConfigPtr
= lpServiceConfig
;
2162 dwBufferSize
= cbBufSize
;
2167 dwError
= RQueryServiceConfigA((SC_RPC_HANDLE
)hService
,
2168 (LPBYTE
)lpConfigPtr
,
2172 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2174 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2178 if (dwError
!= ERROR_SUCCESS
)
2180 TRACE("RQueryServiceConfigA() failed (Error %lu)\n", dwError
);
2181 SetLastError(dwError
);
2185 /* Adjust the pointers */
2186 if (lpConfigPtr
->lpBinaryPathName
)
2187 lpConfigPtr
->lpBinaryPathName
=
2188 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2189 (ULONG_PTR
)lpConfigPtr
->lpBinaryPathName
);
2191 if (lpConfigPtr
->lpLoadOrderGroup
)
2192 lpConfigPtr
->lpLoadOrderGroup
=
2193 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2194 (ULONG_PTR
)lpConfigPtr
->lpLoadOrderGroup
);
2196 if (lpConfigPtr
->lpDependencies
)
2197 lpConfigPtr
->lpDependencies
=
2198 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2199 (ULONG_PTR
)lpConfigPtr
->lpDependencies
);
2201 if (lpConfigPtr
->lpServiceStartName
)
2202 lpConfigPtr
->lpServiceStartName
=
2203 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2204 (ULONG_PTR
)lpConfigPtr
->lpServiceStartName
);
2206 if (lpConfigPtr
->lpDisplayName
)
2207 lpConfigPtr
->lpDisplayName
=
2208 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2209 (ULONG_PTR
)lpConfigPtr
->lpDisplayName
);
2211 TRACE("QueryServiceConfigA() done\n");
2217 /**********************************************************************
2218 * QueryServiceConfigW
2223 QueryServiceConfigW(SC_HANDLE hService
,
2224 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
2226 LPDWORD pcbBytesNeeded
)
2228 QUERY_SERVICE_CONFIGW ServiceConfig
;
2229 LPQUERY_SERVICE_CONFIGW lpConfigPtr
;
2233 TRACE("QueryServiceConfigW(%p %p %lu %p)\n",
2234 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
2236 if (lpServiceConfig
== NULL
||
2237 cbBufSize
< sizeof(QUERY_SERVICE_CONFIGW
))
2239 lpConfigPtr
= &ServiceConfig
;
2240 dwBufferSize
= sizeof(QUERY_SERVICE_CONFIGW
);
2244 lpConfigPtr
= lpServiceConfig
;
2245 dwBufferSize
= cbBufSize
;
2250 dwError
= RQueryServiceConfigW((SC_RPC_HANDLE
)hService
,
2251 (LPBYTE
)lpConfigPtr
,
2255 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2257 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2261 if (dwError
!= ERROR_SUCCESS
)
2263 TRACE("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
2264 SetLastError(dwError
);
2268 /* Adjust the pointers */
2269 if (lpConfigPtr
->lpBinaryPathName
)
2270 lpConfigPtr
->lpBinaryPathName
=
2271 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2272 (ULONG_PTR
)lpConfigPtr
->lpBinaryPathName
);
2274 if (lpConfigPtr
->lpLoadOrderGroup
)
2275 lpConfigPtr
->lpLoadOrderGroup
=
2276 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2277 (ULONG_PTR
)lpConfigPtr
->lpLoadOrderGroup
);
2279 if (lpConfigPtr
->lpDependencies
)
2280 lpConfigPtr
->lpDependencies
=
2281 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2282 (ULONG_PTR
)lpConfigPtr
->lpDependencies
);
2284 if (lpConfigPtr
->lpServiceStartName
)
2285 lpConfigPtr
->lpServiceStartName
=
2286 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2287 (ULONG_PTR
)lpConfigPtr
->lpServiceStartName
);
2289 if (lpConfigPtr
->lpDisplayName
)
2290 lpConfigPtr
->lpDisplayName
=
2291 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2292 (ULONG_PTR
)lpConfigPtr
->lpDisplayName
);
2294 TRACE("QueryServiceConfigW() done\n");
2300 /**********************************************************************
2301 * QueryServiceConfig2A
2306 QueryServiceConfig2A(SC_HANDLE hService
,
2310 LPDWORD pcbBytesNeeded
)
2312 SERVICE_DESCRIPTIONA ServiceDescription
;
2313 SERVICE_FAILURE_ACTIONSA ServiceFailureActions
;
2314 LPBYTE lpTempBuffer
;
2315 BOOL bUseTempBuffer
= FALSE
;
2319 TRACE("QueryServiceConfig2A(%p %lu %p %lu %p)\n",
2320 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2322 lpTempBuffer
= lpBuffer
;
2323 dwBufferSize
= cbBufSize
;
2325 switch (dwInfoLevel
)
2327 case SERVICE_CONFIG_DESCRIPTION
:
2328 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_DESCRIPTIONA
)))
2330 lpTempBuffer
= (LPBYTE
)&ServiceDescription
;
2331 dwBufferSize
= sizeof(SERVICE_DESCRIPTIONA
);
2332 bUseTempBuffer
= TRUE
;
2336 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2337 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_FAILURE_ACTIONSA
)))
2339 lpTempBuffer
= (LPBYTE
)&ServiceFailureActions
;
2340 dwBufferSize
= sizeof(SERVICE_FAILURE_ACTIONSA
);
2341 bUseTempBuffer
= TRUE
;
2346 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
2347 SetLastError(ERROR_INVALID_LEVEL
);
2353 dwError
= RQueryServiceConfig2A((SC_RPC_HANDLE
)hService
,
2359 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2361 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2365 if (dwError
!= ERROR_SUCCESS
)
2367 TRACE("RQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
2368 SetLastError(dwError
);
2372 if (bUseTempBuffer
!= FALSE
)
2374 TRACE("RQueryServiceConfig2A() returns ERROR_INSUFFICIENT_BUFFER\n");
2375 *pcbBytesNeeded
= dwBufferSize
;
2376 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2380 switch (dwInfoLevel
)
2382 case SERVICE_CONFIG_DESCRIPTION
:
2384 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpTempBuffer
;
2386 if (lpPtr
->lpDescription
!= NULL
)
2387 lpPtr
->lpDescription
=
2388 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpDescription
);
2392 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2394 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpTempBuffer
;
2396 if (lpPtr
->lpRebootMsg
!= NULL
)
2397 lpPtr
->lpRebootMsg
=
2398 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpRebootMsg
);
2400 if (lpPtr
->lpCommand
!= NULL
)
2402 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpCommand
);
2404 if (lpPtr
->lpsaActions
!= NULL
)
2405 lpPtr
->lpsaActions
=
2406 (LPSC_ACTION
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpsaActions
);
2411 TRACE("QueryServiceConfig2A() done\n");
2417 /**********************************************************************
2418 * QueryServiceConfig2W
2423 QueryServiceConfig2W(SC_HANDLE hService
,
2427 LPDWORD pcbBytesNeeded
)
2429 SERVICE_DESCRIPTIONW ServiceDescription
;
2430 SERVICE_FAILURE_ACTIONSW ServiceFailureActions
;
2431 LPBYTE lpTempBuffer
;
2432 BOOL bUseTempBuffer
= FALSE
;
2436 TRACE("QueryServiceConfig2W(%p %lu %p %lu %p)\n",
2437 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2439 lpTempBuffer
= lpBuffer
;
2440 dwBufferSize
= cbBufSize
;
2442 switch (dwInfoLevel
)
2444 case SERVICE_CONFIG_DESCRIPTION
:
2445 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_DESCRIPTIONW
)))
2447 lpTempBuffer
= (LPBYTE
)&ServiceDescription
;
2448 dwBufferSize
= sizeof(SERVICE_DESCRIPTIONW
);
2449 bUseTempBuffer
= TRUE
;
2453 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2454 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_FAILURE_ACTIONSW
)))
2456 lpTempBuffer
= (LPBYTE
)&ServiceFailureActions
;
2457 dwBufferSize
= sizeof(SERVICE_FAILURE_ACTIONSW
);
2458 bUseTempBuffer
= TRUE
;
2463 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
2464 SetLastError(ERROR_INVALID_LEVEL
);
2470 dwError
= RQueryServiceConfig2W((SC_RPC_HANDLE
)hService
,
2476 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2478 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2482 if (dwError
!= ERROR_SUCCESS
)
2484 TRACE("RQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
2485 SetLastError(dwError
);
2489 if (bUseTempBuffer
!= FALSE
)
2491 TRACE("RQueryServiceConfig2W() returns ERROR_INSUFFICIENT_BUFFER\n");
2492 *pcbBytesNeeded
= dwBufferSize
;
2493 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2497 switch (dwInfoLevel
)
2499 case SERVICE_CONFIG_DESCRIPTION
:
2501 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpTempBuffer
;
2503 if (lpPtr
->lpDescription
!= NULL
)
2504 lpPtr
->lpDescription
=
2505 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpDescription
);
2509 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2511 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpTempBuffer
;
2513 if (lpPtr
->lpRebootMsg
!= NULL
)
2514 lpPtr
->lpRebootMsg
=
2515 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpRebootMsg
);
2517 if (lpPtr
->lpCommand
!= NULL
)
2519 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpCommand
);
2521 if (lpPtr
->lpsaActions
!= NULL
)
2522 lpPtr
->lpsaActions
=
2523 (LPSC_ACTION
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpsaActions
);
2528 TRACE("QueryServiceConfig2W() done\n");
2534 /**********************************************************************
2535 * QueryServiceLockStatusA
2540 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
2541 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
2543 LPDWORD pcbBytesNeeded
)
2545 QUERY_SERVICE_LOCK_STATUSA LockStatus
;
2546 LPQUERY_SERVICE_LOCK_STATUSA lpStatusPtr
;
2550 TRACE("QueryServiceLockStatusA(%p %p %lu %p)\n",
2551 hSCManager
, lpLockStatus
, cbBufSize
, pcbBytesNeeded
);
2553 if (lpLockStatus
== NULL
|| cbBufSize
< sizeof(QUERY_SERVICE_LOCK_STATUSA
))
2555 lpStatusPtr
= &LockStatus
;
2556 dwBufferSize
= sizeof(QUERY_SERVICE_LOCK_STATUSA
);
2560 lpStatusPtr
= lpLockStatus
;
2561 dwBufferSize
= cbBufSize
;
2566 dwError
= RQueryServiceLockStatusA((SC_RPC_HANDLE
)hSCManager
,
2567 (LPBYTE
)lpStatusPtr
,
2571 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2573 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2577 if (dwError
!= ERROR_SUCCESS
)
2579 TRACE("RQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
2580 SetLastError(dwError
);
2584 if (lpStatusPtr
->lpLockOwner
!= NULL
)
2586 lpStatusPtr
->lpLockOwner
=
2587 (LPSTR
)((ULONG_PTR
)lpStatusPtr
+ (ULONG_PTR
)lpStatusPtr
->lpLockOwner
);
2590 TRACE("QueryServiceLockStatusA() done\n");
2596 /**********************************************************************
2597 * QueryServiceLockStatusW
2602 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
2603 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
2605 LPDWORD pcbBytesNeeded
)
2607 QUERY_SERVICE_LOCK_STATUSW LockStatus
;
2608 LPQUERY_SERVICE_LOCK_STATUSW lpStatusPtr
;
2612 TRACE("QueryServiceLockStatusW(%p %p %lu %p)\n",
2613 hSCManager
, lpLockStatus
, cbBufSize
, pcbBytesNeeded
);
2615 if (lpLockStatus
== NULL
|| cbBufSize
< sizeof(QUERY_SERVICE_LOCK_STATUSW
))
2617 lpStatusPtr
= &LockStatus
;
2618 dwBufferSize
= sizeof(QUERY_SERVICE_LOCK_STATUSW
);
2622 lpStatusPtr
= lpLockStatus
;
2623 dwBufferSize
= cbBufSize
;
2628 dwError
= RQueryServiceLockStatusW((SC_RPC_HANDLE
)hSCManager
,
2629 (LPBYTE
)lpStatusPtr
,
2633 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2635 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2639 if (dwError
!= ERROR_SUCCESS
)
2641 TRACE("RQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
2642 SetLastError(dwError
);
2646 if (lpStatusPtr
->lpLockOwner
!= NULL
)
2648 lpStatusPtr
->lpLockOwner
=
2649 (LPWSTR
)((ULONG_PTR
)lpStatusPtr
+ (ULONG_PTR
)lpStatusPtr
->lpLockOwner
);
2652 TRACE("QueryServiceLockStatusW() done\n");
2658 /**********************************************************************
2659 * QueryServiceObjectSecurity
2664 QueryServiceObjectSecurity(SC_HANDLE hService
,
2665 SECURITY_INFORMATION dwSecurityInformation
,
2666 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
2668 LPDWORD pcbBytesNeeded
)
2672 TRACE("QueryServiceObjectSecurity(%p %lu %p)\n",
2673 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2677 dwError
= RQueryServiceObjectSecurity((SC_RPC_HANDLE
)hService
,
2678 dwSecurityInformation
,
2679 (LPBYTE
)lpSecurityDescriptor
,
2683 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2685 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2689 if (dwError
!= ERROR_SUCCESS
)
2691 TRACE("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2692 SetLastError(dwError
);
2700 /**********************************************************************
2701 * SetServiceObjectSecurity
2706 SetServiceObjectSecurity(SC_HANDLE hService
,
2707 SECURITY_INFORMATION dwSecurityInformation
,
2708 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
2710 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
2715 TRACE("SetServiceObjectSecurity(%p %lu %p)\n",
2716 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2719 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2722 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
2724 SetLastError(ERROR_INVALID_PARAMETER
);
2728 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
2729 if (SelfRelativeSD
== NULL
)
2731 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2735 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2738 if (!NT_SUCCESS(Status
))
2740 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2741 SetLastError(RtlNtStatusToDosError(Status
));
2747 dwError
= RSetServiceObjectSecurity((SC_RPC_HANDLE
)hService
,
2748 dwSecurityInformation
,
2749 (LPBYTE
)SelfRelativeSD
,
2752 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2754 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2758 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2760 if (dwError
!= ERROR_SUCCESS
)
2762 TRACE("RServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2763 SetLastError(dwError
);
2771 /**********************************************************************
2772 * QueryServiceStatus
2777 QueryServiceStatus(SC_HANDLE hService
,
2778 LPSERVICE_STATUS lpServiceStatus
)
2782 TRACE("QueryServiceStatus(%p %p)\n",
2783 hService
, lpServiceStatus
);
2787 SetLastError(ERROR_INVALID_HANDLE
);
2793 dwError
= RQueryServiceStatus((SC_RPC_HANDLE
)hService
,
2796 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2798 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2802 if (dwError
!= ERROR_SUCCESS
)
2804 TRACE("RQueryServiceStatus() failed (Error %lu)\n", dwError
);
2805 SetLastError(dwError
);
2813 /**********************************************************************
2814 * QueryServiceStatusEx
2819 QueryServiceStatusEx(SC_HANDLE hService
,
2820 SC_STATUS_TYPE InfoLevel
,
2823 LPDWORD pcbBytesNeeded
)
2827 TRACE("QueryServiceStatusEx(%p %lu %p %lu %p)\n",
2828 hService
, InfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2830 if (InfoLevel
!= SC_STATUS_PROCESS_INFO
)
2832 SetLastError(ERROR_INVALID_LEVEL
);
2836 if (cbBufSize
< sizeof(SERVICE_STATUS_PROCESS
))
2838 *pcbBytesNeeded
= sizeof(SERVICE_STATUS_PROCESS
);
2839 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2845 dwError
= RQueryServiceStatusEx((SC_RPC_HANDLE
)hService
,
2851 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2853 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2857 if (dwError
!= ERROR_SUCCESS
)
2859 TRACE("RQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
2860 SetLastError(dwError
);
2868 /**********************************************************************
2874 StartServiceA(SC_HANDLE hService
,
2875 DWORD dwNumServiceArgs
,
2876 LPCSTR
*lpServiceArgVectors
)
2880 TRACE("StartServiceA(%p %lu %p)\n",
2881 hService
, dwNumServiceArgs
, lpServiceArgVectors
);
2885 dwError
= RStartServiceA((SC_RPC_HANDLE
)hService
,
2887 (LPSTRING_PTRSA
)lpServiceArgVectors
);
2889 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2891 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2895 if (dwError
!= ERROR_SUCCESS
)
2897 ERR("RStartServiceA() failed (Error %lu)\n", dwError
);
2898 SetLastError(dwError
);
2906 /**********************************************************************
2912 StartServiceW(SC_HANDLE hService
,
2913 DWORD dwNumServiceArgs
,
2914 LPCWSTR
*lpServiceArgVectors
)
2918 TRACE("StartServiceW(%p %lu %p)\n",
2919 hService
, dwNumServiceArgs
, lpServiceArgVectors
);
2923 dwError
= RStartServiceW((SC_RPC_HANDLE
)hService
,
2925 (LPSTRING_PTRSW
)lpServiceArgVectors
);
2927 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2929 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2933 if (dwError
!= ERROR_SUCCESS
)
2935 ERR("RStartServiceW() failed (Error %lu)\n", dwError
);
2936 SetLastError(dwError
);
2944 /**********************************************************************
2945 * UnlockServiceDatabase
2950 UnlockServiceDatabase(SC_LOCK ScLock
)
2954 TRACE("UnlockServiceDatabase(%x)\n",
2959 dwError
= RUnlockServiceDatabase((LPSC_RPC_LOCK
)&ScLock
);
2961 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2963 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2967 if (dwError
== ERROR_INVALID_HANDLE
)
2968 dwError
= ERROR_INVALID_SERVICE_LOCK
;
2970 if (dwError
!= ERROR_SUCCESS
)
2972 TRACE("RUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2973 SetLastError(dwError
);
2981 /**********************************************************************
2982 * NotifyBootConfigStatus
2987 NotifyBootConfigStatus(BOOL BootAcceptable
)
2991 TRACE("NotifyBootConfigStatus(%u)\n",
2996 dwError
= RNotifyBootConfigStatus(NULL
,
2999 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
3001 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
3005 if (dwError
!= ERROR_SUCCESS
)
3007 TRACE("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
3008 SetLastError(dwError
);