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 *****************************************************************/
25 SVCCTL_HANDLEA_bind(SVCCTL_HANDLEA szMachineName
)
27 handle_t hBinding
= NULL
;
28 UCHAR
*pszStringBinding
;
31 TRACE("SVCCTL_HANDLEA_bind() called\n");
33 status
= RpcStringBindingComposeA(NULL
,
35 (UCHAR
*)szMachineName
,
36 (UCHAR
*)"\\pipe\\ntsvcs",
38 (UCHAR
**)&pszStringBinding
);
39 if (status
!= RPC_S_OK
)
41 ERR("RpcStringBindingCompose returned 0x%x\n", status
);
45 /* Set the binding handle that will be used to bind to the server. */
46 status
= RpcBindingFromStringBindingA(pszStringBinding
,
48 if (status
!= RPC_S_OK
)
50 ERR("RpcBindingFromStringBinding returned 0x%x\n", status
);
53 status
= RpcStringFreeA(&pszStringBinding
);
54 if (status
!= RPC_S_OK
)
56 ERR("RpcStringFree returned 0x%x\n", status
);
64 SVCCTL_HANDLEA_unbind(SVCCTL_HANDLEA szMachineName
,
69 TRACE("SVCCTL_HANDLEA_unbind() called\n");
71 status
= RpcBindingFree(&hBinding
);
72 if (status
!= RPC_S_OK
)
74 ERR("RpcBindingFree returned 0x%x\n", status
);
80 SVCCTL_HANDLEW_bind(SVCCTL_HANDLEW szMachineName
)
82 handle_t hBinding
= NULL
;
83 LPWSTR pszStringBinding
;
86 TRACE("SVCCTL_HANDLEW_bind() called\n");
88 status
= RpcStringBindingComposeW(NULL
,
94 if (status
!= RPC_S_OK
)
96 ERR("RpcStringBindingCompose returned 0x%x\n", status
);
100 /* Set the binding handle that will be used to bind to the server. */
101 status
= RpcBindingFromStringBindingW(pszStringBinding
,
103 if (status
!= RPC_S_OK
)
105 ERR("RpcBindingFromStringBinding returned 0x%x\n", status
);
108 status
= RpcStringFreeW(&pszStringBinding
);
109 if (status
!= RPC_S_OK
)
111 ERR("RpcStringFree returned 0x%x\n", status
);
119 SVCCTL_HANDLEW_unbind(SVCCTL_HANDLEW szMachineName
,
124 TRACE("SVCCTL_HANDLEW_unbind() called\n");
126 status
= RpcBindingFree(&hBinding
);
127 if (status
!= RPC_S_OK
)
129 ERR("RpcBindingFree returned 0x%x\n", status
);
135 RPC_SERVICE_STATUS_HANDLE_bind(RPC_SERVICE_STATUS_HANDLE hServiceStatus
)
137 handle_t hBinding
= NULL
;
138 LPWSTR pszStringBinding
;
141 TRACE("RPC_SERVICE_STATUS_HANDLE_bind() called\n");
143 status
= RpcStringBindingComposeW(NULL
,
149 if (status
!= RPC_S_OK
)
151 ERR("RpcStringBindingCompose returned 0x%x\n", status
);
155 /* Set the binding handle that will be used to bind to the server. */
156 status
= RpcBindingFromStringBindingW(pszStringBinding
,
158 if (status
!= RPC_S_OK
)
160 ERR("RpcBindingFromStringBinding returned 0x%x\n", status
);
163 status
= RpcStringFreeW(&pszStringBinding
);
164 if (status
!= RPC_S_OK
)
166 ERR("RpcStringFree returned 0x%x\n", status
);
174 RPC_SERVICE_STATUS_HANDLE_unbind(RPC_SERVICE_STATUS_HANDLE hServiceStatus
,
179 TRACE("RPC_SERVICE_STATUS_HANDLE_unbind() called\n");
181 status
= RpcBindingFree(&hBinding
);
182 if (status
!= RPC_S_OK
)
184 ERR("RpcBindingFree returned 0x%x\n", status
);
190 ScmRpcStatusToWinError(RPC_STATUS Status
)
194 case RPC_S_INVALID_BINDING
:
195 case RPC_X_SS_IN_NULL_CONTEXT
:
196 return ERROR_INVALID_HANDLE
;
198 case RPC_X_ENUM_VALUE_OUT_OF_RANGE
:
199 case RPC_X_BYTE_COUNT_TOO_SMALL
:
200 return ERROR_INVALID_PARAMETER
;
202 case RPC_X_NULL_REF_POINTER
:
203 return ERROR_INVALID_ADDRESS
;
206 return (DWORD
)Status
;
211 /**********************************************************************
212 * ChangeServiceConfig2A
217 ChangeServiceConfig2A(SC_HANDLE hService
,
221 SC_RPC_CONFIG_INFOA Info
;
224 TRACE("ChangeServiceConfig2A() called\n");
226 /* Fill relevent field of the Info structure */
227 Info
.dwInfoLevel
= dwInfoLevel
;
230 case SERVICE_CONFIG_DESCRIPTION
:
231 Info
.psd
= (LPSERVICE_DESCRIPTIONA
)&lpInfo
;
232 Info
.lpDescription
= ((LPSERVICE_DESCRIPTIONA
)lpInfo
)->lpDescription
; //HACK
235 case SERVICE_CONFIG_FAILURE_ACTIONS
:
236 Info
.psfa
= (LPSERVICE_FAILURE_ACTIONSA
)lpInfo
;
240 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
241 SetLastError(ERROR_INVALID_PARAMETER
);
250 dwError
= RChangeServiceConfig2A((SC_RPC_HANDLE
)hService
,
253 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
255 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
259 if (dwError
!= ERROR_SUCCESS
)
261 ERR("RChangeServiceConfig2A() failed (Error %lu)\n", dwError
);
262 SetLastError(dwError
);
270 /**********************************************************************
271 * ChangeServiceConfig2W
276 ChangeServiceConfig2W(SC_HANDLE hService
,
280 SC_RPC_CONFIG_INFOW Info
;
283 TRACE("ChangeServiceConfig2W() called\n");
285 /* Fill relevent field of the Info structure */
286 Info
.dwInfoLevel
= dwInfoLevel
;
289 case SERVICE_CONFIG_DESCRIPTION
:
290 Info
.psd
= (LPSERVICE_DESCRIPTIONW
)&lpInfo
;
293 case SERVICE_CONFIG_FAILURE_ACTIONS
:
294 Info
.psfa
= (LPSERVICE_FAILURE_ACTIONSW
)&lpInfo
;
298 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
299 SetLastError(ERROR_INVALID_PARAMETER
);
308 dwError
= RChangeServiceConfig2W((SC_RPC_HANDLE
)hService
,
311 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
313 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
317 if (dwError
!= ERROR_SUCCESS
)
319 ERR("RChangeServiceConfig2W() failed (Error %lu)\n", dwError
);
320 SetLastError(dwError
);
328 /**********************************************************************
329 * ChangeServiceConfigA
334 ChangeServiceConfigA(SC_HANDLE hService
,
337 DWORD dwErrorControl
,
338 LPCSTR lpBinaryPathName
,
339 LPCSTR lpLoadOrderGroup
,
341 LPCSTR lpDependencies
,
342 LPCSTR lpServiceStartName
,
344 LPCSTR lpDisplayName
)
347 DWORD dwDependenciesLength
= 0;
351 TRACE("ChangeServiceConfigA() called\n");
353 /* Calculate the Dependencies length*/
354 if (lpDependencies
!= NULL
)
356 lpStr
= (LPSTR
)lpDependencies
;
359 dwLength
= strlen(lpStr
) + 1;
360 dwDependenciesLength
+= dwLength
;
361 lpStr
= lpStr
+ dwLength
;
363 dwDependenciesLength
++;
366 /* FIXME: Encrypt the password */
370 /* Call to services.exe using RPC */
371 dwError
= RChangeServiceConfigA((SC_RPC_HANDLE
)hService
,
375 (LPSTR
)lpBinaryPathName
,
376 (LPSTR
)lpLoadOrderGroup
,
378 (LPSTR
)lpDependencies
,
379 dwDependenciesLength
,
380 (LPSTR
)lpServiceStartName
,
381 NULL
, /* FIXME: lpPassword */
382 0, /* FIXME: dwPasswordLength */
383 (LPSTR
)lpDisplayName
);
385 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
387 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
391 if (dwError
!= ERROR_SUCCESS
)
393 ERR("RChangeServiceConfigA() failed (Error %lu)\n", dwError
);
394 SetLastError(dwError
);
402 /**********************************************************************
403 * ChangeServiceConfigW
408 ChangeServiceConfigW(SC_HANDLE hService
,
411 DWORD dwErrorControl
,
412 LPCWSTR lpBinaryPathName
,
413 LPCWSTR lpLoadOrderGroup
,
415 LPCWSTR lpDependencies
,
416 LPCWSTR lpServiceStartName
,
418 LPCWSTR lpDisplayName
)
421 DWORD dwDependenciesLength
= 0;
425 TRACE("ChangeServiceConfigW() called\n");
427 /* Calculate the Dependencies length*/
428 if (lpDependencies
!= NULL
)
430 lpStr
= (LPWSTR
)lpDependencies
;
433 dwLength
= wcslen(lpStr
) + 1;
434 dwDependenciesLength
+= dwLength
;
435 lpStr
= lpStr
+ dwLength
;
437 dwDependenciesLength
++;
440 /* FIXME: Encrypt the password */
444 /* Call to services.exe using RPC */
445 dwError
= RChangeServiceConfigW((SC_RPC_HANDLE
)hService
,
449 (LPWSTR
)lpBinaryPathName
,
450 (LPWSTR
)lpLoadOrderGroup
,
452 (LPBYTE
)lpDependencies
,
453 dwDependenciesLength
,
454 (LPWSTR
)lpServiceStartName
,
455 NULL
, /* FIXME: lpPassword */
456 0, /* FIXME: dwPasswordLength */
457 (LPWSTR
)lpDisplayName
);
459 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
461 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
465 if (dwError
!= ERROR_SUCCESS
)
467 ERR("RChangeServiceConfigW() failed (Error %lu)\n", dwError
);
468 SetLastError(dwError
);
476 /**********************************************************************
482 CloseServiceHandle(SC_HANDLE hSCObject
)
486 TRACE("CloseServiceHandle() called\n");
490 SetLastError(ERROR_INVALID_HANDLE
);
496 /* Call to services.exe using RPC */
497 dwError
= RCloseServiceHandle((LPSC_RPC_HANDLE
)&hSCObject
);
499 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
501 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
507 ERR("RCloseServiceHandle() failed (Error %lu)\n", dwError
);
508 SetLastError(dwError
);
512 TRACE("CloseServiceHandle() done\n");
518 /**********************************************************************
524 ControlService(SC_HANDLE hService
,
526 LPSERVICE_STATUS lpServiceStatus
)
530 TRACE("ControlService(%x, %x, %p)\n",
531 hService
, dwControl
, lpServiceStatus
);
535 /* Call to services.exe using RPC */
536 dwError
= RControlService((SC_RPC_HANDLE
)hService
,
540 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
542 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
546 if (dwError
!= ERROR_SUCCESS
)
548 ERR("RControlService() failed (Error %lu)\n", dwError
);
549 SetLastError(dwError
);
553 TRACE("ControlService() done\n");
559 /**********************************************************************
565 ControlServiceEx(IN SC_HANDLE hService
,
567 IN DWORD dwInfoLevel
,
568 IN OUT PVOID pControlParams
)
570 FIXME("ControlServiceEx(0x%p, 0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n",
571 hService
, dwControl
, dwInfoLevel
, pControlParams
);
572 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
577 /**********************************************************************
583 CreateServiceA(SC_HANDLE hSCManager
,
584 LPCSTR lpServiceName
,
585 LPCSTR lpDisplayName
,
586 DWORD dwDesiredAccess
,
589 DWORD dwErrorControl
,
590 LPCSTR lpBinaryPathName
,
591 LPCSTR lpLoadOrderGroup
,
593 LPCSTR lpDependencies
,
594 LPCSTR lpServiceStartName
,
597 SC_HANDLE hService
= NULL
;
598 DWORD dwDependenciesLength
= 0;
603 TRACE("CreateServiceA() called\n");
604 TRACE("%p %s %s\n", hSCManager
,
605 lpServiceName
, lpDisplayName
);
609 SetLastError(ERROR_INVALID_HANDLE
);
613 /* Calculate the Dependencies length*/
614 if (lpDependencies
!= NULL
)
616 lpStr
= (LPSTR
)lpDependencies
;
619 dwLength
= strlen(lpStr
) + 1;
620 dwDependenciesLength
+= dwLength
;
621 lpStr
= lpStr
+ dwLength
;
623 dwDependenciesLength
++;
626 /* FIXME: Encrypt the password */
630 /* Call to services.exe using RPC */
631 dwError
= RCreateServiceA((SC_RPC_HANDLE
)hSCManager
,
632 (LPSTR
)lpServiceName
,
633 (LPSTR
)lpDisplayName
,
638 (LPSTR
)lpBinaryPathName
,
639 (LPSTR
)lpLoadOrderGroup
,
641 (LPBYTE
)lpDependencies
,
642 dwDependenciesLength
,
643 (LPSTR
)lpServiceStartName
,
644 NULL
, /* FIXME: lpPassword */
645 0, /* FIXME: dwPasswordLength */
646 (SC_RPC_HANDLE
*)&hService
);
648 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
650 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
654 if (dwError
!= ERROR_SUCCESS
)
656 ERR("RCreateServiceA() failed (Error %lu)\n", dwError
);
657 SetLastError(dwError
);
665 /**********************************************************************
671 CreateServiceW(SC_HANDLE hSCManager
,
672 LPCWSTR lpServiceName
,
673 LPCWSTR lpDisplayName
,
674 DWORD dwDesiredAccess
,
677 DWORD dwErrorControl
,
678 LPCWSTR lpBinaryPathName
,
679 LPCWSTR lpLoadOrderGroup
,
681 LPCWSTR lpDependencies
,
682 LPCWSTR lpServiceStartName
,
685 SC_HANDLE hService
= NULL
;
686 DWORD dwDependenciesLength
= 0;
691 TRACE("CreateServiceW() called\n");
692 TRACE("%p %S %S\n", hSCManager
,
693 lpServiceName
, lpDisplayName
);
697 SetLastError(ERROR_INVALID_HANDLE
);
701 /* Calculate the Dependencies length*/
702 if (lpDependencies
!= NULL
)
704 lpStr
= (LPWSTR
)lpDependencies
;
707 dwLength
= wcslen(lpStr
) + 1;
708 dwDependenciesLength
+= dwLength
;
709 lpStr
= lpStr
+ dwLength
;
711 dwDependenciesLength
++;
713 dwDependenciesLength
*= sizeof(WCHAR
);
716 /* FIXME: Encrypt the password */
720 /* Call to services.exe using RPC */
721 dwError
= RCreateServiceW((SC_RPC_HANDLE
)hSCManager
,
731 (LPBYTE
)lpDependencies
,
732 dwDependenciesLength
,
734 NULL
, /* FIXME: lpPassword */
735 0, /* FIXME: dwPasswordLength */
736 (SC_RPC_HANDLE
*)&hService
);
738 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
740 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
744 if (dwError
!= ERROR_SUCCESS
)
746 ERR("RCreateServiceW() failed (Error %lu)\n", dwError
);
747 SetLastError(dwError
);
755 /**********************************************************************
761 DeleteService(SC_HANDLE hService
)
765 TRACE("DeleteService(%x)\n", hService
);
769 /* Call to services.exe using RPC */
770 dwError
= RDeleteService((SC_RPC_HANDLE
)hService
);
772 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
774 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
778 if (dwError
!= ERROR_SUCCESS
)
780 ERR("RDeleteService() failed (Error %lu)\n", dwError
);
781 SetLastError(dwError
);
789 /**********************************************************************
790 * EnumDependentServicesA
795 EnumDependentServicesA(SC_HANDLE hService
,
796 DWORD dwServiceState
,
797 LPENUM_SERVICE_STATUSA lpServices
,
799 LPDWORD pcbBytesNeeded
,
800 LPDWORD lpServicesReturned
)
802 LPENUM_SERVICE_STATUSA lpStatusPtr
;
806 TRACE("EnumServicesStatusA() called\n");
810 dwError
= REnumDependentServicesA((SC_RPC_HANDLE
)hService
,
817 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
819 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
823 if (dwError
!= ERROR_SUCCESS
)
825 ERR("REnumDependentServicesA() failed (Error %lu)\n", dwError
);
826 SetLastError(dwError
);
830 lpStatusPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
831 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
833 if (lpStatusPtr
->lpServiceName
)
834 lpStatusPtr
->lpServiceName
=
835 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
837 if (lpStatusPtr
->lpDisplayName
)
838 lpStatusPtr
->lpDisplayName
=
839 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
844 TRACE("EnumDependentServicesA() done\n");
850 /**********************************************************************
851 * EnumDependentServicesW
856 EnumDependentServicesW(SC_HANDLE hService
,
857 DWORD dwServiceState
,
858 LPENUM_SERVICE_STATUSW lpServices
,
860 LPDWORD pcbBytesNeeded
,
861 LPDWORD lpServicesReturned
)
863 LPENUM_SERVICE_STATUSW lpStatusPtr
;
867 TRACE("EnumServicesStatusW() called\n");
871 dwError
= REnumDependentServicesW((SC_RPC_HANDLE
)hService
,
878 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
880 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
884 if (dwError
!= ERROR_SUCCESS
)
886 ERR("REnumDependentServicesW() failed (Error %lu)\n", dwError
);
887 SetLastError(dwError
);
891 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
892 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
894 if (lpStatusPtr
->lpServiceName
)
895 lpStatusPtr
->lpServiceName
=
896 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
898 if (lpStatusPtr
->lpDisplayName
)
899 lpStatusPtr
->lpDisplayName
=
900 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
905 TRACE("EnumDependentServicesW() done\n");
911 /**********************************************************************
919 SC_HANDLE hSCManager
,
921 DWORD dwServiceState
,
922 LPENUM_SERVICE_STATUSW lpServices
,
924 LPDWORD pcbBytesNeeded
,
925 LPDWORD lpServicesReturned
,
926 LPDWORD lpResumeHandle
,
929 FIXME("EnumServiceGroupW is unimplemented\n");
930 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
935 /**********************************************************************
936 * EnumServicesStatusA
941 EnumServicesStatusA(SC_HANDLE hSCManager
,
943 DWORD dwServiceState
,
944 LPENUM_SERVICE_STATUSA lpServices
,
946 LPDWORD pcbBytesNeeded
,
947 LPDWORD lpServicesReturned
,
948 LPDWORD lpResumeHandle
)
950 LPENUM_SERVICE_STATUSA lpStatusPtr
;
954 TRACE("EnumServicesStatusA() called\n");
958 SetLastError(ERROR_INVALID_HANDLE
);
962 if (dwServiceType
!= SERVICE_DRIVER
&& dwServiceType
!= SERVICE_WIN32
)
964 if (pcbBytesNeeded
&& lpServicesReturned
)
967 *lpServicesReturned
= 0;
970 SetLastError(ERROR_INVALID_PARAMETER
);
974 if (dwServiceState
!= SERVICE_ACTIVE
&& dwServiceState
!= SERVICE_INACTIVE
&& dwServiceState
!= SERVICE_STATE_ALL
)
979 if (lpServicesReturned
)
980 *lpServicesReturned
= 0;
982 SetLastError(ERROR_INVALID_PARAMETER
);
986 if (!pcbBytesNeeded
|| !lpServicesReturned
)
988 SetLastError(ERROR_INVALID_ADDRESS
);
992 if (!lpServices
&& cbBufSize
!= 0)
994 SetLastError(ERROR_INVALID_ADDRESS
);
1000 dwError
= REnumServicesStatusA((SC_RPC_HANDLE
)hSCManager
,
1009 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1011 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1015 if (dwError
!= ERROR_SUCCESS
)
1017 ERR("REnumServicesStatusA() failed (Error %lu)\n", dwError
);
1018 SetLastError(dwError
);
1022 lpStatusPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
1023 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1025 if (lpStatusPtr
->lpServiceName
)
1026 lpStatusPtr
->lpServiceName
=
1027 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1029 if (lpStatusPtr
->lpDisplayName
)
1030 lpStatusPtr
->lpDisplayName
=
1031 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1036 TRACE("EnumServicesStatusA() done\n");
1042 /**********************************************************************
1043 * EnumServicesStatusW
1048 EnumServicesStatusW(SC_HANDLE hSCManager
,
1049 DWORD dwServiceType
,
1050 DWORD dwServiceState
,
1051 LPENUM_SERVICE_STATUSW lpServices
,
1053 LPDWORD pcbBytesNeeded
,
1054 LPDWORD lpServicesReturned
,
1055 LPDWORD lpResumeHandle
)
1057 LPENUM_SERVICE_STATUSW lpStatusPtr
;
1061 TRACE("EnumServicesStatusW() called\n");
1065 SetLastError(ERROR_INVALID_HANDLE
);
1071 dwError
= REnumServicesStatusW((SC_RPC_HANDLE
)hSCManager
,
1080 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1082 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1086 if (dwError
!= ERROR_SUCCESS
)
1088 ERR("REnumServicesStatusW() failed (Error %lu)\n", dwError
);
1089 SetLastError(dwError
);
1093 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
1094 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1096 if (lpStatusPtr
->lpServiceName
)
1097 lpStatusPtr
->lpServiceName
=
1098 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1100 if (lpStatusPtr
->lpDisplayName
)
1101 lpStatusPtr
->lpDisplayName
=
1102 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1107 TRACE("EnumServicesStatusW() done\n");
1113 /**********************************************************************
1114 * EnumServicesStatusExA
1119 EnumServicesStatusExA(SC_HANDLE hSCManager
,
1120 SC_ENUM_TYPE InfoLevel
,
1121 DWORD dwServiceType
,
1122 DWORD dwServiceState
,
1125 LPDWORD pcbBytesNeeded
,
1126 LPDWORD lpServicesReturned
,
1127 LPDWORD lpResumeHandle
,
1128 LPCSTR pszGroupName
)
1130 LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtr
;
1134 TRACE("EnumServicesStatusExA() called\n");
1136 if (InfoLevel
!= SC_ENUM_PROCESS_INFO
)
1138 SetLastError(ERROR_INVALID_LEVEL
);
1144 SetLastError(ERROR_INVALID_HANDLE
);
1151 dwError
= REnumServicesStatusExA((SC_RPC_HANDLE
)hSCManager
,
1160 (LPSTR
)pszGroupName
);
1162 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1164 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1168 if (dwError
== ERROR_MORE_DATA
)
1170 WARN("Required buffer size %ul\n", *pcbBytesNeeded
);
1171 SetLastError(dwError
);
1174 else if (dwError
== ERROR_SUCCESS
)
1176 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpServices
;
1177 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1179 if (lpStatusPtr
->lpServiceName
)
1180 lpStatusPtr
->lpServiceName
=
1181 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1183 if (lpStatusPtr
->lpDisplayName
)
1184 lpStatusPtr
->lpDisplayName
=
1185 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1192 ERR("REnumServicesStatusExA() failed (Error %lu)\n", dwError
);
1193 SetLastError(dwError
);
1197 TRACE("EnumServicesStatusExA() done\n");
1203 /**********************************************************************
1204 * EnumServicesStatusExW
1209 EnumServicesStatusExW(SC_HANDLE hSCManager
,
1210 SC_ENUM_TYPE InfoLevel
,
1211 DWORD dwServiceType
,
1212 DWORD dwServiceState
,
1215 LPDWORD pcbBytesNeeded
,
1216 LPDWORD lpServicesReturned
,
1217 LPDWORD lpResumeHandle
,
1218 LPCWSTR pszGroupName
)
1220 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
1224 TRACE("EnumServicesStatusExW() called\n");
1228 dwError
= REnumServicesStatusExW((SC_RPC_HANDLE
)hSCManager
,
1237 (LPWSTR
)pszGroupName
);
1239 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1241 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1245 if (dwError
== ERROR_MORE_DATA
)
1247 WARN("Required buffer size %ul\n", *pcbBytesNeeded
);
1248 SetLastError(dwError
);
1251 else if (dwError
== ERROR_SUCCESS
)
1253 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpServices
;
1254 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1256 if (lpStatusPtr
->lpServiceName
)
1257 lpStatusPtr
->lpServiceName
=
1258 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1260 if (lpStatusPtr
->lpDisplayName
)
1261 lpStatusPtr
->lpDisplayName
=
1262 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1269 ERR("REnumServicesStatusExW() failed (Error %lu)\n", dwError
);
1270 SetLastError(dwError
);
1274 TRACE("EnumServicesStatusExW() done\n");
1280 /**********************************************************************
1281 * GetServiceDisplayNameA
1286 GetServiceDisplayNameA(SC_HANDLE hSCManager
,
1287 LPCSTR lpServiceName
,
1288 LPSTR lpDisplayName
,
1289 LPDWORD lpcchBuffer
)
1293 TRACE("GetServiceDisplayNameA() called\n");
1294 TRACE("%p %s %p %p\n", hSCManager
,
1295 debugstr_a(lpServiceName
), lpDisplayName
, lpcchBuffer
);
1299 SetLastError(ERROR_INVALID_HANDLE
);
1308 dwError
= RGetServiceDisplayNameA((SC_RPC_HANDLE
)hSCManager
,
1313 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1315 /* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
1316 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1322 if (dwError
!= ERROR_SUCCESS
)
1324 ERR("RGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
1325 SetLastError(dwError
);
1333 /**********************************************************************
1334 * GetServiceDisplayNameW
1339 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
1340 LPCWSTR lpServiceName
,
1341 LPWSTR lpDisplayName
,
1342 LPDWORD lpcchBuffer
)
1346 TRACE("GetServiceDisplayNameW() called\n");
1350 SetLastError(ERROR_INVALID_HANDLE
);
1359 dwError
= RGetServiceDisplayNameW((SC_RPC_HANDLE
)hSCManager
,
1364 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1366 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1370 if (dwError
!= ERROR_SUCCESS
)
1372 ERR("RGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1373 SetLastError(dwError
);
1381 /**********************************************************************
1382 * GetServiceKeyNameA
1387 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1388 LPCSTR lpDisplayName
,
1389 LPSTR lpServiceName
,
1390 LPDWORD lpcchBuffer
)
1394 TRACE("GetServiceKeyNameA() called\n");
1398 SetLastError(ERROR_INVALID_HANDLE
);
1404 SetLastError(ERROR_INVALID_ADDRESS
);
1416 dwError
= RGetServiceKeyNameA((SC_RPC_HANDLE
)hSCManager
,
1421 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1423 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1427 if (dwError
!= ERROR_SUCCESS
)
1429 ERR("RGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1430 SetLastError(dwError
);
1438 /**********************************************************************
1439 * GetServiceKeyNameW
1444 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1445 LPCWSTR lpDisplayName
,
1446 LPWSTR lpServiceName
,
1447 LPDWORD lpcchBuffer
)
1451 TRACE("GetServiceKeyNameW() called\n");
1455 SetLastError(ERROR_INVALID_HANDLE
);
1461 SetLastError(ERROR_INVALID_ADDRESS
);
1473 dwError
= RGetServiceKeyNameW((SC_RPC_HANDLE
)hSCManager
,
1478 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1480 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1484 if (dwError
!= ERROR_SUCCESS
)
1486 ERR("RGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1487 SetLastError(dwError
);
1495 /**********************************************************************
1496 * LockServiceDatabase
1501 LockServiceDatabase(SC_HANDLE hSCManager
)
1506 TRACE("LockServiceDatabase(%x)\n", hSCManager
);
1510 /* Call to services.exe using RPC */
1511 dwError
= RLockServiceDatabase((SC_RPC_HANDLE
)hSCManager
,
1512 (SC_RPC_LOCK
*)&hLock
);
1514 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1516 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1520 if (dwError
!= ERROR_SUCCESS
)
1522 ERR("RLockServiceDatabase() failed (Error %lu)\n", dwError
);
1523 SetLastError(dwError
);
1527 TRACE("hLock = %p\n", hLock
);
1534 WaitForSCManager(VOID
)
1538 TRACE("WaitForSCManager() called\n");
1540 /* Try to open the existing event */
1541 hEvent
= OpenEventW(SYNCHRONIZE
,
1543 L
"SvcctrlStartEvent_A3752DX");
1546 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1549 /* Try to create a new event */
1550 hEvent
= CreateEventW(NULL
,
1553 L
"SvcctrlStartEvent_A3752DX");
1556 /* Try to open the existing event again */
1557 hEvent
= OpenEventW(SYNCHRONIZE
,
1559 L
"SvcctrlStartEvent_A3752DX");
1565 /* Wait for 3 minutes */
1566 WaitForSingleObject(hEvent
, 180000);
1567 CloseHandle(hEvent
);
1569 TRACE("ScmWaitForSCManager() done\n");
1573 /**********************************************************************
1579 OpenSCManagerA(LPCSTR lpMachineName
,
1580 LPCSTR lpDatabaseName
,
1581 DWORD dwDesiredAccess
)
1583 SC_HANDLE hScm
= NULL
;
1586 TRACE("OpenSCManagerA(%s, %s, %lx)\n",
1587 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1593 /* Call to services.exe using RPC */
1594 dwError
= ROpenSCManagerA((LPSTR
)lpMachineName
,
1595 (LPSTR
)lpDatabaseName
,
1597 (SC_RPC_HANDLE
*)&hScm
);
1599 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1601 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1605 if (dwError
!= ERROR_SUCCESS
)
1607 ERR("ROpenSCManagerA() failed (Error %lu)\n", dwError
);
1608 SetLastError(dwError
);
1612 TRACE("hScm = %p\n", hScm
);
1618 /**********************************************************************
1624 OpenSCManagerW(LPCWSTR lpMachineName
,
1625 LPCWSTR lpDatabaseName
,
1626 DWORD dwDesiredAccess
)
1628 SC_HANDLE hScm
= NULL
;
1631 TRACE("OpenSCManagerW(%S, %S, %lx)\n",
1632 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1638 /* Call to services.exe using RPC */
1639 dwError
= ROpenSCManagerW((LPWSTR
)lpMachineName
,
1640 (LPWSTR
)lpDatabaseName
,
1642 (SC_RPC_HANDLE
*)&hScm
);
1644 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1646 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1650 if (dwError
!= ERROR_SUCCESS
)
1652 ERR("ROpenSCManagerW() failed (Error %lu)\n", dwError
);
1653 SetLastError(dwError
);
1657 TRACE("hScm = %p\n", hScm
);
1663 /**********************************************************************
1669 OpenServiceA(SC_HANDLE hSCManager
,
1670 LPCSTR lpServiceName
,
1671 DWORD dwDesiredAccess
)
1673 SC_HANDLE hService
= NULL
;
1676 TRACE("OpenServiceA(%p, %s, %lx)\n",
1677 hSCManager
, lpServiceName
, dwDesiredAccess
);
1681 SetLastError(ERROR_INVALID_HANDLE
);
1687 /* Call to services.exe using RPC */
1688 dwError
= ROpenServiceA((SC_RPC_HANDLE
)hSCManager
,
1689 (LPSTR
)lpServiceName
,
1691 (SC_RPC_HANDLE
*)&hService
);
1693 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1695 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1699 if (dwError
!= ERROR_SUCCESS
)
1701 ERR("ROpenServiceA() failed (Error %lu)\n", dwError
);
1702 SetLastError(dwError
);
1706 TRACE("hService = %p\n", hService
);
1712 /**********************************************************************
1718 OpenServiceW(SC_HANDLE hSCManager
,
1719 LPCWSTR lpServiceName
,
1720 DWORD dwDesiredAccess
)
1722 SC_HANDLE hService
= NULL
;
1725 TRACE("OpenServiceW(%p, %S, %lx)\n",
1726 hSCManager
, lpServiceName
, dwDesiredAccess
);
1730 SetLastError(ERROR_INVALID_HANDLE
);
1736 /* Call to services.exe using RPC */
1737 dwError
= ROpenServiceW((SC_RPC_HANDLE
)hSCManager
,
1738 (LPWSTR
)lpServiceName
,
1740 (SC_RPC_HANDLE
*)&hService
);
1742 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1744 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1748 if (dwError
!= ERROR_SUCCESS
)
1750 if (dwError
== ERROR_SERVICE_DOES_NOT_EXIST
)
1751 WARN("ROpenServiceW() failed (Error %lu)\n", dwError
);
1753 ERR("ROpenServiceW() failed (Error %lu)\n", dwError
);
1754 SetLastError(dwError
);
1758 TRACE("hService = %p\n", hService
);
1764 /**********************************************************************
1765 * QueryServiceConfigA
1770 QueryServiceConfigA(SC_HANDLE hService
,
1771 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
1773 LPDWORD pcbBytesNeeded
)
1777 TRACE("QueryServiceConfigA(%p, %p, %lu, %p)\n",
1778 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1782 /* Call to services.exe using RPC */
1783 dwError
= RQueryServiceConfigA((SC_RPC_HANDLE
)hService
,
1784 (LPBYTE
)lpServiceConfig
,
1788 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1790 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1794 if (dwError
!= ERROR_SUCCESS
)
1796 ERR("RQueryServiceConfigA() failed (Error %lu)\n", dwError
);
1797 SetLastError(dwError
);
1801 /* Adjust the pointers */
1802 if (lpServiceConfig
->lpBinaryPathName
)
1803 lpServiceConfig
->lpBinaryPathName
=
1804 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1805 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1807 if (lpServiceConfig
->lpLoadOrderGroup
)
1808 lpServiceConfig
->lpLoadOrderGroup
=
1809 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1810 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1812 if (lpServiceConfig
->lpDependencies
)
1813 lpServiceConfig
->lpDependencies
=
1814 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1815 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1817 if (lpServiceConfig
->lpServiceStartName
)
1818 lpServiceConfig
->lpServiceStartName
=
1819 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1820 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1822 if (lpServiceConfig
->lpDisplayName
)
1823 lpServiceConfig
->lpDisplayName
=
1824 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1825 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1827 TRACE("QueryServiceConfigA() done\n");
1833 /**********************************************************************
1834 * QueryServiceConfigW
1839 QueryServiceConfigW(SC_HANDLE hService
,
1840 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
1842 LPDWORD pcbBytesNeeded
)
1846 TRACE("QueryServiceConfigW(%p, %p, %lu, %p)\n",
1847 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1851 /* Call to services.exe using RPC */
1852 dwError
= RQueryServiceConfigW((SC_RPC_HANDLE
)hService
,
1853 (LPBYTE
)lpServiceConfig
,
1857 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1859 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1863 if (dwError
!= ERROR_SUCCESS
)
1865 if (dwError
== ERROR_INSUFFICIENT_BUFFER
)
1866 WARN("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1868 ERR("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1869 SetLastError(dwError
);
1873 /* Adjust the pointers */
1874 if (lpServiceConfig
->lpBinaryPathName
)
1875 lpServiceConfig
->lpBinaryPathName
=
1876 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1877 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1879 if (lpServiceConfig
->lpLoadOrderGroup
)
1880 lpServiceConfig
->lpLoadOrderGroup
=
1881 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1882 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1884 if (lpServiceConfig
->lpDependencies
)
1885 lpServiceConfig
->lpDependencies
=
1886 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1887 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1889 if (lpServiceConfig
->lpServiceStartName
)
1890 lpServiceConfig
->lpServiceStartName
=
1891 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1892 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1894 if (lpServiceConfig
->lpDisplayName
)
1895 lpServiceConfig
->lpDisplayName
=
1896 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1897 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1899 TRACE("QueryServiceConfigW() done\n");
1905 /**********************************************************************
1906 * QueryServiceConfig2A
1911 QueryServiceConfig2A(SC_HANDLE hService
,
1915 LPDWORD pcbBytesNeeded
)
1919 DbgPrint("QueryServiceConfig2A(hService %p, dwInfoLevel %lu, lpBuffer %p, cbBufSize %lu, pcbBytesNeeded %p)\n",
1920 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1922 if (dwInfoLevel
!= SERVICE_CONFIG_DESCRIPTION
&&
1923 dwInfoLevel
!= SERVICE_CONFIG_FAILURE_ACTIONS
)
1925 SetLastError(ERROR_INVALID_LEVEL
);
1929 if ((lpBuffer
== NULL
&& cbBufSize
!= 0) ||
1930 pcbBytesNeeded
== NULL
)
1932 SetLastError(ERROR_INVALID_ADDRESS
);
1938 /* Call to services.exe using RPC */
1939 dwError
= RQueryServiceConfig2A((SC_RPC_HANDLE
)hService
,
1945 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1947 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1951 if (dwError
!= ERROR_SUCCESS
)
1953 ERR("RQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
1954 SetLastError(dwError
);
1958 switch (dwInfoLevel
)
1960 case SERVICE_CONFIG_DESCRIPTION
:
1962 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
1964 if (lpPtr
->lpDescription
!= NULL
)
1965 lpPtr
->lpDescription
=
1966 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1970 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1972 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpBuffer
;
1974 if (lpPtr
->lpRebootMsg
!= NULL
)
1975 lpPtr
->lpRebootMsg
=
1976 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1978 if (lpPtr
->lpCommand
!= NULL
)
1980 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1982 if (lpPtr
->lpsaActions
!= NULL
)
1983 lpPtr
->lpsaActions
=
1984 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1989 ERR("Unknown info level 0x%lx\n", dwInfoLevel
);
1990 SetLastError(ERROR_INVALID_PARAMETER
);
1994 TRACE("QueryServiceConfig2A() done\n");
2000 /**********************************************************************
2001 * QueryServiceConfig2W
2006 QueryServiceConfig2W(SC_HANDLE hService
,
2010 LPDWORD pcbBytesNeeded
)
2014 TRACE("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
2015 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2017 if (dwInfoLevel
!= SERVICE_CONFIG_DESCRIPTION
&&
2018 dwInfoLevel
!= SERVICE_CONFIG_FAILURE_ACTIONS
)
2020 SetLastError(ERROR_INVALID_LEVEL
);
2024 if ((lpBuffer
== NULL
&& cbBufSize
!= 0) ||
2025 pcbBytesNeeded
== NULL
)
2027 SetLastError(ERROR_INVALID_ADDRESS
);
2033 /* Call to services.exe using RPC */
2034 dwError
= RQueryServiceConfig2W((SC_RPC_HANDLE
)hService
,
2040 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2042 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2046 if (dwError
!= ERROR_SUCCESS
)
2048 ERR("RQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
2049 SetLastError(dwError
);
2053 switch (dwInfoLevel
)
2055 case SERVICE_CONFIG_DESCRIPTION
:
2057 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
2059 if (lpPtr
->lpDescription
!= NULL
)
2060 lpPtr
->lpDescription
=
2061 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
2065 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2067 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
2069 if (lpPtr
->lpRebootMsg
!= NULL
)
2070 lpPtr
->lpRebootMsg
=
2071 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
2073 if (lpPtr
->lpCommand
!= NULL
)
2075 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
2077 if (lpPtr
->lpsaActions
!= NULL
)
2078 lpPtr
->lpsaActions
=
2079 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
2084 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
2085 SetLastError(ERROR_INVALID_PARAMETER
);
2089 TRACE("QueryServiceConfig2W() done\n");
2095 /**********************************************************************
2096 * QueryServiceLockStatusA
2101 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
2102 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
2104 LPDWORD pcbBytesNeeded
)
2108 TRACE("QueryServiceLockStatusA() called\n");
2112 /* Call to services.exe using RPC */
2113 dwError
= RQueryServiceLockStatusA((SC_RPC_HANDLE
)hSCManager
,
2118 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2120 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2124 if (dwError
!= ERROR_SUCCESS
)
2126 ERR("RQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
2127 SetLastError(dwError
);
2131 if (lpLockStatus
->lpLockOwner
!= NULL
)
2133 lpLockStatus
->lpLockOwner
=
2134 (LPSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
2137 TRACE("QueryServiceLockStatusA() done\n");
2143 /**********************************************************************
2144 * QueryServiceLockStatusW
2149 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
2150 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
2152 LPDWORD pcbBytesNeeded
)
2156 TRACE("QueryServiceLockStatusW() called\n");
2160 /* Call to services.exe using RPC */
2161 dwError
= RQueryServiceLockStatusW((SC_RPC_HANDLE
)hSCManager
,
2166 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2168 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2172 if (dwError
!= ERROR_SUCCESS
)
2174 ERR("RQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
2175 SetLastError(dwError
);
2179 if (lpLockStatus
->lpLockOwner
!= NULL
)
2181 lpLockStatus
->lpLockOwner
=
2182 (LPWSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
2185 TRACE("QueryServiceLockStatusW() done\n");
2191 /**********************************************************************
2192 * QueryServiceObjectSecurity
2197 QueryServiceObjectSecurity(SC_HANDLE hService
,
2198 SECURITY_INFORMATION dwSecurityInformation
,
2199 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
2201 LPDWORD pcbBytesNeeded
)
2205 TRACE("QueryServiceObjectSecurity(%p, %lu, %p)\n",
2206 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2210 /* Call to services.exe using RPC */
2211 dwError
= RQueryServiceObjectSecurity((SC_RPC_HANDLE
)hService
,
2212 dwSecurityInformation
,
2213 (LPBYTE
)lpSecurityDescriptor
,
2217 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2219 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2223 if (dwError
!= ERROR_SUCCESS
)
2225 ERR("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2226 SetLastError(dwError
);
2233 /**********************************************************************
2234 * SetServiceObjectSecurity
2239 SetServiceObjectSecurity(SC_HANDLE hService
,
2240 SECURITY_INFORMATION dwSecurityInformation
,
2241 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
2243 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
2249 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2252 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
2254 SetLastError(ERROR_INVALID_PARAMETER
);
2258 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
2259 if (SelfRelativeSD
== NULL
)
2261 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2265 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2268 if (!NT_SUCCESS(Status
))
2270 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2271 SetLastError(RtlNtStatusToDosError(Status
));
2277 /* Call to services.exe using RPC */
2278 dwError
= RSetServiceObjectSecurity((SC_RPC_HANDLE
)hService
,
2279 dwSecurityInformation
,
2280 (LPBYTE
)SelfRelativeSD
,
2283 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2285 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2289 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2291 if (dwError
!= ERROR_SUCCESS
)
2293 ERR("RServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2294 SetLastError(dwError
);
2302 /**********************************************************************
2303 * QueryServiceStatus
2308 QueryServiceStatus(SC_HANDLE hService
,
2309 LPSERVICE_STATUS lpServiceStatus
)
2313 TRACE("QueryServiceStatus(%p, %p)\n",
2314 hService
, lpServiceStatus
);
2318 SetLastError(ERROR_INVALID_HANDLE
);
2324 /* Call to services.exe using RPC */
2325 dwError
= RQueryServiceStatus((SC_RPC_HANDLE
)hService
,
2328 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2330 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2334 if (dwError
!= ERROR_SUCCESS
)
2336 ERR("RQueryServiceStatus() failed (Error %lu)\n", dwError
);
2337 SetLastError(dwError
);
2345 /**********************************************************************
2346 * QueryServiceStatusEx
2351 QueryServiceStatusEx(SC_HANDLE hService
,
2352 SC_STATUS_TYPE InfoLevel
,
2355 LPDWORD pcbBytesNeeded
)
2359 TRACE("QueryServiceStatusEx() called\n");
2361 if (InfoLevel
!= SC_STATUS_PROCESS_INFO
)
2363 SetLastError(ERROR_INVALID_LEVEL
);
2369 /* Call to services.exe using RPC */
2370 dwError
= RQueryServiceStatusEx((SC_RPC_HANDLE
)hService
,
2376 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2378 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2382 if (dwError
!= ERROR_SUCCESS
)
2384 ERR("RQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
2385 SetLastError(dwError
);
2393 /**********************************************************************
2399 StartServiceA(SC_HANDLE hService
,
2400 DWORD dwNumServiceArgs
,
2401 LPCSTR
*lpServiceArgVectors
)
2407 dwError
= RStartServiceA((SC_RPC_HANDLE
)hService
,
2409 (LPSTRING_PTRSA
)lpServiceArgVectors
);
2411 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2413 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2417 if (dwError
!= ERROR_SUCCESS
)
2419 ERR("RStartServiceA() failed (Error %lu)\n", dwError
);
2420 SetLastError(dwError
);
2428 /**********************************************************************
2434 StartServiceW(SC_HANDLE hService
,
2435 DWORD dwNumServiceArgs
,
2436 LPCWSTR
*lpServiceArgVectors
)
2442 dwError
= RStartServiceW((SC_RPC_HANDLE
)hService
,
2444 (LPSTRING_PTRSW
)lpServiceArgVectors
);
2446 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2448 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2452 if (dwError
!= ERROR_SUCCESS
)
2454 ERR("RStartServiceW() failed (Error %lu)\n", dwError
);
2455 SetLastError(dwError
);
2463 /**********************************************************************
2464 * UnlockServiceDatabase
2469 UnlockServiceDatabase(SC_LOCK ScLock
)
2473 TRACE("UnlockServiceDatabase(%x)\n", ScLock
);
2477 /* Call to services.exe using RPC */
2478 dwError
= RUnlockServiceDatabase((LPSC_RPC_LOCK
)&ScLock
);
2480 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2482 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2486 if (dwError
!= ERROR_SUCCESS
)
2488 ERR("RUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2489 SetLastError(dwError
);
2497 /**********************************************************************
2498 * NotifyBootConfigStatus
2503 NotifyBootConfigStatus(BOOL BootAcceptable
)
2507 TRACE("NotifyBootConfigStatus()\n");
2511 /* Call to services.exe using RPC */
2512 dwError
= RNotifyBootConfigStatus(NULL
,
2515 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2517 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2521 if (dwError
!= ERROR_SUCCESS
)
2523 ERR("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
2524 SetLastError(dwError
);