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
)(ULONG_PTR
)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
);
1834 if (dwInfoLevel
!= SERVICE_CONFIG_DESCRIPTION
&&
1835 dwInfoLevel
!= SERVICE_CONFIG_FAILURE_ACTIONS
)
1837 SetLastError(ERROR_INVALID_LEVEL
);
1841 if ((lpBuffer
== NULL
&& cbBufSize
!= 0) ||
1842 pcbBytesNeeded
== NULL
)
1844 SetLastError(ERROR_INVALID_ADDRESS
);
1852 /* Call to services.exe using RPC */
1853 dwError
= RQueryServiceConfig2A(BindingHandle
,
1854 (SC_RPC_HANDLE
)hService
,
1862 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1866 if (dwError
!= ERROR_SUCCESS
)
1868 ERR("RQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
1869 SetLastError(dwError
);
1873 switch (dwInfoLevel
)
1875 case SERVICE_CONFIG_DESCRIPTION
:
1877 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
1879 if (lpPtr
->lpDescription
!= NULL
)
1880 lpPtr
->lpDescription
=
1881 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1885 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1887 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpBuffer
;
1889 if (lpPtr
->lpRebootMsg
!= NULL
)
1890 lpPtr
->lpRebootMsg
=
1891 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1893 if (lpPtr
->lpCommand
!= NULL
)
1895 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1897 if (lpPtr
->lpsaActions
!= NULL
)
1898 lpPtr
->lpsaActions
=
1899 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1904 ERR("Unknown info level 0x%lx\n", dwInfoLevel
);
1905 SetLastError(ERROR_INVALID_PARAMETER
);
1909 TRACE("QueryServiceConfig2A() done\n");
1915 /**********************************************************************
1916 * QueryServiceConfig2W
1921 QueryServiceConfig2W(SC_HANDLE hService
,
1925 LPDWORD pcbBytesNeeded
)
1929 TRACE("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
1930 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1932 if (dwInfoLevel
!= SERVICE_CONFIG_DESCRIPTION
&&
1933 dwInfoLevel
!= SERVICE_CONFIG_FAILURE_ACTIONS
)
1935 SetLastError(ERROR_INVALID_LEVEL
);
1939 if ((lpBuffer
== NULL
&& cbBufSize
!= 0) ||
1940 pcbBytesNeeded
== NULL
)
1942 SetLastError(ERROR_INVALID_ADDRESS
);
1950 /* Call to services.exe using RPC */
1951 dwError
= RQueryServiceConfig2W(BindingHandle
,
1952 (SC_RPC_HANDLE
)hService
,
1960 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1964 if (dwError
!= ERROR_SUCCESS
)
1966 ERR("RQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
1967 SetLastError(dwError
);
1971 switch (dwInfoLevel
)
1973 case SERVICE_CONFIG_DESCRIPTION
:
1975 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
1977 if (lpPtr
->lpDescription
!= NULL
)
1978 lpPtr
->lpDescription
=
1979 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1983 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1985 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
1987 if (lpPtr
->lpRebootMsg
!= NULL
)
1988 lpPtr
->lpRebootMsg
=
1989 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1991 if (lpPtr
->lpCommand
!= NULL
)
1993 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1995 if (lpPtr
->lpsaActions
!= NULL
)
1996 lpPtr
->lpsaActions
=
1997 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
2002 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
2003 SetLastError(ERROR_INVALID_PARAMETER
);
2007 TRACE("QueryServiceConfig2W() done\n");
2013 /**********************************************************************
2014 * QueryServiceLockStatusA
2019 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
2020 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
2022 LPDWORD pcbBytesNeeded
)
2026 TRACE("QueryServiceLockStatusA() called\n");
2032 /* Call to services.exe using RPC */
2033 dwError
= RQueryServiceLockStatusA(BindingHandle
,
2034 (SC_RPC_HANDLE
)hSCManager
,
2041 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2045 if (dwError
!= ERROR_SUCCESS
)
2047 ERR("RQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
2048 SetLastError(dwError
);
2052 if (lpLockStatus
->lpLockOwner
!= NULL
)
2054 lpLockStatus
->lpLockOwner
=
2055 (LPSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
2058 TRACE("QueryServiceLockStatusA() done\n");
2064 /**********************************************************************
2065 * QueryServiceLockStatusW
2070 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
2071 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
2073 LPDWORD pcbBytesNeeded
)
2077 TRACE("QueryServiceLockStatusW() called\n");
2083 /* Call to services.exe using RPC */
2084 dwError
= RQueryServiceLockStatusW(BindingHandle
,
2085 (SC_RPC_HANDLE
)hSCManager
,
2092 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2096 if (dwError
!= ERROR_SUCCESS
)
2098 ERR("RQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
2099 SetLastError(dwError
);
2103 if (lpLockStatus
->lpLockOwner
!= NULL
)
2105 lpLockStatus
->lpLockOwner
=
2106 (LPWSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
2109 TRACE("QueryServiceLockStatusW() done\n");
2115 /**********************************************************************
2116 * QueryServiceObjectSecurity
2121 QueryServiceObjectSecurity(SC_HANDLE hService
,
2122 SECURITY_INFORMATION dwSecurityInformation
,
2123 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
2125 LPDWORD pcbBytesNeeded
)
2129 TRACE("QueryServiceObjectSecurity(%p, %lu, %p)\n",
2130 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2136 /* Call to services.exe using RPC */
2137 dwError
= RQueryServiceObjectSecurity(BindingHandle
,
2138 (SC_RPC_HANDLE
)hService
,
2139 dwSecurityInformation
,
2140 (LPBYTE
)lpSecurityDescriptor
,
2146 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2150 if (dwError
!= ERROR_SUCCESS
)
2152 ERR("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2153 SetLastError(dwError
);
2160 /**********************************************************************
2161 * SetServiceObjectSecurity
2166 SetServiceObjectSecurity(SC_HANDLE hService
,
2167 SECURITY_INFORMATION dwSecurityInformation
,
2168 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
2170 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
2176 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2179 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
2181 SetLastError(ERROR_INVALID_PARAMETER
);
2185 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
2186 if (SelfRelativeSD
== NULL
)
2188 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2192 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2195 if (!NT_SUCCESS(Status
))
2197 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2198 SetLastError(RtlNtStatusToDosError(Status
));
2206 /* Call to services.exe using RPC */
2207 dwError
= RSetServiceObjectSecurity(BindingHandle
,
2208 (SC_RPC_HANDLE
)hService
,
2209 dwSecurityInformation
,
2210 (LPBYTE
)SelfRelativeSD
,
2215 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2219 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2221 if (dwError
!= ERROR_SUCCESS
)
2223 ERR("RServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2224 SetLastError(dwError
);
2232 /**********************************************************************
2233 * QueryServiceStatus
2238 QueryServiceStatus(SC_HANDLE hService
,
2239 LPSERVICE_STATUS lpServiceStatus
)
2243 TRACE("QueryServiceStatus(%p, %p)\n",
2244 hService
, lpServiceStatus
);
2250 /* Call to services.exe using RPC */
2251 dwError
= RQueryServiceStatus(BindingHandle
,
2252 (SC_RPC_HANDLE
)hService
,
2257 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2261 if (dwError
!= ERROR_SUCCESS
)
2263 ERR("RQueryServiceStatus() failed (Error %lu)\n", dwError
);
2264 SetLastError(dwError
);
2272 /**********************************************************************
2273 * QueryServiceStatusEx
2278 QueryServiceStatusEx(SC_HANDLE hService
,
2279 SC_STATUS_TYPE InfoLevel
,
2282 LPDWORD pcbBytesNeeded
)
2286 TRACE("QueryServiceStatusEx() called\n");
2292 /* Call to services.exe using RPC */
2293 dwError
= RQueryServiceStatusEx(BindingHandle
,
2294 (SC_RPC_HANDLE
)hService
,
2302 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2306 if (dwError
!= ERROR_SUCCESS
)
2308 ERR("RQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
2309 SetLastError(dwError
);
2317 /**********************************************************************
2323 StartServiceA(SC_HANDLE hService
,
2324 DWORD dwNumServiceArgs
,
2325 LPCSTR
*lpServiceArgVectors
)
2331 dwError
= RStartServiceA(BindingHandle
,
2332 (SC_RPC_HANDLE
)hService
,
2334 (LPSTRING_PTRSA
)lpServiceArgVectors
);
2338 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2342 if (dwError
!= ERROR_SUCCESS
)
2344 ERR("RStartServiceA() failed (Error %lu)\n", dwError
);
2345 SetLastError(dwError
);
2353 /**********************************************************************
2359 StartServiceW(SC_HANDLE hService
,
2360 DWORD dwNumServiceArgs
,
2361 LPCWSTR
*lpServiceArgVectors
)
2367 dwError
= RStartServiceW(BindingHandle
,
2368 (SC_RPC_HANDLE
)hService
,
2370 (LPSTRING_PTRSW
)lpServiceArgVectors
);
2374 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2378 if (dwError
!= ERROR_SUCCESS
)
2380 ERR("RStartServiceW() failed (Error %lu)\n", dwError
);
2381 SetLastError(dwError
);
2389 /**********************************************************************
2390 * UnlockServiceDatabase
2395 UnlockServiceDatabase(SC_LOCK ScLock
)
2399 TRACE("UnlockServiceDatabase(%x)\n", ScLock
);
2405 /* Call to services.exe using RPC */
2406 dwError
= RUnlockServiceDatabase(BindingHandle
,
2407 (SC_RPC_LOCK
)ScLock
);
2411 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2415 if (dwError
!= ERROR_SUCCESS
)
2417 ERR("RUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2418 SetLastError(dwError
);
2426 /**********************************************************************
2427 * NotifyBootConfigStatus
2432 NotifyBootConfigStatus(BOOL BootAcceptable
)
2436 TRACE("NotifyBootConfigStatus()\n");
2442 /* Call to services.exe using RPC */
2443 dwError
= RNotifyBootConfigStatus(BindingHandle
,
2449 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2453 if (dwError
!= ERROR_SUCCESS
)
2455 ERR("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
2456 SetLastError(dwError
);