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
13 /* INCLUDES ******************************************************************/
17 #include "wine/debug.h"
19 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
22 /* FUNCTIONS *****************************************************************/
24 handle_t BindingHandle
= NULL
;
29 LPWSTR pszStringBinding
;
32 if (BindingHandle
!= NULL
)
35 status
= RpcStringBindingComposeW(NULL
,
43 TRACE("RpcStringBindingCompose returned 0x%x\n", status
);
47 /* Set the binding handle that will be used to bind to the server. */
48 status
= RpcBindingFromStringBindingW(pszStringBinding
,
52 TRACE("RpcBindingFromStringBinding returned 0x%x\n", status
);
55 status
= RpcStringFreeW(&pszStringBinding
);
58 TRACE("RpcStringFree returned 0x%x\n", status
);
69 if (BindingHandle
== NULL
)
72 status
= RpcBindingFree(&BindingHandle
);
75 TRACE("RpcBindingFree returned 0x%x\n", status
);
82 ScmRpcStatusToWinError(RPC_STATUS Status
)
86 case RPC_X_SS_IN_NULL_CONTEXT
:
87 return ERROR_INVALID_HANDLE
;
89 case RPC_X_NULL_REF_POINTER
:
90 return ERROR_INVALID_PARAMETER
;
92 case STATUS_ACCESS_VIOLATION
:
93 return ERROR_INVALID_ADDRESS
;
101 /**********************************************************************
102 * ChangeServiceConfig2A
107 ChangeServiceConfig2A(SC_HANDLE hService
,
111 SC_RPC_CONFIG_INFOA Info
;
114 TRACE("ChangeServiceConfig2A() called\n");
116 /* Fill relevent field of the Info structure */
117 Info
.dwInfoLevel
= dwInfoLevel
;
120 case SERVICE_CONFIG_DESCRIPTION
:
121 Info
.psd
= (LPSERVICE_DESCRIPTIONA
)&lpInfo
;
124 case SERVICE_CONFIG_FAILURE_ACTIONS
:
125 Info
.psfa
= (LPSERVICE_FAILURE_ACTIONSA
)&lpInfo
;
129 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
130 SetLastError(ERROR_INVALID_PARAMETER
);
141 dwError
= RChangeServiceConfig2A(BindingHandle
,
142 (SC_RPC_HANDLE
)hService
,
147 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
151 if (dwError
!= ERROR_SUCCESS
)
153 ERR("RChangeServiceConfig2A() failed (Error %lu)\n", dwError
);
154 SetLastError(dwError
);
162 /**********************************************************************
163 * ChangeServiceConfig2W
168 ChangeServiceConfig2W(SC_HANDLE hService
,
172 SC_RPC_CONFIG_INFOW Info
;
175 TRACE("ChangeServiceConfig2W() called\n");
177 /* Fill relevent field of the Info structure */
178 Info
.dwInfoLevel
= dwInfoLevel
;
181 case SERVICE_CONFIG_DESCRIPTION
:
183 Info
.psd
= (LPSERVICE_DESCRIPTIONW
)&lpInfo
;
187 case SERVICE_CONFIG_FAILURE_ACTIONS
:
188 Info
.psfa
= (LPSERVICE_FAILURE_ACTIONSW
)&lpInfo
;
192 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
193 SetLastError(ERROR_INVALID_PARAMETER
);
204 dwError
= RChangeServiceConfig2W(BindingHandle
,
205 (SC_RPC_HANDLE
)hService
,
210 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
214 if (dwError
!= ERROR_SUCCESS
)
216 ERR("RChangeServiceConfig2W() failed (Error %lu)\n", dwError
);
217 SetLastError(dwError
);
225 /**********************************************************************
226 * ChangeServiceConfigA
231 ChangeServiceConfigA(SC_HANDLE hService
,
234 DWORD dwErrorControl
,
235 LPCSTR lpBinaryPathName
,
236 LPCSTR lpLoadOrderGroup
,
238 LPCSTR lpDependencies
,
239 LPCSTR lpServiceStartName
,
241 LPCSTR lpDisplayName
)
244 DWORD dwDependenciesLength
= 0;
248 TRACE("ChangeServiceConfigA() called\n");
250 /* Calculate the Dependencies length*/
251 if (lpDependencies
!= NULL
)
253 lpStr
= (LPSTR
)lpDependencies
;
256 dwLength
= strlen(lpStr
) + 1;
257 dwDependenciesLength
+= dwLength
;
258 lpStr
= lpStr
+ dwLength
;
260 dwDependenciesLength
++;
263 /* FIXME: Encrypt the password */
269 /* Call to services.exe using RPC */
270 dwError
= RChangeServiceConfigA(BindingHandle
,
271 (SC_RPC_HANDLE
)hService
,
275 (LPSTR
)lpBinaryPathName
,
276 (LPSTR
)lpLoadOrderGroup
,
278 (LPSTR
)lpDependencies
,
279 dwDependenciesLength
,
280 (LPSTR
)lpServiceStartName
,
281 NULL
, /* FIXME: lpPassword */
282 0, /* FIXME: dwPasswordLength */
283 (LPSTR
)lpDisplayName
);
287 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
291 if (dwError
!= ERROR_SUCCESS
)
293 ERR("RChangeServiceConfigA() failed (Error %lu)\n", dwError
);
294 SetLastError(dwError
);
302 /**********************************************************************
303 * ChangeServiceConfigW
308 ChangeServiceConfigW(SC_HANDLE hService
,
311 DWORD dwErrorControl
,
312 LPCWSTR lpBinaryPathName
,
313 LPCWSTR lpLoadOrderGroup
,
315 LPCWSTR lpDependencies
,
316 LPCWSTR lpServiceStartName
,
318 LPCWSTR lpDisplayName
)
321 DWORD dwDependenciesLength
= 0;
325 TRACE("ChangeServiceConfigW() called\n");
327 /* Calculate the Dependencies length*/
328 if (lpDependencies
!= NULL
)
330 lpStr
= (LPWSTR
)lpDependencies
;
333 dwLength
= wcslen(lpStr
) + 1;
334 dwDependenciesLength
+= dwLength
;
335 lpStr
= lpStr
+ dwLength
;
337 dwDependenciesLength
++;
340 /* FIXME: Encrypt the password */
346 /* Call to services.exe using RPC */
347 dwError
= RChangeServiceConfigW(BindingHandle
,
348 (SC_RPC_HANDLE
)hService
,
352 (LPWSTR
)lpBinaryPathName
,
353 (LPWSTR
)lpLoadOrderGroup
,
355 (LPBYTE
)lpDependencies
,
356 dwDependenciesLength
,
357 (LPWSTR
)lpServiceStartName
,
358 NULL
, /* FIXME: lpPassword */
359 0, /* FIXME: dwPasswordLength */
360 (LPWSTR
)lpDisplayName
);
364 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
368 if (dwError
!= ERROR_SUCCESS
)
370 ERR("RChangeServiceConfigW() failed (Error %lu)\n", dwError
);
371 SetLastError(dwError
);
379 /**********************************************************************
385 CloseServiceHandle(SC_HANDLE hSCObject
)
389 TRACE("CloseServiceHandle() called\n");
395 /* Call to services.exe using RPC */
396 dwError
= RCloseServiceHandle(BindingHandle
,
397 (LPSC_RPC_HANDLE
)&hSCObject
);
401 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
407 ERR("RCloseServiceHandle() failed (Error %lu)\n", dwError
);
408 SetLastError(dwError
);
412 TRACE("CloseServiceHandle() done\n");
418 /**********************************************************************
424 ControlService(SC_HANDLE hService
,
426 LPSERVICE_STATUS lpServiceStatus
)
430 TRACE("ControlService(%x, %x, %p)\n",
431 hService
, dwControl
, lpServiceStatus
);
437 /* Call to services.exe using RPC */
438 dwError
= RControlService(BindingHandle
,
439 (SC_RPC_HANDLE
)hService
,
445 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
449 if (dwError
!= ERROR_SUCCESS
)
451 ERR("RControlService() failed (Error %lu)\n", dwError
);
452 SetLastError(dwError
);
456 TRACE("ControlService() done\n");
462 /**********************************************************************
468 ControlServiceEx(IN SC_HANDLE hService
,
470 IN DWORD dwInfoLevel
,
471 IN OUT PVOID pControlParams
)
473 FIXME("ControlServiceEx(0x%p, 0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n",
474 hService
, dwControl
, dwInfoLevel
, pControlParams
);
475 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
480 /**********************************************************************
486 CreateServiceA(SC_HANDLE hSCManager
,
487 LPCSTR lpServiceName
,
488 LPCSTR lpDisplayName
,
489 DWORD dwDesiredAccess
,
492 DWORD dwErrorControl
,
493 LPCSTR lpBinaryPathName
,
494 LPCSTR lpLoadOrderGroup
,
496 LPCSTR lpDependencies
,
497 LPCSTR lpServiceStartName
,
500 SC_HANDLE RetVal
= NULL
;
501 LPWSTR lpServiceNameW
= NULL
;
502 LPWSTR lpDisplayNameW
= NULL
;
503 LPWSTR lpBinaryPathNameW
= NULL
;
504 LPWSTR lpLoadOrderGroupW
= NULL
;
505 LPWSTR lpDependenciesW
= NULL
;
506 LPWSTR lpServiceStartNameW
= NULL
;
507 LPWSTR lpPasswordW
= NULL
;
508 DWORD dwDependenciesLength
= 0;
515 len
= MultiByteToWideChar(CP_ACP
, 0, lpServiceName
, -1, NULL
, 0);
516 lpServiceNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
519 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
522 MultiByteToWideChar(CP_ACP
, 0, lpServiceName
, -1, lpServiceNameW
, len
);
527 len
= MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, NULL
, 0);
528 lpDisplayNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
531 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
534 MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, lpDisplayNameW
, len
);
537 if (lpBinaryPathName
)
539 len
= MultiByteToWideChar(CP_ACP
, 0, lpBinaryPathName
, -1, NULL
, 0);
540 lpBinaryPathNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
541 if (!lpBinaryPathNameW
)
543 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
546 MultiByteToWideChar(CP_ACP
, 0, lpBinaryPathName
, -1, lpBinaryPathNameW
, len
);
549 if (lpLoadOrderGroup
)
551 len
= MultiByteToWideChar(CP_ACP
, 0, lpLoadOrderGroup
, -1, NULL
, 0);
552 lpLoadOrderGroupW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
553 if (!lpLoadOrderGroupW
)
555 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
558 MultiByteToWideChar(CP_ACP
, 0, lpLoadOrderGroup
, -1, lpLoadOrderGroupW
, len
);
563 lpStr
= (LPSTR
)lpDependencies
;
566 dwLength
= strlen(lpStr
) + 1;
567 dwDependenciesLength
+= dwLength
;
568 lpStr
= lpStr
+ dwLength
;
570 dwDependenciesLength
++;
572 lpDependenciesW
= HeapAlloc(GetProcessHeap(), 0, dwDependenciesLength
* sizeof(WCHAR
));
573 if (!lpDependenciesW
)
575 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
578 MultiByteToWideChar(CP_ACP
, 0, lpDependencies
, dwDependenciesLength
, lpDependenciesW
, dwDependenciesLength
);
581 if (lpServiceStartName
)
583 len
= MultiByteToWideChar(CP_ACP
, 0, lpServiceStartName
, -1, NULL
, 0);
584 lpServiceStartNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
585 if (!lpServiceStartNameW
)
587 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
590 MultiByteToWideChar(CP_ACP
, 0, lpServiceStartName
, -1, lpServiceStartNameW
, len
);
595 len
= MultiByteToWideChar(CP_ACP
, 0, lpPassword
, -1, NULL
, 0);
596 lpPasswordW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
599 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
602 MultiByteToWideChar(CP_ACP
, 0, lpPassword
, -1, lpPasswordW
, len
);
605 RetVal
= CreateServiceW(hSCManager
,
620 if (lpServiceNameW
!=NULL
)
621 HeapFree(GetProcessHeap(), 0, lpServiceNameW
);
623 if (lpDisplayNameW
!= NULL
)
624 HeapFree(GetProcessHeap(), 0, lpDisplayNameW
);
626 if (lpBinaryPathNameW
!= NULL
)
627 HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW
);
629 if (lpLoadOrderGroupW
!= NULL
)
630 HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW
);
632 if (lpDependenciesW
!= NULL
)
633 HeapFree(GetProcessHeap(), 0, lpDependenciesW
);
635 if (lpServiceStartNameW
!= NULL
)
636 HeapFree(GetProcessHeap(), 0, lpServiceStartNameW
);
638 if (lpPasswordW
!= NULL
)
639 HeapFree(GetProcessHeap(), 0, lpPasswordW
);
645 /**********************************************************************
651 CreateServiceW(SC_HANDLE hSCManager
,
652 LPCWSTR lpServiceName
,
653 LPCWSTR lpDisplayName
,
654 DWORD dwDesiredAccess
,
657 DWORD dwErrorControl
,
658 LPCWSTR lpBinaryPathName
,
659 LPCWSTR lpLoadOrderGroup
,
661 LPCWSTR lpDependencies
,
662 LPCWSTR lpServiceStartName
,
665 SC_HANDLE hService
= NULL
;
666 DWORD dwDependenciesLength
= 0;
671 TRACE("CreateServiceW() called\n");
673 /* Calculate the Dependencies length*/
674 if (lpDependencies
!= NULL
)
676 lpStr
= (LPWSTR
)lpDependencies
;
679 dwLength
= wcslen(lpStr
) + 1;
680 dwDependenciesLength
+= dwLength
;
681 lpStr
= lpStr
+ dwLength
;
683 dwDependenciesLength
++;
685 dwDependenciesLength
*= sizeof(WCHAR
);
688 /* FIXME: Encrypt the password */
694 /* Call to services.exe using RPC */
695 dwError
= RCreateServiceW(BindingHandle
,
696 (SC_RPC_HANDLE
)hSCManager
,
697 (LPWSTR
)lpServiceName
,
698 (LPWSTR
)lpDisplayName
,
703 (LPWSTR
)lpBinaryPathName
,
704 (LPWSTR
)lpLoadOrderGroup
,
706 (LPBYTE
)lpDependencies
,
707 dwDependenciesLength
,
708 (LPWSTR
)lpServiceStartName
,
709 NULL
, /* FIXME: lpPassword */
710 0, /* FIXME: dwPasswordLength */
711 (SC_RPC_HANDLE
*)&hService
);
715 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
719 if (dwError
!= ERROR_SUCCESS
)
721 ERR("RCreateServiceW() failed (Error %lu)\n", dwError
);
722 SetLastError(dwError
);
730 /**********************************************************************
736 DeleteService(SC_HANDLE hService
)
740 TRACE("DeleteService(%x)\n", hService
);
746 /* Call to services.exe using RPC */
747 dwError
= RDeleteService(BindingHandle
,
748 (SC_RPC_HANDLE
)hService
);
752 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
756 if (dwError
!= ERROR_SUCCESS
)
758 ERR("RDeleteService() failed (Error %lu)\n", dwError
);
759 SetLastError(dwError
);
767 /**********************************************************************
768 * EnumDependentServicesA
773 EnumDependentServicesA(SC_HANDLE hService
,
774 DWORD dwServiceState
,
775 LPENUM_SERVICE_STATUSA lpServices
,
777 LPDWORD pcbBytesNeeded
,
778 LPDWORD lpServicesReturned
)
780 LPENUM_SERVICE_STATUSA lpStatusPtr
;
784 TRACE("EnumServicesStatusA() called\n");
790 dwError
= REnumDependentServicesA(BindingHandle
,
791 (SC_RPC_HANDLE
)hService
,
800 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
804 lpStatusPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
805 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
807 if (lpStatusPtr
->lpServiceName
)
808 lpStatusPtr
->lpServiceName
=
809 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
811 if (lpStatusPtr
->lpDisplayName
)
812 lpStatusPtr
->lpDisplayName
=
813 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
818 if (dwError
!= ERROR_SUCCESS
)
820 ERR("REnumDependentServicesA() failed (Error %lu)\n", dwError
);
821 SetLastError(dwError
);
825 TRACE("EnumDependentServicesA() done\n");
831 /**********************************************************************
832 * EnumDependentServicesW
837 EnumDependentServicesW(SC_HANDLE hService
,
838 DWORD dwServiceState
,
839 LPENUM_SERVICE_STATUSW lpServices
,
841 LPDWORD pcbBytesNeeded
,
842 LPDWORD lpServicesReturned
)
844 LPENUM_SERVICE_STATUSW lpStatusPtr
;
848 TRACE("EnumServicesStatusW() called\n");
854 dwError
= REnumDependentServicesW(BindingHandle
,
855 (SC_RPC_HANDLE
)hService
,
864 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
868 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
869 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
871 if (lpStatusPtr
->lpServiceName
)
872 lpStatusPtr
->lpServiceName
=
873 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
875 if (lpStatusPtr
->lpDisplayName
)
876 lpStatusPtr
->lpDisplayName
=
877 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
882 if (dwError
!= ERROR_SUCCESS
)
884 ERR("REnumDependentServicesW() failed (Error %lu)\n", dwError
);
885 SetLastError(dwError
);
889 TRACE("EnumDependentServicesW() done\n");
895 /**********************************************************************
903 SC_HANDLE hSCManager
,
905 DWORD dwServiceState
,
906 LPENUM_SERVICE_STATUSW lpServices
,
908 LPDWORD pcbBytesNeeded
,
909 LPDWORD lpServicesReturned
,
910 LPDWORD lpResumeHandle
,
913 FIXME("EnumServiceGroupW is unimplemented\n");
914 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
919 /**********************************************************************
920 * EnumServicesStatusA
925 EnumServicesStatusA(SC_HANDLE hSCManager
,
927 DWORD dwServiceState
,
928 LPENUM_SERVICE_STATUSA lpServices
,
930 LPDWORD pcbBytesNeeded
,
931 LPDWORD lpServicesReturned
,
932 LPDWORD lpResumeHandle
)
934 LPENUM_SERVICE_STATUSA lpStatusPtr
;
938 TRACE("EnumServicesStatusA() called\n");
944 dwError
= REnumServicesStatusA(BindingHandle
,
945 (SC_RPC_HANDLE
)hSCManager
,
956 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
960 lpStatusPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
961 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
963 if (lpStatusPtr
->lpServiceName
)
964 lpStatusPtr
->lpServiceName
=
965 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
967 if (lpStatusPtr
->lpDisplayName
)
968 lpStatusPtr
->lpDisplayName
=
969 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
974 if (dwError
!= ERROR_SUCCESS
)
976 ERR("REnumServicesStatusA() failed (Error %lu)\n", dwError
);
977 SetLastError(dwError
);
981 TRACE("EnumServicesStatusA() done\n");
987 /**********************************************************************
988 * EnumServicesStatusW
993 EnumServicesStatusW(SC_HANDLE hSCManager
,
995 DWORD dwServiceState
,
996 LPENUM_SERVICE_STATUSW lpServices
,
998 LPDWORD pcbBytesNeeded
,
999 LPDWORD lpServicesReturned
,
1000 LPDWORD lpResumeHandle
)
1002 LPENUM_SERVICE_STATUSW lpStatusPtr
;
1006 TRACE("EnumServicesStatusW() called\n");
1012 dwError
= REnumServicesStatusW(BindingHandle
,
1013 (SC_RPC_HANDLE
)hSCManager
,
1024 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1028 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
1029 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1031 if (lpStatusPtr
->lpServiceName
)
1032 lpStatusPtr
->lpServiceName
=
1033 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1035 if (lpStatusPtr
->lpDisplayName
)
1036 lpStatusPtr
->lpDisplayName
=
1037 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1042 if (dwError
!= ERROR_SUCCESS
)
1044 ERR("REnumServicesStatusW() failed (Error %lu)\n", dwError
);
1045 SetLastError(dwError
);
1049 TRACE("EnumServicesStatusW() done\n");
1055 /**********************************************************************
1056 * EnumServicesStatusExA
1061 EnumServicesStatusExA(SC_HANDLE hSCManager
,
1062 SC_ENUM_TYPE InfoLevel
,
1063 DWORD dwServiceType
,
1064 DWORD dwServiceState
,
1067 LPDWORD pcbBytesNeeded
,
1068 LPDWORD lpServicesReturned
,
1069 LPDWORD lpResumeHandle
,
1070 LPCSTR pszGroupName
)
1072 LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtr
;
1076 TRACE("EnumServicesStatusExA() called\n");
1082 dwError
= REnumServicesStatusExA(BindingHandle
,
1083 (SC_RPC_HANDLE
)hSCManager
,
1092 (LPSTR
)pszGroupName
);
1096 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1100 if (dwError
== ERROR_MORE_DATA
)
1102 WARN("Required buffer size %ul\n", *pcbBytesNeeded
);
1103 SetLastError(dwError
);
1106 else if (dwError
== ERROR_SUCCESS
)
1108 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpServices
;
1109 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1111 if (lpStatusPtr
->lpServiceName
)
1112 lpStatusPtr
->lpServiceName
=
1113 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1115 if (lpStatusPtr
->lpDisplayName
)
1116 lpStatusPtr
->lpDisplayName
=
1117 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1124 ERR("REnumServicesStatusExA() failed (Error %lu)\n", dwError
);
1125 SetLastError(dwError
);
1129 TRACE("EnumServicesStatusExA() done\n");
1135 /**********************************************************************
1136 * EnumServicesStatusExW
1141 EnumServicesStatusExW(SC_HANDLE hSCManager
,
1142 SC_ENUM_TYPE InfoLevel
,
1143 DWORD dwServiceType
,
1144 DWORD dwServiceState
,
1147 LPDWORD pcbBytesNeeded
,
1148 LPDWORD lpServicesReturned
,
1149 LPDWORD lpResumeHandle
,
1150 LPCWSTR pszGroupName
)
1152 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
1156 TRACE("EnumServicesStatusExW() called\n");
1162 dwError
= REnumServicesStatusExW(BindingHandle
,
1163 (SC_RPC_HANDLE
)hSCManager
,
1172 (LPWSTR
)pszGroupName
);
1176 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1180 if (dwError
== ERROR_MORE_DATA
)
1182 WARN("Required buffer size %ul\n", *pcbBytesNeeded
);
1183 SetLastError(dwError
);
1186 else if (dwError
== ERROR_SUCCESS
)
1188 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpServices
;
1189 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1191 if (lpStatusPtr
->lpServiceName
)
1192 lpStatusPtr
->lpServiceName
=
1193 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1195 if (lpStatusPtr
->lpDisplayName
)
1196 lpStatusPtr
->lpDisplayName
=
1197 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1204 ERR("REnumServicesStatusExW() failed (Error %lu)\n", dwError
);
1205 SetLastError(dwError
);
1209 TRACE("EnumServicesStatusExW() done\n");
1215 /**********************************************************************
1216 * GetServiceDisplayNameA
1221 GetServiceDisplayNameA(SC_HANDLE hSCManager
,
1222 LPCSTR lpServiceName
,
1223 LPSTR lpDisplayName
,
1224 LPDWORD lpcchBuffer
)
1228 TRACE("GetServiceDisplayNameA() called\n");
1237 dwError
= RGetServiceDisplayNameA(BindingHandle
,
1238 (SC_RPC_HANDLE
)hSCManager
,
1239 (LPSTR
)lpServiceName
,
1245 /* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
1246 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1252 if (dwError
!= ERROR_SUCCESS
)
1254 ERR("RGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
1255 SetLastError(dwError
);
1263 /**********************************************************************
1264 * GetServiceDisplayNameW
1269 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
1270 LPCWSTR lpServiceName
,
1271 LPWSTR lpDisplayName
,
1272 LPDWORD lpcchBuffer
)
1276 TRACE("GetServiceDisplayNameW() called\n");
1285 dwError
= RGetServiceDisplayNameW(BindingHandle
,
1286 (SC_RPC_HANDLE
)hSCManager
,
1287 (LPWSTR
)lpServiceName
,
1293 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1297 if (dwError
!= ERROR_SUCCESS
)
1299 ERR("RGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1300 SetLastError(dwError
);
1308 /**********************************************************************
1309 * GetServiceKeyNameA
1314 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1315 LPCSTR lpDisplayName
,
1316 LPSTR lpServiceName
,
1317 LPDWORD lpcchBuffer
)
1321 TRACE("GetServiceKeyNameA() called\n");
1330 dwError
= RGetServiceKeyNameA(BindingHandle
,
1331 (SC_RPC_HANDLE
)hSCManager
,
1332 (LPSTR
)lpDisplayName
,
1338 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1342 if (dwError
!= ERROR_SUCCESS
)
1344 ERR("RGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1345 SetLastError(dwError
);
1353 /**********************************************************************
1354 * GetServiceKeyNameW
1359 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1360 LPCWSTR lpDisplayName
,
1361 LPWSTR lpServiceName
,
1362 LPDWORD lpcchBuffer
)
1366 TRACE("GetServiceKeyNameW() called\n");
1375 dwError
= RGetServiceKeyNameW(BindingHandle
,
1376 (SC_RPC_HANDLE
)hSCManager
,
1377 (LPWSTR
)lpDisplayName
,
1383 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1387 if (dwError
!= ERROR_SUCCESS
)
1389 ERR("RGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1390 SetLastError(dwError
);
1398 /**********************************************************************
1399 * LockServiceDatabase
1404 LockServiceDatabase(SC_HANDLE hSCManager
)
1409 TRACE("LockServiceDatabase(%x)\n", hSCManager
);
1415 /* Call to services.exe using RPC */
1416 dwError
= RLockServiceDatabase(BindingHandle
,
1417 (SC_RPC_HANDLE
)hSCManager
,
1418 (SC_RPC_LOCK
*)&hLock
);
1422 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1426 if (dwError
!= ERROR_SUCCESS
)
1428 ERR("RLockServiceDatabase() failed (Error %lu)\n", dwError
);
1429 SetLastError(dwError
);
1433 TRACE("hLock = %p\n", hLock
);
1440 WaitForSCManager(VOID
)
1444 TRACE("WaitForSCManager() called\n");
1446 /* Try to open the existing event */
1447 hEvent
= OpenEventW(SYNCHRONIZE
,
1449 L
"SvcctrlStartEvent_A3752DX");
1452 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1455 /* Try to create a new event */
1456 hEvent
= CreateEventW(NULL
,
1459 L
"SvcctrlStartEvent_A3752DX");
1462 /* Try to open the existing event again */
1463 hEvent
= OpenEventW(SYNCHRONIZE
,
1465 L
"SvcctrlStartEvent_A3752DX");
1471 /* Wait for 3 minutes */
1472 WaitForSingleObject(hEvent
, 180000);
1473 CloseHandle(hEvent
);
1475 TRACE("ScmWaitForSCManager() done\n");
1479 /**********************************************************************
1485 OpenSCManagerA(LPCSTR lpMachineName
,
1486 LPCSTR lpDatabaseName
,
1487 DWORD dwDesiredAccess
)
1489 SC_HANDLE hScm
= NULL
;
1492 TRACE("OpenSCManagerA(%s, %s, %lx)\n",
1493 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1501 /* Call to services.exe using RPC */
1502 dwError
= ROpenSCManagerA(BindingHandle
,
1503 (LPSTR
)lpMachineName
,
1504 (LPSTR
)lpDatabaseName
,
1506 (SC_RPC_HANDLE
*)&hScm
);
1510 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1514 if (dwError
!= ERROR_SUCCESS
)
1516 ERR("ROpenSCManagerA() failed (Error %lu)\n", dwError
);
1517 SetLastError(dwError
);
1521 TRACE("hScm = %p\n", hScm
);
1527 /**********************************************************************
1533 OpenSCManagerW(LPCWSTR lpMachineName
,
1534 LPCWSTR lpDatabaseName
,
1535 DWORD dwDesiredAccess
)
1537 SC_HANDLE hScm
= NULL
;
1540 TRACE("OpenSCManagerW(%S, %S, %lx)\n",
1541 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1549 /* Call to services.exe using RPC */
1550 dwError
= ROpenSCManagerW(BindingHandle
,
1551 (LPWSTR
)lpMachineName
,
1552 (LPWSTR
)lpDatabaseName
,
1554 (SC_RPC_HANDLE
*)&hScm
);
1558 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1562 if (dwError
!= ERROR_SUCCESS
)
1564 ERR("ROpenSCManagerW() failed (Error %lu)\n", dwError
);
1565 SetLastError(dwError
);
1569 TRACE("hScm = %p\n", hScm
);
1575 /**********************************************************************
1581 OpenServiceA(SC_HANDLE hSCManager
,
1582 LPCSTR lpServiceName
,
1583 DWORD dwDesiredAccess
)
1585 SC_HANDLE hService
= NULL
;
1588 TRACE("OpenServiceA(%p, %s, %lx)\n",
1589 hSCManager
, lpServiceName
, dwDesiredAccess
);
1595 /* Call to services.exe using RPC */
1596 dwError
= ROpenServiceA(BindingHandle
,
1597 (SC_RPC_HANDLE
)hSCManager
,
1598 (LPSTR
)lpServiceName
,
1600 (SC_RPC_HANDLE
*)&hService
);
1604 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1608 if (dwError
!= ERROR_SUCCESS
)
1610 ERR("ROpenServiceA() failed (Error %lu)\n", dwError
);
1611 SetLastError(dwError
);
1615 TRACE("hService = %p\n", hService
);
1621 /**********************************************************************
1627 OpenServiceW(SC_HANDLE hSCManager
,
1628 LPCWSTR lpServiceName
,
1629 DWORD dwDesiredAccess
)
1631 SC_HANDLE hService
= NULL
;
1634 TRACE("OpenServiceW(%p, %S, %lx)\n",
1635 hSCManager
, lpServiceName
, dwDesiredAccess
);
1641 /* Call to services.exe using RPC */
1642 dwError
= ROpenServiceW(BindingHandle
,
1643 (SC_RPC_HANDLE
)hSCManager
,
1644 (LPWSTR
)lpServiceName
,
1646 (SC_RPC_HANDLE
*)&hService
);
1650 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1654 if (dwError
!= ERROR_SUCCESS
)
1656 if (dwError
== ERROR_SERVICE_DOES_NOT_EXIST
)
1657 WARN("ROpenServiceW() failed (Error %lu)\n", dwError
);
1659 ERR("ROpenServiceW() failed (Error %lu)\n", dwError
);
1660 SetLastError(dwError
);
1664 TRACE("hService = %p\n", hService
);
1670 /**********************************************************************
1671 * QueryServiceConfigA
1676 QueryServiceConfigA(SC_HANDLE hService
,
1677 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
1679 LPDWORD pcbBytesNeeded
)
1683 TRACE("QueryServiceConfigA(%p, %p, %lu, %p)\n",
1684 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1690 /* Call to services.exe using RPC */
1691 dwError
= RQueryServiceConfigA(BindingHandle
,
1692 (SC_RPC_HANDLE
)hService
,
1693 (LPBYTE
)lpServiceConfig
,
1699 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1703 if (dwError
!= ERROR_SUCCESS
)
1705 ERR("RQueryServiceConfigA() failed (Error %lu)\n", dwError
);
1706 SetLastError(dwError
);
1710 /* Adjust the pointers */
1711 if (lpServiceConfig
->lpBinaryPathName
)
1712 lpServiceConfig
->lpBinaryPathName
=
1713 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1714 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1716 if (lpServiceConfig
->lpLoadOrderGroup
)
1717 lpServiceConfig
->lpLoadOrderGroup
=
1718 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1719 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1721 if (lpServiceConfig
->lpDependencies
)
1722 lpServiceConfig
->lpDependencies
=
1723 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1724 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1726 if (lpServiceConfig
->lpServiceStartName
)
1727 lpServiceConfig
->lpServiceStartName
=
1728 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1729 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1731 if (lpServiceConfig
->lpDisplayName
)
1732 lpServiceConfig
->lpDisplayName
=
1733 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1734 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1736 TRACE("QueryServiceConfigA() done\n");
1742 /**********************************************************************
1743 * QueryServiceConfigW
1748 QueryServiceConfigW(SC_HANDLE hService
,
1749 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
1751 LPDWORD pcbBytesNeeded
)
1755 TRACE("QueryServiceConfigW(%p, %p, %lu, %p)\n",
1756 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1762 /* Call to services.exe using RPC */
1763 dwError
= RQueryServiceConfigW(BindingHandle
,
1764 (SC_RPC_HANDLE
)hService
,
1765 (LPBYTE
)lpServiceConfig
,
1771 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1775 if (dwError
!= ERROR_SUCCESS
)
1777 if (dwError
== ERROR_INSUFFICIENT_BUFFER
)
1778 WARN("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1780 ERR("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1781 SetLastError(dwError
);
1785 /* Adjust the pointers */
1786 if (lpServiceConfig
->lpBinaryPathName
)
1787 lpServiceConfig
->lpBinaryPathName
=
1788 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1789 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1791 if (lpServiceConfig
->lpLoadOrderGroup
)
1792 lpServiceConfig
->lpLoadOrderGroup
=
1793 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1794 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1796 if (lpServiceConfig
->lpDependencies
)
1797 lpServiceConfig
->lpDependencies
=
1798 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1799 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1801 if (lpServiceConfig
->lpServiceStartName
)
1802 lpServiceConfig
->lpServiceStartName
=
1803 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1804 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1806 if (lpServiceConfig
->lpDisplayName
)
1807 lpServiceConfig
->lpDisplayName
=
1808 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1809 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1811 TRACE("QueryServiceConfigW() done\n");
1817 /**********************************************************************
1818 * QueryServiceConfig2A
1823 QueryServiceConfig2A(SC_HANDLE hService
,
1827 LPDWORD pcbBytesNeeded
)
1831 TRACE("QueryServiceConfig2A(%p, %lu, %p, %lu, %p)\n",
1832 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1838 /* Call to services.exe using RPC */
1839 dwError
= RQueryServiceConfig2A(BindingHandle
,
1840 (SC_RPC_HANDLE
)hService
,
1848 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1852 if (dwError
!= ERROR_SUCCESS
)
1854 ERR("RQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
1855 SetLastError(dwError
);
1859 switch (dwInfoLevel
)
1861 case SERVICE_CONFIG_DESCRIPTION
:
1863 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
1865 if (lpPtr
->lpDescription
!= NULL
)
1866 lpPtr
->lpDescription
=
1867 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1871 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1873 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpBuffer
;
1875 if (lpPtr
->lpRebootMsg
!= NULL
)
1876 lpPtr
->lpRebootMsg
=
1877 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1879 if (lpPtr
->lpCommand
!= NULL
)
1881 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1883 if (lpPtr
->lpsaActions
!= NULL
)
1884 lpPtr
->lpsaActions
=
1885 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1890 ERR("Unknown info level 0x%lx\n", dwInfoLevel
);
1891 SetLastError(ERROR_INVALID_PARAMETER
);
1895 TRACE("QueryServiceConfig2A() done\n");
1901 /**********************************************************************
1902 * QueryServiceConfig2W
1907 QueryServiceConfig2W(SC_HANDLE hService
,
1911 LPDWORD pcbBytesNeeded
)
1915 TRACE("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
1916 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1922 /* Call to services.exe using RPC */
1923 dwError
= RQueryServiceConfig2W(BindingHandle
,
1924 (SC_RPC_HANDLE
)hService
,
1932 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1936 if (dwError
!= ERROR_SUCCESS
)
1938 ERR("RQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
1939 SetLastError(dwError
);
1943 switch (dwInfoLevel
)
1945 case SERVICE_CONFIG_DESCRIPTION
:
1947 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
1949 if (lpPtr
->lpDescription
!= NULL
)
1950 lpPtr
->lpDescription
=
1951 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1955 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1957 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
1959 if (lpPtr
->lpRebootMsg
!= NULL
)
1960 lpPtr
->lpRebootMsg
=
1961 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1963 if (lpPtr
->lpCommand
!= NULL
)
1965 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1967 if (lpPtr
->lpsaActions
!= NULL
)
1968 lpPtr
->lpsaActions
=
1969 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1974 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
1975 SetLastError(ERROR_INVALID_PARAMETER
);
1979 TRACE("QueryServiceConfig2W() done\n");
1985 /**********************************************************************
1986 * QueryServiceLockStatusA
1991 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
1992 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
1994 LPDWORD pcbBytesNeeded
)
1998 TRACE("QueryServiceLockStatusA() called\n");
2004 /* Call to services.exe using RPC */
2005 dwError
= RQueryServiceLockStatusA(BindingHandle
,
2006 (SC_RPC_HANDLE
)hSCManager
,
2013 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2017 if (dwError
!= ERROR_SUCCESS
)
2019 ERR("RQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
2020 SetLastError(dwError
);
2024 if (lpLockStatus
->lpLockOwner
!= NULL
)
2026 lpLockStatus
->lpLockOwner
=
2027 (LPSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
2030 TRACE("QueryServiceLockStatusA() done\n");
2036 /**********************************************************************
2037 * QueryServiceLockStatusW
2042 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
2043 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
2045 LPDWORD pcbBytesNeeded
)
2049 TRACE("QueryServiceLockStatusW() called\n");
2055 /* Call to services.exe using RPC */
2056 dwError
= RQueryServiceLockStatusW(BindingHandle
,
2057 (SC_RPC_HANDLE
)hSCManager
,
2064 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2068 if (dwError
!= ERROR_SUCCESS
)
2070 ERR("RQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
2071 SetLastError(dwError
);
2075 if (lpLockStatus
->lpLockOwner
!= NULL
)
2077 lpLockStatus
->lpLockOwner
=
2078 (LPWSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
2081 TRACE("QueryServiceLockStatusW() done\n");
2087 /**********************************************************************
2088 * QueryServiceObjectSecurity
2093 QueryServiceObjectSecurity(SC_HANDLE hService
,
2094 SECURITY_INFORMATION dwSecurityInformation
,
2095 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
2097 LPDWORD pcbBytesNeeded
)
2101 TRACE("QueryServiceObjectSecurity(%p, %lu, %p)\n",
2102 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2108 /* Call to services.exe using RPC */
2109 dwError
= RQueryServiceObjectSecurity(BindingHandle
,
2110 (SC_RPC_HANDLE
)hService
,
2111 dwSecurityInformation
,
2112 (LPBYTE
)lpSecurityDescriptor
,
2118 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2122 if (dwError
!= ERROR_SUCCESS
)
2124 ERR("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2125 SetLastError(dwError
);
2132 /**********************************************************************
2133 * SetServiceObjectSecurity
2138 SetServiceObjectSecurity(SC_HANDLE hService
,
2139 SECURITY_INFORMATION dwSecurityInformation
,
2140 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
2142 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
2148 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2151 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
2153 SetLastError(ERROR_INVALID_PARAMETER
);
2157 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
2158 if (SelfRelativeSD
== NULL
)
2160 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2164 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2167 if (!NT_SUCCESS(Status
))
2169 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2170 SetLastError(RtlNtStatusToDosError(Status
));
2178 /* Call to services.exe using RPC */
2179 dwError
= RSetServiceObjectSecurity(BindingHandle
,
2180 (SC_RPC_HANDLE
)hService
,
2181 dwSecurityInformation
,
2182 (LPBYTE
)SelfRelativeSD
,
2187 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2191 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2193 if (dwError
!= ERROR_SUCCESS
)
2195 ERR("RServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2196 SetLastError(dwError
);
2204 /**********************************************************************
2205 * QueryServiceStatus
2210 QueryServiceStatus(SC_HANDLE hService
,
2211 LPSERVICE_STATUS lpServiceStatus
)
2215 TRACE("QueryServiceStatus(%p, %p)\n",
2216 hService
, lpServiceStatus
);
2222 /* Call to services.exe using RPC */
2223 dwError
= RQueryServiceStatus(BindingHandle
,
2224 (SC_RPC_HANDLE
)hService
,
2229 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2233 if (dwError
!= ERROR_SUCCESS
)
2235 ERR("RQueryServiceStatus() failed (Error %lu)\n", dwError
);
2236 SetLastError(dwError
);
2244 /**********************************************************************
2245 * QueryServiceStatusEx
2250 QueryServiceStatusEx(SC_HANDLE hService
,
2251 SC_STATUS_TYPE InfoLevel
,
2254 LPDWORD pcbBytesNeeded
)
2258 TRACE("QueryServiceStatusEx() called\n");
2264 /* Call to services.exe using RPC */
2265 dwError
= RQueryServiceStatusEx(BindingHandle
,
2266 (SC_RPC_HANDLE
)hService
,
2274 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2278 if (dwError
!= ERROR_SUCCESS
)
2280 ERR("RQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
2281 SetLastError(dwError
);
2289 /**********************************************************************
2295 StartServiceA(SC_HANDLE hService
,
2296 DWORD dwNumServiceArgs
,
2297 LPCSTR
*lpServiceArgVectors
)
2303 dwError
= RStartServiceA(BindingHandle
,
2304 (SC_RPC_HANDLE
)hService
,
2306 (LPSTRING_PTRSA
)lpServiceArgVectors
);
2310 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2314 if (dwError
!= ERROR_SUCCESS
)
2316 ERR("RStartServiceA() failed (Error %lu)\n", dwError
);
2317 SetLastError(dwError
);
2325 /**********************************************************************
2331 StartServiceW(SC_HANDLE hService
,
2332 DWORD dwNumServiceArgs
,
2333 LPCWSTR
*lpServiceArgVectors
)
2339 dwError
= RStartServiceW(BindingHandle
,
2340 (SC_RPC_HANDLE
)hService
,
2342 (LPSTRING_PTRSW
)lpServiceArgVectors
);
2346 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2350 if (dwError
!= ERROR_SUCCESS
)
2352 ERR("RStartServiceW() failed (Error %lu)\n", dwError
);
2353 SetLastError(dwError
);
2361 /**********************************************************************
2362 * UnlockServiceDatabase
2367 UnlockServiceDatabase(SC_LOCK ScLock
)
2371 TRACE("UnlockServiceDatabase(%x)\n", ScLock
);
2377 /* Call to services.exe using RPC */
2378 dwError
= RUnlockServiceDatabase(BindingHandle
,
2379 (SC_RPC_LOCK
)ScLock
);
2383 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2387 if (dwError
!= ERROR_SUCCESS
)
2389 ERR("RUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2390 SetLastError(dwError
);
2398 /**********************************************************************
2399 * NotifyBootConfigStatus
2404 NotifyBootConfigStatus(BOOL BootAcceptable
)
2408 TRACE("NotifyBootConfigStatus()\n");
2414 /* Call to services.exe using RPC */
2415 dwError
= RNotifyBootConfigStatus(BindingHandle
,
2421 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2425 if (dwError
!= ERROR_SUCCESS
)
2427 ERR("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
2428 SetLastError(dwError
);