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");
1234 dwError
= RGetServiceDisplayNameA(BindingHandle
,
1235 (SC_RPC_HANDLE
)hSCManager
,
1236 (LPSTR
)lpServiceName
,
1242 /* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
1243 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1249 if (dwError
!= ERROR_SUCCESS
)
1251 ERR("RGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
1252 SetLastError(dwError
);
1262 /**********************************************************************
1263 * GetServiceDisplayNameW
1268 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
1269 LPCWSTR lpServiceName
,
1270 LPWSTR lpDisplayName
,
1271 LPDWORD lpcchBuffer
)
1275 TRACE("GetServiceDisplayNameW() called\n");
1281 dwError
= RGetServiceDisplayNameW(BindingHandle
,
1282 (SC_RPC_HANDLE
)hSCManager
,
1283 (LPWSTR
)lpServiceName
,
1289 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1293 if (dwError
!= ERROR_SUCCESS
)
1295 ERR("RGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1296 SetLastError(dwError
);
1306 /**********************************************************************
1307 * GetServiceKeyNameA
1312 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1313 LPCSTR lpDisplayName
,
1314 LPSTR lpServiceName
,
1315 LPDWORD lpcchBuffer
)
1319 TRACE("GetServiceKeyNameA() called\n");
1325 dwError
= RGetServiceKeyNameA(BindingHandle
,
1326 (SC_RPC_HANDLE
)hSCManager
,
1327 (LPSTR
)lpDisplayName
,
1333 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1337 if (dwError
!= ERROR_SUCCESS
)
1339 ERR("RGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1340 SetLastError(dwError
);
1350 /**********************************************************************
1351 * GetServiceKeyNameW
1356 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1357 LPCWSTR lpDisplayName
,
1358 LPWSTR lpServiceName
,
1359 LPDWORD lpcchBuffer
)
1363 TRACE("GetServiceKeyNameW() called\n");
1369 dwError
= RGetServiceKeyNameW(BindingHandle
,
1370 (SC_RPC_HANDLE
)hSCManager
,
1371 (LPWSTR
)lpDisplayName
,
1377 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1381 if (dwError
!= ERROR_SUCCESS
)
1383 ERR("RGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1384 SetLastError(dwError
);
1394 /**********************************************************************
1395 * LockServiceDatabase
1400 LockServiceDatabase(SC_HANDLE hSCManager
)
1405 TRACE("LockServiceDatabase(%x)\n", hSCManager
);
1411 /* Call to services.exe using RPC */
1412 dwError
= RLockServiceDatabase(BindingHandle
,
1413 (SC_RPC_HANDLE
)hSCManager
,
1414 (SC_RPC_LOCK
*)&hLock
);
1418 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1422 if (dwError
!= ERROR_SUCCESS
)
1424 ERR("RLockServiceDatabase() failed (Error %lu)\n", dwError
);
1425 SetLastError(dwError
);
1429 TRACE("hLock = %p\n", hLock
);
1436 WaitForSCManager(VOID
)
1440 TRACE("WaitForSCManager() called\n");
1442 /* Try to open the existing event */
1443 hEvent
= OpenEventW(SYNCHRONIZE
,
1445 L
"SvcctrlStartEvent_A3752DX");
1448 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1451 /* Try to create a new event */
1452 hEvent
= CreateEventW(NULL
,
1455 L
"SvcctrlStartEvent_A3752DX");
1458 /* Try to open the existing event again */
1459 hEvent
= OpenEventW(SYNCHRONIZE
,
1461 L
"SvcctrlStartEvent_A3752DX");
1467 /* Wait for 3 minutes */
1468 WaitForSingleObject(hEvent
, 180000);
1469 CloseHandle(hEvent
);
1471 TRACE("ScmWaitForSCManager() done\n");
1475 /**********************************************************************
1481 OpenSCManagerA(LPCSTR lpMachineName
,
1482 LPCSTR lpDatabaseName
,
1483 DWORD dwDesiredAccess
)
1485 SC_HANDLE hScm
= NULL
;
1488 TRACE("OpenSCManagerA(%s, %s, %lx)\n",
1489 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1497 /* Call to services.exe using RPC */
1498 dwError
= ROpenSCManagerA(BindingHandle
,
1499 (LPSTR
)lpMachineName
,
1500 (LPSTR
)lpDatabaseName
,
1502 (SC_RPC_HANDLE
*)&hScm
);
1506 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1510 if (dwError
!= ERROR_SUCCESS
)
1512 ERR("ROpenSCManagerA() failed (Error %lu)\n", dwError
);
1513 SetLastError(dwError
);
1517 TRACE("hScm = %p\n", hScm
);
1523 /**********************************************************************
1529 OpenSCManagerW(LPCWSTR lpMachineName
,
1530 LPCWSTR lpDatabaseName
,
1531 DWORD dwDesiredAccess
)
1533 SC_HANDLE hScm
= NULL
;
1536 TRACE("OpenSCManagerW(%S, %S, %lx)\n",
1537 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1545 /* Call to services.exe using RPC */
1546 dwError
= ROpenSCManagerW(BindingHandle
,
1547 (LPWSTR
)lpMachineName
,
1548 (LPWSTR
)lpDatabaseName
,
1550 (SC_RPC_HANDLE
*)&hScm
);
1554 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1558 if (dwError
!= ERROR_SUCCESS
)
1560 ERR("ROpenSCManagerW() failed (Error %lu)\n", dwError
);
1561 SetLastError(dwError
);
1565 TRACE("hScm = %p\n", hScm
);
1571 /**********************************************************************
1577 OpenServiceA(SC_HANDLE hSCManager
,
1578 LPCSTR lpServiceName
,
1579 DWORD dwDesiredAccess
)
1581 SC_HANDLE hService
= NULL
;
1584 TRACE("OpenServiceA(%p, %s, %lx)\n",
1585 hSCManager
, lpServiceName
, dwDesiredAccess
);
1591 /* Call to services.exe using RPC */
1592 dwError
= ROpenServiceA(BindingHandle
,
1593 (SC_RPC_HANDLE
)hSCManager
,
1594 (LPSTR
)lpServiceName
,
1596 (SC_RPC_HANDLE
*)&hService
);
1600 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1604 if (dwError
!= ERROR_SUCCESS
)
1606 ERR("ROpenServiceA() failed (Error %lu)\n", dwError
);
1607 SetLastError(dwError
);
1611 TRACE("hService = %p\n", hService
);
1617 /**********************************************************************
1623 OpenServiceW(SC_HANDLE hSCManager
,
1624 LPCWSTR lpServiceName
,
1625 DWORD dwDesiredAccess
)
1627 SC_HANDLE hService
= NULL
;
1630 TRACE("OpenServiceW(%p, %S, %lx)\n",
1631 hSCManager
, lpServiceName
, dwDesiredAccess
);
1637 /* Call to services.exe using RPC */
1638 dwError
= ROpenServiceW(BindingHandle
,
1639 (SC_RPC_HANDLE
)hSCManager
,
1640 (LPWSTR
)lpServiceName
,
1642 (SC_RPC_HANDLE
*)&hService
);
1646 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1650 if (dwError
!= ERROR_SUCCESS
)
1652 if (dwError
== ERROR_SERVICE_DOES_NOT_EXIST
)
1653 WARN("ROpenServiceW() failed (Error %lu)\n", dwError
);
1655 ERR("ROpenServiceW() failed (Error %lu)\n", dwError
);
1656 SetLastError(dwError
);
1660 TRACE("hService = %p\n", hService
);
1666 /**********************************************************************
1667 * QueryServiceConfigA
1672 QueryServiceConfigA(SC_HANDLE hService
,
1673 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
1675 LPDWORD pcbBytesNeeded
)
1679 TRACE("QueryServiceConfigA(%p, %p, %lu, %p)\n",
1680 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1686 /* Call to services.exe using RPC */
1687 dwError
= RQueryServiceConfigA(BindingHandle
,
1688 (SC_RPC_HANDLE
)hService
,
1689 (LPBYTE
)lpServiceConfig
,
1695 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1699 if (dwError
!= ERROR_SUCCESS
)
1701 ERR("RQueryServiceConfigA() failed (Error %lu)\n", dwError
);
1702 SetLastError(dwError
);
1706 /* Adjust the pointers */
1707 if (lpServiceConfig
->lpBinaryPathName
)
1708 lpServiceConfig
->lpBinaryPathName
=
1709 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1710 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1712 if (lpServiceConfig
->lpLoadOrderGroup
)
1713 lpServiceConfig
->lpLoadOrderGroup
=
1714 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1715 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1717 if (lpServiceConfig
->lpDependencies
)
1718 lpServiceConfig
->lpDependencies
=
1719 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1720 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1722 if (lpServiceConfig
->lpServiceStartName
)
1723 lpServiceConfig
->lpServiceStartName
=
1724 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1725 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1727 if (lpServiceConfig
->lpDisplayName
)
1728 lpServiceConfig
->lpDisplayName
=
1729 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1730 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1732 TRACE("QueryServiceConfigA() done\n");
1738 /**********************************************************************
1739 * QueryServiceConfigW
1744 QueryServiceConfigW(SC_HANDLE hService
,
1745 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
1747 LPDWORD pcbBytesNeeded
)
1751 TRACE("QueryServiceConfigW(%p, %p, %lu, %p)\n",
1752 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1758 /* Call to services.exe using RPC */
1759 dwError
= RQueryServiceConfigW(BindingHandle
,
1760 (SC_RPC_HANDLE
)hService
,
1761 (LPBYTE
)lpServiceConfig
,
1767 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1771 if (dwError
!= ERROR_SUCCESS
)
1773 if (dwError
== ERROR_INSUFFICIENT_BUFFER
)
1774 WARN("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1776 ERR("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1777 SetLastError(dwError
);
1781 /* Adjust the pointers */
1782 if (lpServiceConfig
->lpBinaryPathName
)
1783 lpServiceConfig
->lpBinaryPathName
=
1784 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1785 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1787 if (lpServiceConfig
->lpLoadOrderGroup
)
1788 lpServiceConfig
->lpLoadOrderGroup
=
1789 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1790 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1792 if (lpServiceConfig
->lpDependencies
)
1793 lpServiceConfig
->lpDependencies
=
1794 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1795 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1797 if (lpServiceConfig
->lpServiceStartName
)
1798 lpServiceConfig
->lpServiceStartName
=
1799 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1800 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1802 if (lpServiceConfig
->lpDisplayName
)
1803 lpServiceConfig
->lpDisplayName
=
1804 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1805 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1807 TRACE("QueryServiceConfigW() done\n");
1813 /**********************************************************************
1814 * QueryServiceConfig2A
1819 QueryServiceConfig2A(SC_HANDLE hService
,
1823 LPDWORD pcbBytesNeeded
)
1827 TRACE("QueryServiceConfig2A(%p, %lu, %p, %lu, %p)\n",
1828 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1834 /* Call to services.exe using RPC */
1835 dwError
= RQueryServiceConfig2A(BindingHandle
,
1836 (SC_RPC_HANDLE
)hService
,
1844 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1848 if (dwError
!= ERROR_SUCCESS
)
1850 ERR("RQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
1851 SetLastError(dwError
);
1855 switch (dwInfoLevel
)
1857 case SERVICE_CONFIG_DESCRIPTION
:
1859 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
1861 if (lpPtr
->lpDescription
!= NULL
)
1862 lpPtr
->lpDescription
=
1863 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1867 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1869 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpBuffer
;
1871 if (lpPtr
->lpRebootMsg
!= NULL
)
1872 lpPtr
->lpRebootMsg
=
1873 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1875 if (lpPtr
->lpCommand
!= NULL
)
1877 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1879 if (lpPtr
->lpsaActions
!= NULL
)
1880 lpPtr
->lpsaActions
=
1881 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1886 ERR("Unknown info level 0x%lx\n", dwInfoLevel
);
1887 SetLastError(ERROR_INVALID_PARAMETER
);
1891 TRACE("QueryServiceConfig2A() done\n");
1897 /**********************************************************************
1898 * QueryServiceConfig2W
1903 QueryServiceConfig2W(SC_HANDLE hService
,
1907 LPDWORD pcbBytesNeeded
)
1911 TRACE("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
1912 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1918 /* Call to services.exe using RPC */
1919 dwError
= RQueryServiceConfig2W(BindingHandle
,
1920 (SC_RPC_HANDLE
)hService
,
1928 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1932 if (dwError
!= ERROR_SUCCESS
)
1934 ERR("RQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
1935 SetLastError(dwError
);
1939 switch (dwInfoLevel
)
1941 case SERVICE_CONFIG_DESCRIPTION
:
1943 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
1945 if (lpPtr
->lpDescription
!= NULL
)
1946 lpPtr
->lpDescription
=
1947 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1951 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1953 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
1955 if (lpPtr
->lpRebootMsg
!= NULL
)
1956 lpPtr
->lpRebootMsg
=
1957 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1959 if (lpPtr
->lpCommand
!= NULL
)
1961 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1963 if (lpPtr
->lpsaActions
!= NULL
)
1964 lpPtr
->lpsaActions
=
1965 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1970 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
1971 SetLastError(ERROR_INVALID_PARAMETER
);
1975 TRACE("QueryServiceConfig2W() done\n");
1981 /**********************************************************************
1982 * QueryServiceLockStatusA
1987 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
1988 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
1990 LPDWORD pcbBytesNeeded
)
1994 TRACE("QueryServiceLockStatusA() called\n");
2000 /* Call to services.exe using RPC */
2001 dwError
= RQueryServiceLockStatusA(BindingHandle
,
2002 (SC_RPC_HANDLE
)hSCManager
,
2009 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2013 if (dwError
!= ERROR_SUCCESS
)
2015 ERR("RQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
2016 SetLastError(dwError
);
2020 if (lpLockStatus
->lpLockOwner
!= NULL
)
2022 lpLockStatus
->lpLockOwner
=
2023 (LPSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
2026 TRACE("QueryServiceLockStatusA() done\n");
2032 /**********************************************************************
2033 * QueryServiceLockStatusW
2038 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
2039 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
2041 LPDWORD pcbBytesNeeded
)
2045 TRACE("QueryServiceLockStatusW() called\n");
2051 /* Call to services.exe using RPC */
2052 dwError
= RQueryServiceLockStatusW(BindingHandle
,
2053 (SC_RPC_HANDLE
)hSCManager
,
2060 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2064 if (dwError
!= ERROR_SUCCESS
)
2066 ERR("RQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
2067 SetLastError(dwError
);
2071 if (lpLockStatus
->lpLockOwner
!= NULL
)
2073 lpLockStatus
->lpLockOwner
=
2074 (LPWSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
2077 TRACE("QueryServiceLockStatusW() done\n");
2083 /**********************************************************************
2084 * QueryServiceObjectSecurity
2089 QueryServiceObjectSecurity(SC_HANDLE hService
,
2090 SECURITY_INFORMATION dwSecurityInformation
,
2091 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
2093 LPDWORD pcbBytesNeeded
)
2097 TRACE("QueryServiceObjectSecurity(%p, %lu, %p)\n",
2098 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2104 /* Call to services.exe using RPC */
2105 dwError
= RQueryServiceObjectSecurity(BindingHandle
,
2106 (SC_RPC_HANDLE
)hService
,
2107 dwSecurityInformation
,
2108 (LPBYTE
)lpSecurityDescriptor
,
2114 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2118 if (dwError
!= ERROR_SUCCESS
)
2120 ERR("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2121 SetLastError(dwError
);
2128 /**********************************************************************
2129 * SetServiceObjectSecurity
2134 SetServiceObjectSecurity(SC_HANDLE hService
,
2135 SECURITY_INFORMATION dwSecurityInformation
,
2136 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
2138 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
2144 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2147 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
2149 SetLastError(ERROR_INVALID_PARAMETER
);
2153 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
2154 if (SelfRelativeSD
== NULL
)
2156 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2160 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2163 if (!NT_SUCCESS(Status
))
2165 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2166 SetLastError(RtlNtStatusToDosError(Status
));
2174 /* Call to services.exe using RPC */
2175 dwError
= RSetServiceObjectSecurity(BindingHandle
,
2176 (SC_RPC_HANDLE
)hService
,
2177 dwSecurityInformation
,
2178 (LPBYTE
)SelfRelativeSD
,
2183 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2187 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2189 if (dwError
!= ERROR_SUCCESS
)
2191 ERR("RServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2192 SetLastError(dwError
);
2200 /**********************************************************************
2201 * QueryServiceStatus
2206 QueryServiceStatus(SC_HANDLE hService
,
2207 LPSERVICE_STATUS lpServiceStatus
)
2211 TRACE("QueryServiceStatus(%p, %p)\n",
2212 hService
, lpServiceStatus
);
2218 /* Call to services.exe using RPC */
2219 dwError
= RQueryServiceStatus(BindingHandle
,
2220 (SC_RPC_HANDLE
)hService
,
2225 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2229 if (dwError
!= ERROR_SUCCESS
)
2231 ERR("RQueryServiceStatus() failed (Error %lu)\n", dwError
);
2232 SetLastError(dwError
);
2240 /**********************************************************************
2241 * QueryServiceStatusEx
2246 QueryServiceStatusEx(SC_HANDLE hService
,
2247 SC_STATUS_TYPE InfoLevel
,
2250 LPDWORD pcbBytesNeeded
)
2254 TRACE("QueryServiceStatusEx() called\n");
2260 /* Call to services.exe using RPC */
2261 dwError
= RQueryServiceStatusEx(BindingHandle
,
2262 (SC_RPC_HANDLE
)hService
,
2270 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2274 if (dwError
!= ERROR_SUCCESS
)
2276 ERR("RQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
2277 SetLastError(dwError
);
2285 /**********************************************************************
2291 StartServiceA(SC_HANDLE hService
,
2292 DWORD dwNumServiceArgs
,
2293 LPCSTR
*lpServiceArgVectors
)
2299 dwError
= RStartServiceA(BindingHandle
,
2300 (SC_RPC_HANDLE
)hService
,
2302 (LPSTRING_PTRSA
)lpServiceArgVectors
);
2306 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2310 if (dwError
!= ERROR_SUCCESS
)
2312 ERR("RStartServiceA() failed (Error %lu)\n", dwError
);
2313 SetLastError(dwError
);
2321 /**********************************************************************
2327 StartServiceW(SC_HANDLE hService
,
2328 DWORD dwNumServiceArgs
,
2329 LPCWSTR
*lpServiceArgVectors
)
2335 dwError
= RStartServiceW(BindingHandle
,
2336 (SC_RPC_HANDLE
)hService
,
2338 (LPSTRING_PTRSW
)lpServiceArgVectors
);
2342 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2346 if (dwError
!= ERROR_SUCCESS
)
2348 ERR("RStartServiceW() failed (Error %lu)\n", dwError
);
2349 SetLastError(dwError
);
2357 /**********************************************************************
2358 * UnlockServiceDatabase
2363 UnlockServiceDatabase(SC_LOCK ScLock
)
2367 TRACE("UnlockServiceDatabase(%x)\n", ScLock
);
2373 /* Call to services.exe using RPC */
2374 dwError
= RUnlockServiceDatabase(BindingHandle
,
2375 (SC_RPC_LOCK
)ScLock
);
2379 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2383 if (dwError
!= ERROR_SUCCESS
)
2385 ERR("RUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2386 SetLastError(dwError
);
2394 /**********************************************************************
2395 * NotifyBootConfigStatus
2400 NotifyBootConfigStatus(BOOL BootAcceptable
)
2404 TRACE("NotifyBootConfigStatus()\n");
2410 /* Call to services.exe using RPC */
2411 dwError
= RNotifyBootConfigStatus(BindingHandle
,
2417 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2421 if (dwError
!= ERROR_SUCCESS
)
2423 ERR("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
2424 SetLastError(dwError
);