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
);
1697 * NOTE: A size of 1 character would be enough, but tests show that
1698 * Windows returns 2 characters instead, certainly due to a WCHAR/bytes
1699 * mismatch in their code.
1701 if (!lpDisplayName
|| *lpcchBuffer
< sizeof(WCHAR
))
1703 lpNameBuffer
= szEmptyName
;
1704 *lpcchBuffer
= sizeof(WCHAR
);
1708 lpNameBuffer
= lpDisplayName
;
1713 dwError
= RGetServiceDisplayNameW((SC_RPC_HANDLE
)hSCManager
,
1718 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1720 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1724 if (dwError
!= ERROR_SUCCESS
)
1726 TRACE("RGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1727 SetLastError(dwError
);
1735 /**********************************************************************
1736 * GetServiceKeyNameA
1741 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1742 LPCSTR lpDisplayName
,
1743 LPSTR lpServiceName
,
1744 LPDWORD lpcchBuffer
)
1748 CHAR szEmptyName
[] = "";
1750 TRACE("GetServiceKeyNameA(%p %s %p %p)\n",
1751 hSCManager
, debugstr_a(lpDisplayName
), lpServiceName
, lpcchBuffer
);
1755 SetLastError(ERROR_INVALID_HANDLE
);
1759 if (!lpServiceName
|| *lpcchBuffer
< sizeof(CHAR
))
1761 lpNameBuffer
= szEmptyName
;
1762 *lpcchBuffer
= sizeof(CHAR
);
1766 lpNameBuffer
= lpServiceName
;
1771 dwError
= RGetServiceKeyNameA((SC_RPC_HANDLE
)hSCManager
,
1776 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1778 /* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
1779 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1783 if (dwError
!= ERROR_SUCCESS
)
1785 TRACE("RGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1786 SetLastError(dwError
);
1794 /**********************************************************************
1795 * GetServiceKeyNameW
1800 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1801 LPCWSTR lpDisplayName
,
1802 LPWSTR lpServiceName
,
1803 LPDWORD lpcchBuffer
)
1806 LPWSTR lpNameBuffer
;
1807 WCHAR szEmptyName
[] = L
"";
1809 TRACE("GetServiceKeyNameW(%p %s %p %p)\n",
1810 hSCManager
, debugstr_w(lpDisplayName
), lpServiceName
, lpcchBuffer
);
1814 SetLastError(ERROR_INVALID_HANDLE
);
1819 * NOTE: A size of 1 character would be enough, but tests show that
1820 * Windows returns 2 characters instead, certainly due to a WCHAR/bytes
1821 * mismatch in their code.
1823 if (!lpServiceName
|| *lpcchBuffer
< sizeof(WCHAR
))
1825 lpNameBuffer
= szEmptyName
;
1826 *lpcchBuffer
= sizeof(WCHAR
);
1830 lpNameBuffer
= lpServiceName
;
1835 dwError
= RGetServiceKeyNameW((SC_RPC_HANDLE
)hSCManager
,
1840 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1842 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1846 if (dwError
!= ERROR_SUCCESS
)
1848 TRACE("RGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1849 SetLastError(dwError
);
1857 /**********************************************************************
1858 * I_ScGetCurrentGroupStateW
1863 I_ScGetCurrentGroupStateW(SC_HANDLE hSCManager
,
1864 LPWSTR pszGroupName
,
1865 LPDWORD pdwGroupState
)
1869 TRACE("I_ScGetCurrentGroupStateW(%p %s %p)\n",
1870 hSCManager
, debugstr_w(pszGroupName
), pdwGroupState
);
1874 dwError
= RI_ScGetCurrentGroupStateW((SC_RPC_HANDLE
)hSCManager
,
1878 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1880 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1884 if (dwError
!= ERROR_SUCCESS
)
1886 TRACE("RI_ScGetCurrentGroupStateW() failed (Error %lu)\n", dwError
);
1887 SetLastError(dwError
);
1894 /**********************************************************************
1895 * LockServiceDatabase
1900 LockServiceDatabase(SC_HANDLE hSCManager
)
1905 TRACE("LockServiceDatabase(%p)\n",
1910 dwError
= RLockServiceDatabase((SC_RPC_HANDLE
)hSCManager
,
1911 (SC_RPC_LOCK
*)&hLock
);
1913 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1915 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1919 if (dwError
!= ERROR_SUCCESS
)
1921 TRACE("RLockServiceDatabase() failed (Error %lu)\n", dwError
);
1922 SetLastError(dwError
);
1926 TRACE("hLock = %p\n", hLock
);
1933 WaitForSCManager(VOID
)
1937 TRACE("WaitForSCManager()\n");
1939 /* Try to open the existing event */
1940 hEvent
= OpenEventW(SYNCHRONIZE
, FALSE
, SCM_START_EVENT
);
1943 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1946 /* Try to create a new event */
1947 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, SCM_START_EVENT
);
1952 /* Wait for 3 minutes */
1953 WaitForSingleObject(hEvent
, 180000);
1954 CloseHandle(hEvent
);
1956 TRACE("ScmWaitForSCManager() done\n");
1960 /**********************************************************************
1966 OpenSCManagerA(LPCSTR lpMachineName
,
1967 LPCSTR lpDatabaseName
,
1968 DWORD dwDesiredAccess
)
1970 SC_HANDLE hScm
= NULL
;
1973 TRACE("OpenSCManagerA(%s %s %lx)\n",
1974 debugstr_a(lpMachineName
), debugstr_a(lpDatabaseName
), dwDesiredAccess
);
1980 dwError
= ROpenSCManagerA((LPSTR
)lpMachineName
,
1981 (LPSTR
)lpDatabaseName
,
1983 (SC_RPC_HANDLE
*)&hScm
);
1985 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1987 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1991 if (dwError
!= ERROR_SUCCESS
)
1993 TRACE("ROpenSCManagerA() failed (Error %lu)\n", dwError
);
1994 SetLastError(dwError
);
1998 TRACE("hScm = %p\n", hScm
);
2004 /**********************************************************************
2010 OpenSCManagerW(LPCWSTR lpMachineName
,
2011 LPCWSTR lpDatabaseName
,
2012 DWORD dwDesiredAccess
)
2014 SC_HANDLE hScm
= NULL
;
2017 TRACE("OpenSCManagerW(%s %s %lx)\n",
2018 debugstr_w(lpMachineName
), debugstr_w(lpDatabaseName
), dwDesiredAccess
);
2024 dwError
= ROpenSCManagerW((LPWSTR
)lpMachineName
,
2025 (LPWSTR
)lpDatabaseName
,
2027 (SC_RPC_HANDLE
*)&hScm
);
2029 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2031 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2035 if (dwError
!= ERROR_SUCCESS
)
2037 TRACE("ROpenSCManagerW() failed (Error %lu)\n", dwError
);
2038 SetLastError(dwError
);
2042 TRACE("hScm = %p\n", hScm
);
2048 /**********************************************************************
2054 OpenServiceA(SC_HANDLE hSCManager
,
2055 LPCSTR lpServiceName
,
2056 DWORD dwDesiredAccess
)
2058 SC_HANDLE hService
= NULL
;
2061 TRACE("OpenServiceA(%p %s %lx)\n",
2062 hSCManager
, debugstr_a(lpServiceName
), dwDesiredAccess
);
2066 SetLastError(ERROR_INVALID_HANDLE
);
2072 dwError
= ROpenServiceA((SC_RPC_HANDLE
)hSCManager
,
2073 (LPSTR
)lpServiceName
,
2075 (SC_RPC_HANDLE
*)&hService
);
2077 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2079 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2083 SetLastError(dwError
);
2084 if (dwError
!= ERROR_SUCCESS
)
2086 TRACE("ROpenServiceA() failed (Error %lu)\n", dwError
);
2090 TRACE("hService = %p\n", hService
);
2096 /**********************************************************************
2102 OpenServiceW(SC_HANDLE hSCManager
,
2103 LPCWSTR lpServiceName
,
2104 DWORD dwDesiredAccess
)
2106 SC_HANDLE hService
= NULL
;
2109 TRACE("OpenServiceW(%p %s %lx)\n",
2110 hSCManager
, debugstr_w(lpServiceName
), dwDesiredAccess
);
2114 SetLastError(ERROR_INVALID_HANDLE
);
2120 dwError
= ROpenServiceW((SC_RPC_HANDLE
)hSCManager
,
2121 (LPWSTR
)lpServiceName
,
2123 (SC_RPC_HANDLE
*)&hService
);
2125 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2127 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2131 SetLastError(dwError
);
2132 if (dwError
!= ERROR_SUCCESS
)
2134 TRACE("ROpenServiceW() failed (Error %lu)\n", dwError
);
2138 TRACE("hService = %p\n", hService
);
2144 /**********************************************************************
2145 * QueryServiceConfigA
2150 QueryServiceConfigA(SC_HANDLE hService
,
2151 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
2153 LPDWORD pcbBytesNeeded
)
2155 QUERY_SERVICE_CONFIGA ServiceConfig
;
2156 LPQUERY_SERVICE_CONFIGA lpConfigPtr
;
2160 TRACE("QueryServiceConfigA(%p %p %lu %p)\n",
2161 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
2163 if (lpServiceConfig
== NULL
||
2164 cbBufSize
< sizeof(QUERY_SERVICE_CONFIGA
))
2166 lpConfigPtr
= &ServiceConfig
;
2167 dwBufferSize
= sizeof(QUERY_SERVICE_CONFIGA
);
2171 lpConfigPtr
= lpServiceConfig
;
2172 dwBufferSize
= cbBufSize
;
2177 dwError
= RQueryServiceConfigA((SC_RPC_HANDLE
)hService
,
2178 (LPBYTE
)lpConfigPtr
,
2182 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2184 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2188 if (dwError
!= ERROR_SUCCESS
)
2190 TRACE("RQueryServiceConfigA() failed (Error %lu)\n", dwError
);
2191 SetLastError(dwError
);
2195 /* Adjust the pointers */
2196 if (lpConfigPtr
->lpBinaryPathName
)
2197 lpConfigPtr
->lpBinaryPathName
=
2198 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2199 (ULONG_PTR
)lpConfigPtr
->lpBinaryPathName
);
2201 if (lpConfigPtr
->lpLoadOrderGroup
)
2202 lpConfigPtr
->lpLoadOrderGroup
=
2203 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2204 (ULONG_PTR
)lpConfigPtr
->lpLoadOrderGroup
);
2206 if (lpConfigPtr
->lpDependencies
)
2207 lpConfigPtr
->lpDependencies
=
2208 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2209 (ULONG_PTR
)lpConfigPtr
->lpDependencies
);
2211 if (lpConfigPtr
->lpServiceStartName
)
2212 lpConfigPtr
->lpServiceStartName
=
2213 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2214 (ULONG_PTR
)lpConfigPtr
->lpServiceStartName
);
2216 if (lpConfigPtr
->lpDisplayName
)
2217 lpConfigPtr
->lpDisplayName
=
2218 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2219 (ULONG_PTR
)lpConfigPtr
->lpDisplayName
);
2221 TRACE("QueryServiceConfigA() done\n");
2227 /**********************************************************************
2228 * QueryServiceConfigW
2233 QueryServiceConfigW(SC_HANDLE hService
,
2234 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
2236 LPDWORD pcbBytesNeeded
)
2238 QUERY_SERVICE_CONFIGW ServiceConfig
;
2239 LPQUERY_SERVICE_CONFIGW lpConfigPtr
;
2243 TRACE("QueryServiceConfigW(%p %p %lu %p)\n",
2244 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
2246 if (lpServiceConfig
== NULL
||
2247 cbBufSize
< sizeof(QUERY_SERVICE_CONFIGW
))
2249 lpConfigPtr
= &ServiceConfig
;
2250 dwBufferSize
= sizeof(QUERY_SERVICE_CONFIGW
);
2254 lpConfigPtr
= lpServiceConfig
;
2255 dwBufferSize
= cbBufSize
;
2260 dwError
= RQueryServiceConfigW((SC_RPC_HANDLE
)hService
,
2261 (LPBYTE
)lpConfigPtr
,
2265 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2267 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2271 if (dwError
!= ERROR_SUCCESS
)
2273 TRACE("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
2274 SetLastError(dwError
);
2278 /* Adjust the pointers */
2279 if (lpConfigPtr
->lpBinaryPathName
)
2280 lpConfigPtr
->lpBinaryPathName
=
2281 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2282 (ULONG_PTR
)lpConfigPtr
->lpBinaryPathName
);
2284 if (lpConfigPtr
->lpLoadOrderGroup
)
2285 lpConfigPtr
->lpLoadOrderGroup
=
2286 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2287 (ULONG_PTR
)lpConfigPtr
->lpLoadOrderGroup
);
2289 if (lpConfigPtr
->lpDependencies
)
2290 lpConfigPtr
->lpDependencies
=
2291 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2292 (ULONG_PTR
)lpConfigPtr
->lpDependencies
);
2294 if (lpConfigPtr
->lpServiceStartName
)
2295 lpConfigPtr
->lpServiceStartName
=
2296 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2297 (ULONG_PTR
)lpConfigPtr
->lpServiceStartName
);
2299 if (lpConfigPtr
->lpDisplayName
)
2300 lpConfigPtr
->lpDisplayName
=
2301 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2302 (ULONG_PTR
)lpConfigPtr
->lpDisplayName
);
2304 TRACE("QueryServiceConfigW() done\n");
2310 /**********************************************************************
2311 * QueryServiceConfig2A
2316 QueryServiceConfig2A(SC_HANDLE hService
,
2320 LPDWORD pcbBytesNeeded
)
2322 SERVICE_DESCRIPTIONA ServiceDescription
;
2323 SERVICE_FAILURE_ACTIONSA ServiceFailureActions
;
2324 LPBYTE lpTempBuffer
;
2325 BOOL bUseTempBuffer
= FALSE
;
2329 TRACE("QueryServiceConfig2A(%p %lu %p %lu %p)\n",
2330 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2332 lpTempBuffer
= lpBuffer
;
2333 dwBufferSize
= cbBufSize
;
2335 switch (dwInfoLevel
)
2337 case SERVICE_CONFIG_DESCRIPTION
:
2338 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_DESCRIPTIONA
)))
2340 lpTempBuffer
= (LPBYTE
)&ServiceDescription
;
2341 dwBufferSize
= sizeof(SERVICE_DESCRIPTIONA
);
2342 bUseTempBuffer
= TRUE
;
2346 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2347 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_FAILURE_ACTIONSA
)))
2349 lpTempBuffer
= (LPBYTE
)&ServiceFailureActions
;
2350 dwBufferSize
= sizeof(SERVICE_FAILURE_ACTIONSA
);
2351 bUseTempBuffer
= TRUE
;
2356 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
2357 SetLastError(ERROR_INVALID_LEVEL
);
2363 dwError
= RQueryServiceConfig2A((SC_RPC_HANDLE
)hService
,
2369 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2371 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2375 if (dwError
!= ERROR_SUCCESS
)
2377 TRACE("RQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
2378 SetLastError(dwError
);
2382 if (bUseTempBuffer
!= FALSE
)
2384 TRACE("RQueryServiceConfig2A() returns ERROR_INSUFFICIENT_BUFFER\n");
2385 *pcbBytesNeeded
= dwBufferSize
;
2386 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2390 switch (dwInfoLevel
)
2392 case SERVICE_CONFIG_DESCRIPTION
:
2394 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpTempBuffer
;
2396 if (lpPtr
->lpDescription
!= NULL
)
2397 lpPtr
->lpDescription
=
2398 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpDescription
);
2402 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2404 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpTempBuffer
;
2406 if (lpPtr
->lpRebootMsg
!= NULL
)
2407 lpPtr
->lpRebootMsg
=
2408 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpRebootMsg
);
2410 if (lpPtr
->lpCommand
!= NULL
)
2412 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpCommand
);
2414 if (lpPtr
->lpsaActions
!= NULL
)
2415 lpPtr
->lpsaActions
=
2416 (LPSC_ACTION
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpsaActions
);
2421 TRACE("QueryServiceConfig2A() done\n");
2427 /**********************************************************************
2428 * QueryServiceConfig2W
2433 QueryServiceConfig2W(SC_HANDLE hService
,
2437 LPDWORD pcbBytesNeeded
)
2439 SERVICE_DESCRIPTIONW ServiceDescription
;
2440 SERVICE_FAILURE_ACTIONSW ServiceFailureActions
;
2441 LPBYTE lpTempBuffer
;
2442 BOOL bUseTempBuffer
= FALSE
;
2446 TRACE("QueryServiceConfig2W(%p %lu %p %lu %p)\n",
2447 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2449 lpTempBuffer
= lpBuffer
;
2450 dwBufferSize
= cbBufSize
;
2452 switch (dwInfoLevel
)
2454 case SERVICE_CONFIG_DESCRIPTION
:
2455 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_DESCRIPTIONW
)))
2457 lpTempBuffer
= (LPBYTE
)&ServiceDescription
;
2458 dwBufferSize
= sizeof(SERVICE_DESCRIPTIONW
);
2459 bUseTempBuffer
= TRUE
;
2463 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2464 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_FAILURE_ACTIONSW
)))
2466 lpTempBuffer
= (LPBYTE
)&ServiceFailureActions
;
2467 dwBufferSize
= sizeof(SERVICE_FAILURE_ACTIONSW
);
2468 bUseTempBuffer
= TRUE
;
2473 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
2474 SetLastError(ERROR_INVALID_LEVEL
);
2480 dwError
= RQueryServiceConfig2W((SC_RPC_HANDLE
)hService
,
2486 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2488 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2492 if (dwError
!= ERROR_SUCCESS
)
2494 TRACE("RQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
2495 SetLastError(dwError
);
2499 if (bUseTempBuffer
!= FALSE
)
2501 TRACE("RQueryServiceConfig2W() returns ERROR_INSUFFICIENT_BUFFER\n");
2502 *pcbBytesNeeded
= dwBufferSize
;
2503 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2507 switch (dwInfoLevel
)
2509 case SERVICE_CONFIG_DESCRIPTION
:
2511 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpTempBuffer
;
2513 if (lpPtr
->lpDescription
!= NULL
)
2514 lpPtr
->lpDescription
=
2515 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpDescription
);
2519 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2521 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpTempBuffer
;
2523 if (lpPtr
->lpRebootMsg
!= NULL
)
2524 lpPtr
->lpRebootMsg
=
2525 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpRebootMsg
);
2527 if (lpPtr
->lpCommand
!= NULL
)
2529 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpCommand
);
2531 if (lpPtr
->lpsaActions
!= NULL
)
2532 lpPtr
->lpsaActions
=
2533 (LPSC_ACTION
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpsaActions
);
2538 TRACE("QueryServiceConfig2W() done\n");
2544 /**********************************************************************
2545 * QueryServiceLockStatusA
2550 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
2551 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
2553 LPDWORD pcbBytesNeeded
)
2555 QUERY_SERVICE_LOCK_STATUSA LockStatus
;
2556 LPQUERY_SERVICE_LOCK_STATUSA lpStatusPtr
;
2560 TRACE("QueryServiceLockStatusA(%p %p %lu %p)\n",
2561 hSCManager
, lpLockStatus
, cbBufSize
, pcbBytesNeeded
);
2563 if (lpLockStatus
== NULL
|| cbBufSize
< sizeof(QUERY_SERVICE_LOCK_STATUSA
))
2565 lpStatusPtr
= &LockStatus
;
2566 dwBufferSize
= sizeof(QUERY_SERVICE_LOCK_STATUSA
);
2570 lpStatusPtr
= lpLockStatus
;
2571 dwBufferSize
= cbBufSize
;
2576 dwError
= RQueryServiceLockStatusA((SC_RPC_HANDLE
)hSCManager
,
2577 (LPBYTE
)lpStatusPtr
,
2581 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2583 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2587 if (dwError
!= ERROR_SUCCESS
)
2589 TRACE("RQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
2590 SetLastError(dwError
);
2594 if (lpStatusPtr
->lpLockOwner
!= NULL
)
2596 lpStatusPtr
->lpLockOwner
=
2597 (LPSTR
)((ULONG_PTR
)lpStatusPtr
+ (ULONG_PTR
)lpStatusPtr
->lpLockOwner
);
2600 TRACE("QueryServiceLockStatusA() done\n");
2606 /**********************************************************************
2607 * QueryServiceLockStatusW
2612 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
2613 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
2615 LPDWORD pcbBytesNeeded
)
2617 QUERY_SERVICE_LOCK_STATUSW LockStatus
;
2618 LPQUERY_SERVICE_LOCK_STATUSW lpStatusPtr
;
2622 TRACE("QueryServiceLockStatusW(%p %p %lu %p)\n",
2623 hSCManager
, lpLockStatus
, cbBufSize
, pcbBytesNeeded
);
2625 if (lpLockStatus
== NULL
|| cbBufSize
< sizeof(QUERY_SERVICE_LOCK_STATUSW
))
2627 lpStatusPtr
= &LockStatus
;
2628 dwBufferSize
= sizeof(QUERY_SERVICE_LOCK_STATUSW
);
2632 lpStatusPtr
= lpLockStatus
;
2633 dwBufferSize
= cbBufSize
;
2638 dwError
= RQueryServiceLockStatusW((SC_RPC_HANDLE
)hSCManager
,
2639 (LPBYTE
)lpStatusPtr
,
2643 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2645 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2649 if (dwError
!= ERROR_SUCCESS
)
2651 TRACE("RQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
2652 SetLastError(dwError
);
2656 if (lpStatusPtr
->lpLockOwner
!= NULL
)
2658 lpStatusPtr
->lpLockOwner
=
2659 (LPWSTR
)((ULONG_PTR
)lpStatusPtr
+ (ULONG_PTR
)lpStatusPtr
->lpLockOwner
);
2662 TRACE("QueryServiceLockStatusW() done\n");
2668 /**********************************************************************
2669 * QueryServiceObjectSecurity
2674 QueryServiceObjectSecurity(SC_HANDLE hService
,
2675 SECURITY_INFORMATION dwSecurityInformation
,
2676 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
2678 LPDWORD pcbBytesNeeded
)
2682 TRACE("QueryServiceObjectSecurity(%p %lu %p)\n",
2683 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2687 dwError
= RQueryServiceObjectSecurity((SC_RPC_HANDLE
)hService
,
2688 dwSecurityInformation
,
2689 (LPBYTE
)lpSecurityDescriptor
,
2693 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2695 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2699 if (dwError
!= ERROR_SUCCESS
)
2701 TRACE("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2702 SetLastError(dwError
);
2710 /**********************************************************************
2711 * SetServiceObjectSecurity
2716 SetServiceObjectSecurity(SC_HANDLE hService
,
2717 SECURITY_INFORMATION dwSecurityInformation
,
2718 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
2720 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
2725 TRACE("SetServiceObjectSecurity(%p %lu %p)\n",
2726 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2729 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2732 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
2734 SetLastError(ERROR_INVALID_PARAMETER
);
2738 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
2739 if (SelfRelativeSD
== NULL
)
2741 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2745 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2748 if (!NT_SUCCESS(Status
))
2750 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2751 SetLastError(RtlNtStatusToDosError(Status
));
2757 dwError
= RSetServiceObjectSecurity((SC_RPC_HANDLE
)hService
,
2758 dwSecurityInformation
,
2759 (LPBYTE
)SelfRelativeSD
,
2762 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2764 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2768 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2770 if (dwError
!= ERROR_SUCCESS
)
2772 TRACE("RServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2773 SetLastError(dwError
);
2781 /**********************************************************************
2782 * QueryServiceStatus
2787 QueryServiceStatus(SC_HANDLE hService
,
2788 LPSERVICE_STATUS lpServiceStatus
)
2792 TRACE("QueryServiceStatus(%p %p)\n",
2793 hService
, lpServiceStatus
);
2797 SetLastError(ERROR_INVALID_HANDLE
);
2803 dwError
= RQueryServiceStatus((SC_RPC_HANDLE
)hService
,
2806 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2808 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2812 if (dwError
!= ERROR_SUCCESS
)
2814 TRACE("RQueryServiceStatus() failed (Error %lu)\n", dwError
);
2815 SetLastError(dwError
);
2823 /**********************************************************************
2824 * QueryServiceStatusEx
2829 QueryServiceStatusEx(SC_HANDLE hService
,
2830 SC_STATUS_TYPE InfoLevel
,
2833 LPDWORD pcbBytesNeeded
)
2837 TRACE("QueryServiceStatusEx(%p %lu %p %lu %p)\n",
2838 hService
, InfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2840 if (InfoLevel
!= SC_STATUS_PROCESS_INFO
)
2842 SetLastError(ERROR_INVALID_LEVEL
);
2846 if (cbBufSize
< sizeof(SERVICE_STATUS_PROCESS
))
2848 *pcbBytesNeeded
= sizeof(SERVICE_STATUS_PROCESS
);
2849 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2855 dwError
= RQueryServiceStatusEx((SC_RPC_HANDLE
)hService
,
2861 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2863 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2867 if (dwError
!= ERROR_SUCCESS
)
2869 TRACE("RQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
2870 SetLastError(dwError
);
2878 /**********************************************************************
2884 StartServiceA(SC_HANDLE hService
,
2885 DWORD dwNumServiceArgs
,
2886 LPCSTR
*lpServiceArgVectors
)
2890 TRACE("StartServiceA(%p %lu %p)\n",
2891 hService
, dwNumServiceArgs
, lpServiceArgVectors
);
2895 dwError
= RStartServiceA((SC_RPC_HANDLE
)hService
,
2897 (LPSTRING_PTRSA
)lpServiceArgVectors
);
2899 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2901 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2905 if (dwError
!= ERROR_SUCCESS
)
2907 ERR("RStartServiceA() failed (Error %lu)\n", dwError
);
2908 SetLastError(dwError
);
2916 /**********************************************************************
2922 StartServiceW(SC_HANDLE hService
,
2923 DWORD dwNumServiceArgs
,
2924 LPCWSTR
*lpServiceArgVectors
)
2928 TRACE("StartServiceW(%p %lu %p)\n",
2929 hService
, dwNumServiceArgs
, lpServiceArgVectors
);
2933 dwError
= RStartServiceW((SC_RPC_HANDLE
)hService
,
2935 (LPSTRING_PTRSW
)lpServiceArgVectors
);
2937 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2939 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2943 if (dwError
!= ERROR_SUCCESS
)
2945 ERR("RStartServiceW() failed (Error %lu)\n", dwError
);
2946 SetLastError(dwError
);
2954 /**********************************************************************
2955 * UnlockServiceDatabase
2960 UnlockServiceDatabase(SC_LOCK ScLock
)
2964 TRACE("UnlockServiceDatabase(%x)\n",
2969 dwError
= RUnlockServiceDatabase((LPSC_RPC_LOCK
)&ScLock
);
2971 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2973 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2977 if (dwError
== ERROR_INVALID_HANDLE
)
2978 dwError
= ERROR_INVALID_SERVICE_LOCK
;
2980 if (dwError
!= ERROR_SUCCESS
)
2982 TRACE("RUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2983 SetLastError(dwError
);
2991 /**********************************************************************
2992 * NotifyBootConfigStatus
2997 NotifyBootConfigStatus(BOOL BootAcceptable
)
3001 TRACE("NotifyBootConfigStatus(%u)\n",
3006 dwError
= RNotifyBootConfigStatus(NULL
,
3009 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
3011 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
3015 if (dwError
!= ERROR_SUCCESS
)
3017 TRACE("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
3018 SetLastError(dwError
);