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 ******************************************************************/
20 /* FUNCTIONS *****************************************************************/
22 handle_t BindingHandle
= NULL
;
27 LPWSTR pszStringBinding
;
30 if (BindingHandle
!= NULL
)
33 status
= RpcStringBindingComposeW(NULL
,
41 DPRINT1("RpcStringBindingCompose returned 0x%x\n", status
);
45 /* Set the binding handle that will be used to bind to the server. */
46 status
= RpcBindingFromStringBindingW(pszStringBinding
,
50 DPRINT1("RpcBindingFromStringBinding returned 0x%x\n", status
);
53 status
= RpcStringFreeW(&pszStringBinding
);
56 DPRINT1("RpcStringFree returned 0x%x\n", status
);
67 if (BindingHandle
== NULL
)
70 status
= RpcBindingFree(&BindingHandle
);
73 DPRINT1("RpcBindingFree returned 0x%x\n", status
);
79 /**********************************************************************
80 * ChangeServiceConfig2A
85 ChangeServiceConfig2A(SC_HANDLE hService
,
92 DPRINT("ChangeServiceConfig2A() called\n");
94 /* Determine the length of the lpInfo parameter */
97 case SERVICE_CONFIG_DESCRIPTION
:
98 lpInfoSize
= sizeof(SERVICE_DESCRIPTIONA
);
101 case SERVICE_CONFIG_FAILURE_ACTIONS
:
102 lpInfoSize
= sizeof(SERVICE_FAILURE_ACTIONSA
);
106 DPRINT1("Unknown info level 0x%lx\n", dwInfoLevel
);
107 SetLastError(ERROR_INVALID_PARAMETER
);
116 dwError
= ScmrChangeServiceConfig2A(BindingHandle
,
117 (unsigned int)hService
,
121 if (dwError
!= ERROR_SUCCESS
)
123 DPRINT1("ScmrChangeServiceConfig2A() failed (Error %lu)\n", dwError
);
124 SetLastError(dwError
);
132 /**********************************************************************
133 * ChangeServiceConfig2W
138 ChangeServiceConfig2W(SC_HANDLE hService
,
145 DPRINT("ChangeServiceConfig2W() called\n");
147 /* Determine the length of the lpInfo parameter */
150 case SERVICE_CONFIG_DESCRIPTION
:
151 lpInfoSize
= sizeof(SERVICE_DESCRIPTIONW
);
154 case SERVICE_CONFIG_FAILURE_ACTIONS
:
155 lpInfoSize
= sizeof(SERVICE_FAILURE_ACTIONSW
);
159 DPRINT1("Unknown info level 0x%lx\n", dwInfoLevel
);
160 SetLastError(ERROR_INVALID_PARAMETER
);
169 dwError
= ScmrChangeServiceConfig2W(BindingHandle
,
170 (unsigned int)hService
,
174 if (dwError
!= ERROR_SUCCESS
)
176 DPRINT1("ScmrChangeServiceConfig2W() failed (Error %lu)\n", dwError
);
177 SetLastError(dwError
);
185 /**********************************************************************
186 * ChangeServiceConfigA
191 ChangeServiceConfigA(SC_HANDLE hService
,
194 DWORD dwErrorControl
,
195 LPCSTR lpBinaryPathName
,
196 LPCSTR lpLoadOrderGroup
,
198 LPCSTR lpDependencies
,
199 LPCSTR lpServiceStartName
,
201 LPCSTR lpDisplayName
)
204 DWORD dwDependenciesLength
= 0;
208 DPRINT("ChangeServiceConfigA() called\n");
210 /* Calculate the Dependencies length*/
211 if (lpDependencies
!= NULL
)
213 lpStr
= (LPSTR
)lpDependencies
;
216 dwLength
= strlen(lpStr
) + 1;
217 dwDependenciesLength
+= dwLength
;
218 lpStr
= lpStr
+ dwLength
;
220 dwDependenciesLength
++;
223 /* FIXME: Encrypt the password */
227 /* Call to services.exe using RPC */
228 dwError
= ScmrChangeServiceConfigA(BindingHandle
,
229 (unsigned int)hService
,
233 (LPSTR
)lpBinaryPathName
,
234 (LPSTR
)lpLoadOrderGroup
,
236 (LPSTR
)lpDependencies
,
237 dwDependenciesLength
,
238 (LPSTR
)lpServiceStartName
,
239 NULL
, /* FIXME: lpPassword */
240 0, /* FIXME: dwPasswordLength */
241 (LPSTR
)lpDisplayName
);
242 if (dwError
!= ERROR_SUCCESS
)
244 DPRINT1("ScmrChangeServiceConfigA() failed (Error %lu)\n", dwError
);
245 SetLastError(dwError
);
253 /**********************************************************************
254 * ChangeServiceConfigW
259 ChangeServiceConfigW(SC_HANDLE hService
,
262 DWORD dwErrorControl
,
263 LPCWSTR lpBinaryPathName
,
264 LPCWSTR lpLoadOrderGroup
,
266 LPCWSTR lpDependencies
,
267 LPCWSTR lpServiceStartName
,
269 LPCWSTR lpDisplayName
)
272 DWORD dwDependenciesLength
= 0;
276 DPRINT("ChangeServiceConfigW() called\n");
278 /* Calculate the Dependencies length*/
279 if (lpDependencies
!= NULL
)
281 lpStr
= (LPWSTR
)lpDependencies
;
284 dwLength
= wcslen(lpStr
) + 1;
285 dwDependenciesLength
+= dwLength
;
286 lpStr
= lpStr
+ dwLength
;
288 dwDependenciesLength
++;
291 /* FIXME: Encrypt the password */
295 /* Call to services.exe using RPC */
296 dwError
= ScmrChangeServiceConfigW(BindingHandle
,
297 (unsigned int)hService
,
301 (LPWSTR
)lpBinaryPathName
,
302 (LPWSTR
)lpLoadOrderGroup
,
304 (LPWSTR
)lpDependencies
,
305 dwDependenciesLength
,
306 (LPWSTR
)lpServiceStartName
,
307 NULL
, /* FIXME: lpPassword */
308 0, /* FIXME: dwPasswordLength */
309 (LPWSTR
)lpDisplayName
);
310 if (dwError
!= ERROR_SUCCESS
)
312 DPRINT1("ScmrChangeServiceConfigW() failed (Error %lu)\n", dwError
);
313 SetLastError(dwError
);
321 /**********************************************************************
327 CloseServiceHandle(SC_HANDLE hSCObject
)
331 DPRINT("CloseServiceHandle() called\n");
335 /* Call to services.exe using RPC */
336 dwError
= ScmrCloseServiceHandle(BindingHandle
,
337 (unsigned int)hSCObject
);
340 DPRINT1("ScmrCloseServiceHandle() failed (Error %lu)\n", dwError
);
341 SetLastError(dwError
);
345 DPRINT("CloseServiceHandle() done\n");
351 /**********************************************************************
357 ControlService(SC_HANDLE hService
,
359 LPSERVICE_STATUS lpServiceStatus
)
363 DPRINT("ControlService(%x, %x, %p)\n",
364 hService
, dwControl
, lpServiceStatus
);
368 /* Call to services.exe using RPC */
369 dwError
= ScmrControlService(BindingHandle
,
370 (unsigned int)hService
,
373 if (dwError
!= ERROR_SUCCESS
)
375 DPRINT1("ScmrControlService() failed (Error %lu)\n", dwError
);
376 SetLastError(dwError
);
380 DPRINT("ControlService() done\n");
386 /**********************************************************************
392 ControlServiceEx(IN SC_HANDLE hService
,
394 IN DWORD dwInfoLevel
,
395 IN OUT PVOID pControlParams
)
397 DPRINT1("ControlServiceEx(0x%p, 0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n",
398 hService
, dwControl
, dwInfoLevel
, pControlParams
);
399 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
405 /**********************************************************************
411 CreateServiceA(SC_HANDLE hSCManager
,
412 LPCSTR lpServiceName
,
413 LPCSTR lpDisplayName
,
414 DWORD dwDesiredAccess
,
417 DWORD dwErrorControl
,
418 LPCSTR lpBinaryPathName
,
419 LPCSTR lpLoadOrderGroup
,
421 LPCSTR lpDependencies
,
422 LPCSTR lpServiceStartName
,
425 SC_HANDLE RetVal
= NULL
;
426 LPWSTR lpServiceNameW
= NULL
;
427 LPWSTR lpDisplayNameW
= NULL
;
428 LPWSTR lpBinaryPathNameW
= NULL
;
429 LPWSTR lpLoadOrderGroupW
= NULL
;
430 LPWSTR lpDependenciesW
= NULL
;
431 LPWSTR lpServiceStartNameW
= NULL
;
432 LPWSTR lpPasswordW
= NULL
;
433 DWORD dwDependenciesLength
= 0;
440 len
= MultiByteToWideChar(CP_ACP
, 0, lpServiceName
, -1, NULL
, 0);
441 lpServiceNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
444 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
447 MultiByteToWideChar(CP_ACP
, 0, lpServiceName
, -1, lpServiceNameW
, len
);
452 len
= MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, NULL
, 0);
453 lpDisplayNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
456 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
459 MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, lpDisplayNameW
, len
);
462 if (lpBinaryPathName
)
464 len
= MultiByteToWideChar(CP_ACP
, 0, lpBinaryPathName
, -1, NULL
, 0);
465 lpBinaryPathNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
466 if (!lpBinaryPathNameW
)
468 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
471 MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, lpBinaryPathNameW
, len
);
474 if (lpLoadOrderGroup
)
476 len
= MultiByteToWideChar(CP_ACP
, 0, lpLoadOrderGroup
, -1, NULL
, 0);
477 lpLoadOrderGroupW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
478 if (!lpLoadOrderGroupW
)
480 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
483 MultiByteToWideChar(CP_ACP
, 0, lpLoadOrderGroup
, -1, lpLoadOrderGroupW
, len
);
488 lpStr
= (LPSTR
)lpDependencies
;
491 dwLength
= strlen(lpStr
) + 1;
492 dwDependenciesLength
+= dwLength
;
493 lpStr
= lpStr
+ dwLength
;
495 dwDependenciesLength
++;
497 lpDependenciesW
= HeapAlloc(GetProcessHeap(), 0, dwDependenciesLength
* sizeof(WCHAR
));
498 if (!lpDependenciesW
)
500 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
503 MultiByteToWideChar(CP_ACP
, 0, lpDependencies
, -1, lpDependenciesW
, dwDependenciesLength
);
506 if (lpServiceStartName
)
508 len
= MultiByteToWideChar(CP_ACP
, 0, lpServiceStartName
, -1, NULL
, 0);
509 lpServiceStartName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
510 if (!lpServiceStartNameW
)
512 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
515 MultiByteToWideChar(CP_ACP
, 0, lpServiceStartName
, -1, lpServiceStartNameW
, len
);
520 len
= MultiByteToWideChar(CP_ACP
, 0, lpPassword
, -1, NULL
, 0);
521 lpPasswordW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
524 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
527 MultiByteToWideChar(CP_ACP
, 0, lpPassword
, -1, lpPasswordW
, len
);
530 RetVal
= CreateServiceW(hSCManager
,
545 HeapFree(GetProcessHeap(), 0, lpServiceNameW
);
546 HeapFree(GetProcessHeap(), 0, lpDisplayNameW
);
547 HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW
);
548 HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW
);
549 HeapFree(GetProcessHeap(), 0, lpDependenciesW
);
550 HeapFree(GetProcessHeap(), 0, lpServiceStartNameW
);
551 HeapFree(GetProcessHeap(), 0, lpPasswordW
);
557 /**********************************************************************
563 CreateServiceW(SC_HANDLE hSCManager
,
564 LPCWSTR lpServiceName
,
565 LPCWSTR lpDisplayName
,
566 DWORD dwDesiredAccess
,
569 DWORD dwErrorControl
,
570 LPCWSTR lpBinaryPathName
,
571 LPCWSTR lpLoadOrderGroup
,
573 LPCWSTR lpDependencies
,
574 LPCWSTR lpServiceStartName
,
577 SC_HANDLE hService
= NULL
;
578 DWORD dwDependenciesLength
= 0;
583 DPRINT("CreateServiceW() called\n");
585 /* Calculate the Dependencies length*/
586 if (lpDependencies
!= NULL
)
588 lpStr
= (LPWSTR
)lpDependencies
;
591 dwLength
= wcslen(lpStr
) + 1;
592 dwDependenciesLength
+= dwLength
;
593 lpStr
= lpStr
+ dwLength
;
595 dwDependenciesLength
++;
598 /* FIXME: Encrypt the password */
602 /* Call to services.exe using RPC */
603 dwError
= ScmrCreateServiceW(BindingHandle
,
604 (unsigned int)hSCManager
,
605 (LPWSTR
)lpServiceName
,
606 (LPWSTR
)lpDisplayName
,
611 (LPWSTR
)lpBinaryPathName
,
612 (LPWSTR
)lpLoadOrderGroup
,
614 (LPWSTR
)lpDependencies
,
615 dwDependenciesLength
,
616 (LPWSTR
)lpServiceStartName
,
617 NULL
, /* FIXME: lpPassword */
618 0, /* FIXME: dwPasswordLength */
619 (unsigned int *)&hService
);
620 if (dwError
!= ERROR_SUCCESS
)
622 DPRINT("ScmrCreateServiceW() failed (Error %lu)\n", dwError
);
623 SetLastError(dwError
);
631 /**********************************************************************
637 DeleteService(SC_HANDLE hService
)
641 DPRINT("DeleteService(%x)\n", hService
);
645 /* Call to services.exe using RPC */
646 dwError
= ScmrDeleteService(BindingHandle
,
647 (unsigned int)hService
);
648 if (dwError
!= ERROR_SUCCESS
)
650 DPRINT1("ScmrDeleteService() failed (Error %lu)\n", dwError
);
651 SetLastError(dwError
);
659 /**********************************************************************
660 * EnumDependentServicesA
665 EnumDependentServicesA(SC_HANDLE hService
,
666 DWORD dwServiceState
,
667 LPENUM_SERVICE_STATUSA lpServices
,
669 LPDWORD pcbBytesNeeded
,
670 LPDWORD lpServicesReturned
)
672 LPENUM_SERVICE_STATUSA lpStatusPtr
;
673 DWORD dwError
= ERROR_SUCCESS
;
676 DPRINT("EnumServicesStatusA() called\n");
680 dwError
= ScmrEnumDependentServicesA(BindingHandle
,
681 (unsigned int)hService
,
683 (unsigned char *)lpServices
,
688 lpStatusPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
689 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
691 if (lpStatusPtr
->lpServiceName
)
692 lpStatusPtr
->lpServiceName
=
693 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
695 if (lpStatusPtr
->lpDisplayName
)
696 lpStatusPtr
->lpDisplayName
=
697 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
702 if (dwError
!= ERROR_SUCCESS
)
704 DPRINT("ScmrEnumDependentServicesA() failed (Error %lu)\n", dwError
);
705 SetLastError(dwError
);
709 DPRINT("EnumDependentServicesA() done\n");
715 /**********************************************************************
716 * EnumDependentServicesW
721 EnumDependentServicesW(SC_HANDLE hService
,
722 DWORD dwServiceState
,
723 LPENUM_SERVICE_STATUSW lpServices
,
725 LPDWORD pcbBytesNeeded
,
726 LPDWORD lpServicesReturned
)
728 LPENUM_SERVICE_STATUSW lpStatusPtr
;
729 DWORD dwError
= ERROR_SUCCESS
;
732 DPRINT("EnumServicesStatusW() called\n");
736 dwError
= ScmrEnumDependentServicesW(BindingHandle
,
737 (unsigned int)hService
,
739 (unsigned char *)lpServices
,
744 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
745 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
747 if (lpStatusPtr
->lpServiceName
)
748 lpStatusPtr
->lpServiceName
=
749 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
751 if (lpStatusPtr
->lpDisplayName
)
752 lpStatusPtr
->lpDisplayName
=
753 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
758 if (dwError
!= ERROR_SUCCESS
)
760 DPRINT("ScmrEnumDependentServicesW() failed (Error %lu)\n", dwError
);
761 SetLastError(dwError
);
765 DPRINT("EnumDependentServicesW() done\n");
771 /**********************************************************************
779 SC_HANDLE hSCManager
,
781 DWORD dwServiceState
,
782 LPENUM_SERVICE_STATUSW lpServices
,
784 LPDWORD pcbBytesNeeded
,
785 LPDWORD lpServicesReturned
,
786 LPDWORD lpResumeHandle
,
789 DPRINT1("EnumServiceGroupW is unimplemented\n");
790 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
795 /**********************************************************************
796 * EnumServicesStatusA
801 EnumServicesStatusA(SC_HANDLE hSCManager
,
803 DWORD dwServiceState
,
804 LPENUM_SERVICE_STATUSA lpServices
,
806 LPDWORD pcbBytesNeeded
,
807 LPDWORD lpServicesReturned
,
808 LPDWORD lpResumeHandle
)
810 LPENUM_SERVICE_STATUSA lpStatusPtr
;
811 DWORD dwError
= ERROR_SUCCESS
;
814 DPRINT("EnumServicesStatusA() called\n");
818 dwError
= ScmrEnumServicesStatusA(BindingHandle
,
819 (unsigned int)hSCManager
,
822 (unsigned char *)lpServices
,
828 lpStatusPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
829 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
831 if (lpStatusPtr
->lpServiceName
)
832 lpStatusPtr
->lpServiceName
=
833 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
835 if (lpStatusPtr
->lpDisplayName
)
836 lpStatusPtr
->lpDisplayName
=
837 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
842 if (dwError
!= ERROR_SUCCESS
)
844 DPRINT("ScmrEnumServicesStatusA() failed (Error %lu)\n", dwError
);
845 SetLastError(dwError
);
849 DPRINT("EnumServicesStatusA() done\n");
855 /**********************************************************************
856 * EnumServicesStatusW
861 EnumServicesStatusW(SC_HANDLE hSCManager
,
863 DWORD dwServiceState
,
864 LPENUM_SERVICE_STATUSW lpServices
,
866 LPDWORD pcbBytesNeeded
,
867 LPDWORD lpServicesReturned
,
868 LPDWORD lpResumeHandle
)
870 LPENUM_SERVICE_STATUSW lpStatusPtr
;
871 DWORD dwError
= ERROR_SUCCESS
;
874 DPRINT("EnumServicesStatusW() called\n");
878 dwError
= ScmrEnumServicesStatusW(BindingHandle
,
879 (unsigned int)hSCManager
,
882 (unsigned char *)lpServices
,
888 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
889 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
891 if (lpStatusPtr
->lpServiceName
)
892 lpStatusPtr
->lpServiceName
=
893 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
895 if (lpStatusPtr
->lpDisplayName
)
896 lpStatusPtr
->lpDisplayName
=
897 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
902 if (dwError
!= ERROR_SUCCESS
)
904 DPRINT("ScmrEnumServicesStatusW() failed (Error %lu)\n", dwError
);
905 SetLastError(dwError
);
909 DPRINT("EnumServicesStatusW() done\n");
915 /**********************************************************************
916 * EnumServicesStatusExA
921 EnumServicesStatusExA(SC_HANDLE hSCManager
,
922 SC_ENUM_TYPE InfoLevel
,
924 DWORD dwServiceState
,
927 LPDWORD pcbBytesNeeded
,
928 LPDWORD lpServicesReturned
,
929 LPDWORD lpResumeHandle
,
932 LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtr
;
933 DWORD dwError
= ERROR_SUCCESS
;
936 DPRINT("EnumServicesStatusExA() called\n");
940 dwError
= ScmrEnumServicesStatusExA(BindingHandle
,
941 (unsigned int)hSCManager
,
942 (unsigned long)InfoLevel
,
945 (unsigned char *)lpServices
,
950 (char *)pszGroupName
);
952 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpServices
;
953 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
955 if (lpStatusPtr
->lpServiceName
)
956 lpStatusPtr
->lpServiceName
=
957 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
959 if (lpStatusPtr
->lpDisplayName
)
960 lpStatusPtr
->lpDisplayName
=
961 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
966 if (dwError
!= ERROR_SUCCESS
)
968 DPRINT1("ScmrEnumServicesStatusExA() failed (Error %lu)\n", dwError
);
969 SetLastError(dwError
);
973 DPRINT("EnumServicesStatusExA() done\n");
979 /**********************************************************************
980 * EnumServicesStatusExW
985 EnumServicesStatusExW(SC_HANDLE hSCManager
,
986 SC_ENUM_TYPE InfoLevel
,
988 DWORD dwServiceState
,
991 LPDWORD pcbBytesNeeded
,
992 LPDWORD lpServicesReturned
,
993 LPDWORD lpResumeHandle
,
994 LPCWSTR pszGroupName
)
996 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
997 DWORD dwError
= ERROR_SUCCESS
;
1000 DPRINT("EnumServicesStatusExW() called\n");
1004 dwError
= ScmrEnumServicesStatusExW(BindingHandle
,
1005 (unsigned int)hSCManager
,
1006 (unsigned long)InfoLevel
,
1009 (unsigned char *)lpServices
,
1014 (wchar_t *)pszGroupName
);
1016 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpServices
;
1017 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1019 if (lpStatusPtr
->lpServiceName
)
1020 lpStatusPtr
->lpServiceName
=
1021 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1023 if (lpStatusPtr
->lpDisplayName
)
1024 lpStatusPtr
->lpDisplayName
=
1025 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1030 if (dwError
!= ERROR_SUCCESS
)
1032 DPRINT1("ScmrEnumServicesStatusExW() failed (Error %lu)\n", dwError
);
1033 SetLastError(dwError
);
1037 DPRINT("EnumServicesStatusExW() done\n");
1043 /**********************************************************************
1044 * GetServiceDisplayNameA
1049 GetServiceDisplayNameA(SC_HANDLE hSCManager
,
1050 LPCSTR lpServiceName
,
1051 LPSTR lpDisplayName
,
1052 LPDWORD lpcchBuffer
)
1056 DPRINT("GetServiceDisplayNameA() called\n");
1060 dwError
= ScmrGetServiceDisplayNameA(BindingHandle
,
1061 (unsigned int)hSCManager
,
1062 (LPSTR
)lpServiceName
,
1065 if (dwError
!= ERROR_SUCCESS
)
1067 DPRINT1("ScmrGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
1068 SetLastError(dwError
);
1078 /**********************************************************************
1079 * GetServiceDisplayNameW
1084 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
1085 LPCWSTR lpServiceName
,
1086 LPWSTR lpDisplayName
,
1087 LPDWORD lpcchBuffer
)
1091 DPRINT("GetServiceDisplayNameW() called\n");
1095 dwError
= ScmrGetServiceDisplayNameW(BindingHandle
,
1096 (unsigned int)hSCManager
,
1097 (LPWSTR
)lpServiceName
,
1100 if (dwError
!= ERROR_SUCCESS
)
1102 DPRINT1("ScmrGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1103 SetLastError(dwError
);
1113 /**********************************************************************
1114 * GetServiceKeyNameA
1119 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1120 LPCSTR lpDisplayName
,
1121 LPSTR lpServiceName
,
1122 LPDWORD lpcchBuffer
)
1126 DPRINT("GetServiceKeyNameA() called\n");
1130 dwError
= ScmrGetServiceKeyNameA(BindingHandle
,
1131 (unsigned int)hSCManager
,
1132 (LPSTR
)lpDisplayName
,
1135 if (dwError
!= ERROR_SUCCESS
)
1137 DPRINT1("ScmrGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1138 SetLastError(dwError
);
1148 /**********************************************************************
1149 * GetServiceKeyNameW
1154 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1155 LPCWSTR lpDisplayName
,
1156 LPWSTR lpServiceName
,
1157 LPDWORD lpcchBuffer
)
1161 DPRINT("GetServiceKeyNameW() called\n");
1165 dwError
= ScmrGetServiceKeyNameW(BindingHandle
,
1166 (unsigned int)hSCManager
,
1167 (LPWSTR
)lpDisplayName
,
1170 if (dwError
!= ERROR_SUCCESS
)
1172 DPRINT1("ScmrGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1173 SetLastError(dwError
);
1183 /**********************************************************************
1184 * LockServiceDatabase
1189 LockServiceDatabase(SC_HANDLE hSCManager
)
1194 DPRINT("LockServiceDatabase(%x)\n", hSCManager
);
1198 /* Call to services.exe using RPC */
1199 dwError
= ScmrLockServiceDatabase(BindingHandle
,
1200 (unsigned int)hSCManager
,
1201 (unsigned int *)&hLock
);
1202 if (dwError
!= ERROR_SUCCESS
)
1204 DPRINT1("ScmrLockServiceDatabase() failed (Error %lu)\n", dwError
);
1205 SetLastError(dwError
);
1209 DPRINT("hLock = %p\n", hLock
);
1216 WaitForSCManager(VOID
)
1220 DPRINT("WaitForSCManager() called\n");
1222 /* Try to open the existing event */
1223 hEvent
= OpenEventW(SYNCHRONIZE
,
1225 L
"SvcctrlStartEvent_A3725DX");
1228 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1231 /* Try to create a new event */
1232 hEvent
= CreateEventW(NULL
,
1235 L
"SvcctrlStartEvent_A3725DX");
1238 /* Try to open the existing event again */
1239 hEvent
= OpenEventW(SYNCHRONIZE
,
1241 L
"SvcctrlStartEvent_A3725DX");
1247 /* Wait for 3 minutes */
1248 WaitForSingleObject(hEvent
, 180000);
1249 CloseHandle(hEvent
);
1251 DPRINT("ScmWaitForSCManager() done\n");
1255 /**********************************************************************
1261 OpenSCManagerA(LPCSTR lpMachineName
,
1262 LPCSTR lpDatabaseName
,
1263 DWORD dwDesiredAccess
)
1265 SC_HANDLE hScm
= NULL
;
1268 DPRINT("OpenSCManagerA(%s, %s, %lx)\n",
1269 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1275 /* Call to services.exe using RPC */
1276 dwError
= ScmrOpenSCManagerA(BindingHandle
,
1277 (LPSTR
)lpMachineName
,
1278 (LPSTR
)lpDatabaseName
,
1280 (unsigned int*)&hScm
);
1281 if (dwError
!= ERROR_SUCCESS
)
1283 DPRINT1("ScmrOpenSCManagerA() failed (Error %lu)\n", dwError
);
1284 SetLastError(dwError
);
1288 DPRINT("hScm = %p\n", hScm
);
1294 /**********************************************************************
1300 OpenSCManagerW(LPCWSTR lpMachineName
,
1301 LPCWSTR lpDatabaseName
,
1302 DWORD dwDesiredAccess
)
1304 SC_HANDLE hScm
= NULL
;
1307 DPRINT("OpenSCManagerW(%S, %S, %lx)\n",
1308 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1314 /* Call to services.exe using RPC */
1315 dwError
= ScmrOpenSCManagerW(BindingHandle
,
1316 (LPWSTR
)lpMachineName
,
1317 (LPWSTR
)lpDatabaseName
,
1319 (unsigned int*)&hScm
);
1320 if (dwError
!= ERROR_SUCCESS
)
1322 DPRINT1("ScmrOpenSCManagerW() failed (Error %lu)\n", dwError
);
1323 SetLastError(dwError
);
1327 DPRINT("hScm = %p\n", hScm
);
1333 /**********************************************************************
1339 OpenServiceA(SC_HANDLE hSCManager
,
1340 LPCSTR lpServiceName
,
1341 DWORD dwDesiredAccess
)
1343 SC_HANDLE hService
= NULL
;
1346 DPRINT("OpenServiceA(%p, %s, %lx)\n",
1347 hSCManager
, lpServiceName
, dwDesiredAccess
);
1351 /* Call to services.exe using RPC */
1352 dwError
= ScmrOpenServiceA(BindingHandle
,
1353 (unsigned int)hSCManager
,
1354 (LPSTR
)lpServiceName
,
1356 (unsigned int*)&hService
);
1357 if (dwError
!= ERROR_SUCCESS
)
1359 DPRINT1("ScmrOpenServiceA() failed (Error %lu)\n", dwError
);
1360 SetLastError(dwError
);
1364 DPRINT("hService = %p\n", hService
);
1370 /**********************************************************************
1376 OpenServiceW(SC_HANDLE hSCManager
,
1377 LPCWSTR lpServiceName
,
1378 DWORD dwDesiredAccess
)
1380 SC_HANDLE hService
= NULL
;
1383 DPRINT("OpenServiceW(%p, %S, %lx)\n",
1384 hSCManager
, lpServiceName
, dwDesiredAccess
);
1388 /* Call to services.exe using RPC */
1389 dwError
= ScmrOpenServiceW(BindingHandle
,
1390 (unsigned int)hSCManager
,
1391 (LPWSTR
)lpServiceName
,
1393 (unsigned int*)&hService
);
1394 if (dwError
!= ERROR_SUCCESS
)
1396 DPRINT("ScmrOpenServiceW() failed (Error %lu)\n", dwError
);
1397 SetLastError(dwError
);
1401 DPRINT("hService = %p\n", hService
);
1407 /**********************************************************************
1408 * QueryServiceConfigA
1413 QueryServiceConfigA(SC_HANDLE hService
,
1414 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
1416 LPDWORD pcbBytesNeeded
)
1420 DPRINT("QueryServiceConfigA(%p, %p, %lu, %p)\n",
1421 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1425 /* Call to services.exe using RPC */
1426 dwError
= ScmrQueryServiceConfigA(BindingHandle
,
1427 (unsigned int)hService
,
1428 (unsigned char *)lpServiceConfig
,
1431 if (dwError
!= ERROR_SUCCESS
)
1433 DPRINT("ScmrQueryServiceConfigA() failed (Error %lu)\n", dwError
);
1434 SetLastError(dwError
);
1438 /* Adjust the pointers */
1439 if (lpServiceConfig
->lpBinaryPathName
)
1440 lpServiceConfig
->lpBinaryPathName
=
1441 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1442 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1444 if (lpServiceConfig
->lpLoadOrderGroup
)
1445 lpServiceConfig
->lpLoadOrderGroup
=
1446 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1447 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1449 if (lpServiceConfig
->lpDependencies
)
1450 lpServiceConfig
->lpDependencies
=
1451 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1452 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1454 if (lpServiceConfig
->lpServiceStartName
)
1455 lpServiceConfig
->lpServiceStartName
=
1456 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1457 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1459 if (lpServiceConfig
->lpDisplayName
)
1460 lpServiceConfig
->lpDisplayName
=
1461 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1462 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1464 DPRINT("QueryServiceConfigA() done\n");
1470 /**********************************************************************
1471 * QueryServiceConfigW
1476 QueryServiceConfigW(SC_HANDLE hService
,
1477 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
1479 LPDWORD pcbBytesNeeded
)
1483 DPRINT("QueryServiceConfigW(%p, %p, %lu, %p)\n",
1484 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1488 /* Call to services.exe using RPC */
1489 dwError
= ScmrQueryServiceConfigW(BindingHandle
,
1490 (unsigned int)hService
,
1491 (unsigned char *)lpServiceConfig
,
1494 if (dwError
!= ERROR_SUCCESS
)
1496 DPRINT("ScmrQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1497 SetLastError(dwError
);
1501 /* Adjust the pointers */
1502 if (lpServiceConfig
->lpBinaryPathName
)
1503 lpServiceConfig
->lpBinaryPathName
=
1504 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1505 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1507 if (lpServiceConfig
->lpLoadOrderGroup
)
1508 lpServiceConfig
->lpLoadOrderGroup
=
1509 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1510 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1512 if (lpServiceConfig
->lpDependencies
)
1513 lpServiceConfig
->lpDependencies
=
1514 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1515 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1517 if (lpServiceConfig
->lpServiceStartName
)
1518 lpServiceConfig
->lpServiceStartName
=
1519 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1520 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1522 if (lpServiceConfig
->lpDisplayName
)
1523 lpServiceConfig
->lpDisplayName
=
1524 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1525 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1527 DPRINT("QueryServiceConfigW() done\n");
1533 /**********************************************************************
1534 * QueryServiceConfig2A
1539 QueryServiceConfig2A(SC_HANDLE hService
,
1543 LPDWORD pcbBytesNeeded
)
1547 DPRINT("QueryServiceConfig2A(%p, %lu, %p, %lu, %p)\n",
1548 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1552 /* Call to services.exe using RPC */
1553 dwError
= ScmrQueryServiceConfig2A(BindingHandle
,
1554 (unsigned int)hService
,
1556 (unsigned char *)lpBuffer
,
1559 if (dwError
!= ERROR_SUCCESS
)
1561 DPRINT("ScmrQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
1562 SetLastError(dwError
);
1566 switch (dwInfoLevel
)
1568 case SERVICE_CONFIG_DESCRIPTION
:
1570 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
1572 if (lpPtr
->lpDescription
!= NULL
)
1573 lpPtr
->lpDescription
=
1574 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1578 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1580 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpBuffer
;
1582 if (lpPtr
->lpRebootMsg
!= NULL
)
1583 lpPtr
->lpRebootMsg
=
1584 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1586 if (lpPtr
->lpCommand
!= NULL
)
1588 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1590 if (lpPtr
->lpsaActions
!= NULL
)
1591 lpPtr
->lpsaActions
=
1592 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1597 DPRINT1("Unknown info level 0x%lx\n", dwInfoLevel
);
1598 SetLastError(ERROR_INVALID_PARAMETER
);
1602 DPRINT("QueryServiceConfig2A() done\n");
1608 /**********************************************************************
1609 * QueryServiceConfig2W
1614 QueryServiceConfig2W(SC_HANDLE hService
,
1618 LPDWORD pcbBytesNeeded
)
1622 DPRINT("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
1623 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1627 /* Call to services.exe using RPC */
1628 dwError
= ScmrQueryServiceConfig2W(BindingHandle
,
1629 (unsigned int)hService
,
1631 (unsigned char *)lpBuffer
,
1634 if (dwError
!= ERROR_SUCCESS
)
1636 DPRINT("ScmrQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
1637 SetLastError(dwError
);
1641 switch (dwInfoLevel
)
1643 case SERVICE_CONFIG_DESCRIPTION
:
1645 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
1647 if (lpPtr
->lpDescription
!= NULL
)
1648 lpPtr
->lpDescription
=
1649 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1653 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1655 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
1657 if (lpPtr
->lpRebootMsg
!= NULL
)
1658 lpPtr
->lpRebootMsg
=
1659 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1661 if (lpPtr
->lpCommand
!= NULL
)
1663 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1665 if (lpPtr
->lpsaActions
!= NULL
)
1666 lpPtr
->lpsaActions
=
1667 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1672 DPRINT1("Unknown info level 0x%lx\n", dwInfoLevel
);
1673 SetLastError(ERROR_INVALID_PARAMETER
);
1677 DPRINT("QueryServiceConfig2W() done\n");
1683 /**********************************************************************
1684 * QueryServiceLockStatusA
1689 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
1690 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
1692 LPDWORD pcbBytesNeeded
)
1696 DPRINT("QueryServiceLockStatusA() called\n");
1700 /* Call to services.exe using RPC */
1701 dwError
= ScmrQueryServiceLockStatusA(BindingHandle
,
1702 (unsigned int)hSCManager
,
1703 (unsigned char *)lpLockStatus
,
1706 if (dwError
!= ERROR_SUCCESS
)
1708 DPRINT("ScmrQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
1709 SetLastError(dwError
);
1713 if (lpLockStatus
->lpLockOwner
!= NULL
)
1715 lpLockStatus
->lpLockOwner
=
1716 (LPSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
1719 DPRINT("QueryServiceLockStatusA() done\n");
1725 /**********************************************************************
1726 * QueryServiceLockStatusW
1731 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
1732 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
1734 LPDWORD pcbBytesNeeded
)
1738 DPRINT("QueryServiceLockStatusW() called\n");
1742 /* Call to services.exe using RPC */
1743 dwError
= ScmrQueryServiceLockStatusW(BindingHandle
,
1744 (unsigned int)hSCManager
,
1745 (unsigned char *)lpLockStatus
,
1748 if (dwError
!= ERROR_SUCCESS
)
1750 DPRINT("ScmrQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
1751 SetLastError(dwError
);
1755 if (lpLockStatus
->lpLockOwner
!= NULL
)
1757 lpLockStatus
->lpLockOwner
=
1758 (LPWSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
1761 DPRINT("QueryServiceLockStatusW() done\n");
1767 /**********************************************************************
1768 * QueryServiceObjectSecurity
1773 QueryServiceObjectSecurity(SC_HANDLE hService
,
1774 SECURITY_INFORMATION dwSecurityInformation
,
1775 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
1777 LPDWORD pcbBytesNeeded
)
1781 DPRINT("QueryServiceObjectSecurity(%p, %lu, %p)\n",
1782 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
1786 /* Call to services.exe using RPC */
1787 dwError
= ScmrQueryServiceObjectSecurity(BindingHandle
,
1788 (unsigned int)hService
,
1789 dwSecurityInformation
,
1790 (unsigned char *)lpSecurityDescriptor
,
1793 if (dwError
!= ERROR_SUCCESS
)
1795 DPRINT1("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
1796 SetLastError(dwError
);
1804 /**********************************************************************
1805 * QueryServiceStatus
1810 QueryServiceStatus(SC_HANDLE hService
,
1811 LPSERVICE_STATUS lpServiceStatus
)
1815 DPRINT("QueryServiceStatus(%p, %p)\n",
1816 hService
, lpServiceStatus
);
1820 /* Call to services.exe using RPC */
1821 dwError
= ScmrQueryServiceStatus(BindingHandle
,
1822 (unsigned int)hService
,
1824 if (dwError
!= ERROR_SUCCESS
)
1826 DPRINT1("ScmrQueryServiceStatus() failed (Error %lu)\n", dwError
);
1827 SetLastError(dwError
);
1835 /**********************************************************************
1836 * QueryServiceStatusEx
1841 QueryServiceStatusEx(SC_HANDLE hService
,
1842 SC_STATUS_TYPE InfoLevel
,
1845 LPDWORD pcbBytesNeeded
)
1849 DPRINT("QueryServiceStatusEx() called\n");
1853 /* Call to services.exe using RPC */
1854 dwError
= ScmrQueryServiceStatusEx(BindingHandle
,
1855 (unsigned int)hService
,
1860 if (dwError
!= ERROR_SUCCESS
)
1862 DPRINT("ScmrQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
1863 SetLastError(dwError
);
1871 /**********************************************************************
1872 * SetServiceObjectSecurity
1877 SetServiceObjectSecurity(SC_HANDLE hService
,
1878 SECURITY_INFORMATION dwSecurityInformation
,
1879 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
1881 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
1887 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
1890 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
1892 SetLastError(ERROR_INVALID_PARAMETER
);
1896 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
1897 if (SelfRelativeSD
== NULL
)
1899 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1903 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
1906 if (!NT_SUCCESS(Status
))
1908 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
1909 SetLastError(RtlNtStatusToDosError(Status
));
1915 /* Call to services.exe using RPC */
1916 dwError
= ScmrSetServiceObjectSecurity(BindingHandle
,
1917 (unsigned int)hService
,
1918 dwSecurityInformation
,
1919 (unsigned char *)SelfRelativeSD
,
1922 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
1924 if (dwError
!= ERROR_SUCCESS
)
1926 DPRINT1("ScmrServiceObjectSecurity() failed (Error %lu)\n", dwError
);
1927 SetLastError(dwError
);
1935 /**********************************************************************
1941 StartServiceA(SC_HANDLE hService
,
1942 DWORD dwNumServiceArgs
,
1943 LPCSTR
*lpServiceArgVectors
)
1952 for (i
= 0; i
< dwNumServiceArgs
; i
++)
1954 dwBufSize
+= (strlen(lpServiceArgVectors
[i
]) + 1);
1956 DPRINT1("dwBufSize: %lu\n", dwBufSize
);
1958 lpBuffer
= HeapAlloc(GetProcessHeap(), 0, dwBufSize
);
1959 if (lpBuffer
== NULL
)
1961 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1966 for (i
= 0; i
< dwNumServiceArgs
; i
++)
1968 strcpy(lpStr
, lpServiceArgVectors
[i
]);
1969 lpStr
+= (strlen(lpServiceArgVectors
[i
]) + 1);
1972 dwError
= ScmrStartServiceA(BindingHandle
,
1973 (unsigned int)hService
,
1975 (unsigned char *)lpBuffer
,
1978 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1980 if (dwError
!= ERROR_SUCCESS
)
1982 DPRINT1("ScmrStartServiceA() failed (Error %lu)\n", dwError
);
1983 SetLastError(dwError
);
1991 /**********************************************************************
1997 StartServiceW(SC_HANDLE hService
,
1998 DWORD dwNumServiceArgs
,
1999 LPCWSTR
*lpServiceArgVectors
)
2008 for (i
= 0; i
< dwNumServiceArgs
; i
++)
2010 dwBufSize
+= ((wcslen(lpServiceArgVectors
[i
]) + 1) * sizeof(WCHAR
));
2012 DPRINT1("dwBufSize: %lu\n", dwBufSize
);
2014 lpBuffer
= HeapAlloc(GetProcessHeap(), 0, dwBufSize
);
2015 if (lpBuffer
== NULL
)
2017 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2022 for (i
= 0; i
< dwNumServiceArgs
; i
++)
2024 wcscpy(lpStr
, lpServiceArgVectors
[i
]);
2025 lpStr
+= (wcslen(lpServiceArgVectors
[i
]) + 1);
2028 dwError
= ScmrStartServiceW(BindingHandle
,
2029 (unsigned int)hService
,
2031 (unsigned char *)lpBuffer
,
2034 HeapFree(GetProcessHeap(), 0, lpBuffer
);
2036 if (dwError
!= ERROR_SUCCESS
)
2038 DPRINT1("ScmrStartServiceW() failed (Error %lu)\n", dwError
);
2039 SetLastError(dwError
);
2047 /**********************************************************************
2048 * UnlockServiceDatabase
2053 UnlockServiceDatabase(SC_LOCK ScLock
)
2057 DPRINT("UnlockServiceDatabase(%x)\n", ScLock
);
2061 /* Call to services.exe using RPC */
2062 dwError
= ScmrUnlockServiceDatabase(BindingHandle
,
2063 (unsigned int)ScLock
);
2064 if (dwError
!= ERROR_SUCCESS
)
2066 DPRINT1("ScmrUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2067 SetLastError(dwError
);
2075 /**********************************************************************
2076 * NotifyBootConfigStatus
2081 NotifyBootConfigStatus(BOOL BootAcceptable
)
2085 DPRINT1("NotifyBootConfigStatus()\n");
2089 /* Call to services.exe using RPC */
2090 dwError
= ScmrNotifyBootConfigStatus(BindingHandle
,
2092 if (dwError
!= ERROR_SUCCESS
)
2094 DPRINT1("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
2095 SetLastError(dwError
);
2103 void __RPC_FAR
* __RPC_USER
midl_user_allocate(size_t len
)
2105 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2109 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
2111 HeapFree(GetProcessHeap(), 0, ptr
);