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 if (lpServiceNameW
!=NULL
)
546 HeapFree(GetProcessHeap(), 0, lpServiceNameW
);
548 if (lpDisplayNameW
!= NULL
)
549 HeapFree(GetProcessHeap(), 0, lpDisplayNameW
);
551 if (lpBinaryPathNameW
!= NULL
)
552 HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW
);
554 if (lpLoadOrderGroupW
!= NULL
)
555 HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW
);
557 if (lpDependenciesW
!= NULL
)
558 HeapFree(GetProcessHeap(), 0, lpDependenciesW
);
560 if (lpServiceStartNameW
!= NULL
)
561 HeapFree(GetProcessHeap(), 0, lpServiceStartNameW
);
563 if (lpPasswordW
!= NULL
)
564 HeapFree(GetProcessHeap(), 0, lpPasswordW
);
570 /**********************************************************************
576 CreateServiceW(SC_HANDLE hSCManager
,
577 LPCWSTR lpServiceName
,
578 LPCWSTR lpDisplayName
,
579 DWORD dwDesiredAccess
,
582 DWORD dwErrorControl
,
583 LPCWSTR lpBinaryPathName
,
584 LPCWSTR lpLoadOrderGroup
,
586 LPCWSTR lpDependencies
,
587 LPCWSTR lpServiceStartName
,
590 SC_HANDLE hService
= NULL
;
591 DWORD dwDependenciesLength
= 0;
596 DPRINT("CreateServiceW() called\n");
598 /* Calculate the Dependencies length*/
599 if (lpDependencies
!= NULL
)
601 lpStr
= (LPWSTR
)lpDependencies
;
604 dwLength
= wcslen(lpStr
) + 1;
605 dwDependenciesLength
+= dwLength
;
606 lpStr
= lpStr
+ dwLength
;
608 dwDependenciesLength
++;
611 /* FIXME: Encrypt the password */
615 /* Call to services.exe using RPC */
616 dwError
= ScmrCreateServiceW(BindingHandle
,
617 (unsigned int)hSCManager
,
618 (LPWSTR
)lpServiceName
,
619 (LPWSTR
)lpDisplayName
,
624 (LPWSTR
)lpBinaryPathName
,
625 (LPWSTR
)lpLoadOrderGroup
,
627 (LPWSTR
)lpDependencies
,
628 dwDependenciesLength
,
629 (LPWSTR
)lpServiceStartName
,
630 NULL
, /* FIXME: lpPassword */
631 0, /* FIXME: dwPasswordLength */
632 (unsigned int *)&hService
);
633 if (dwError
!= ERROR_SUCCESS
)
635 DPRINT("ScmrCreateServiceW() failed (Error %lu)\n", dwError
);
636 SetLastError(dwError
);
644 /**********************************************************************
650 DeleteService(SC_HANDLE hService
)
654 DPRINT("DeleteService(%x)\n", hService
);
658 /* Call to services.exe using RPC */
659 dwError
= ScmrDeleteService(BindingHandle
,
660 (unsigned int)hService
);
661 if (dwError
!= ERROR_SUCCESS
)
663 DPRINT1("ScmrDeleteService() failed (Error %lu)\n", dwError
);
664 SetLastError(dwError
);
672 /**********************************************************************
673 * EnumDependentServicesA
678 EnumDependentServicesA(SC_HANDLE hService
,
679 DWORD dwServiceState
,
680 LPENUM_SERVICE_STATUSA lpServices
,
682 LPDWORD pcbBytesNeeded
,
683 LPDWORD lpServicesReturned
)
685 LPENUM_SERVICE_STATUSA lpStatusPtr
;
686 DWORD dwError
= ERROR_SUCCESS
;
689 DPRINT("EnumServicesStatusA() called\n");
693 dwError
= ScmrEnumDependentServicesA(BindingHandle
,
694 (unsigned int)hService
,
696 (unsigned char *)lpServices
,
701 lpStatusPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
702 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
704 if (lpStatusPtr
->lpServiceName
)
705 lpStatusPtr
->lpServiceName
=
706 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
708 if (lpStatusPtr
->lpDisplayName
)
709 lpStatusPtr
->lpDisplayName
=
710 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
715 if (dwError
!= ERROR_SUCCESS
)
717 DPRINT("ScmrEnumDependentServicesA() failed (Error %lu)\n", dwError
);
718 SetLastError(dwError
);
722 DPRINT("EnumDependentServicesA() done\n");
728 /**********************************************************************
729 * EnumDependentServicesW
734 EnumDependentServicesW(SC_HANDLE hService
,
735 DWORD dwServiceState
,
736 LPENUM_SERVICE_STATUSW lpServices
,
738 LPDWORD pcbBytesNeeded
,
739 LPDWORD lpServicesReturned
)
741 LPENUM_SERVICE_STATUSW lpStatusPtr
;
742 DWORD dwError
= ERROR_SUCCESS
;
745 DPRINT("EnumServicesStatusW() called\n");
749 dwError
= ScmrEnumDependentServicesW(BindingHandle
,
750 (unsigned int)hService
,
752 (unsigned char *)lpServices
,
757 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
758 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
760 if (lpStatusPtr
->lpServiceName
)
761 lpStatusPtr
->lpServiceName
=
762 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
764 if (lpStatusPtr
->lpDisplayName
)
765 lpStatusPtr
->lpDisplayName
=
766 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
771 if (dwError
!= ERROR_SUCCESS
)
773 DPRINT("ScmrEnumDependentServicesW() failed (Error %lu)\n", dwError
);
774 SetLastError(dwError
);
778 DPRINT("EnumDependentServicesW() done\n");
784 /**********************************************************************
792 SC_HANDLE hSCManager
,
794 DWORD dwServiceState
,
795 LPENUM_SERVICE_STATUSW lpServices
,
797 LPDWORD pcbBytesNeeded
,
798 LPDWORD lpServicesReturned
,
799 LPDWORD lpResumeHandle
,
802 DPRINT1("EnumServiceGroupW is unimplemented\n");
803 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
808 /**********************************************************************
809 * EnumServicesStatusA
814 EnumServicesStatusA(SC_HANDLE hSCManager
,
816 DWORD dwServiceState
,
817 LPENUM_SERVICE_STATUSA lpServices
,
819 LPDWORD pcbBytesNeeded
,
820 LPDWORD lpServicesReturned
,
821 LPDWORD lpResumeHandle
)
823 LPENUM_SERVICE_STATUSA lpStatusPtr
;
824 DWORD dwError
= ERROR_SUCCESS
;
827 DPRINT("EnumServicesStatusA() called\n");
831 dwError
= ScmrEnumServicesStatusA(BindingHandle
,
832 (unsigned int)hSCManager
,
835 (unsigned char *)lpServices
,
841 lpStatusPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
842 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
844 if (lpStatusPtr
->lpServiceName
)
845 lpStatusPtr
->lpServiceName
=
846 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
848 if (lpStatusPtr
->lpDisplayName
)
849 lpStatusPtr
->lpDisplayName
=
850 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
855 if (dwError
!= ERROR_SUCCESS
)
857 DPRINT("ScmrEnumServicesStatusA() failed (Error %lu)\n", dwError
);
858 SetLastError(dwError
);
862 DPRINT("EnumServicesStatusA() done\n");
868 /**********************************************************************
869 * EnumServicesStatusW
874 EnumServicesStatusW(SC_HANDLE hSCManager
,
876 DWORD dwServiceState
,
877 LPENUM_SERVICE_STATUSW lpServices
,
879 LPDWORD pcbBytesNeeded
,
880 LPDWORD lpServicesReturned
,
881 LPDWORD lpResumeHandle
)
883 LPENUM_SERVICE_STATUSW lpStatusPtr
;
884 DWORD dwError
= ERROR_SUCCESS
;
887 DPRINT("EnumServicesStatusW() called\n");
891 dwError
= ScmrEnumServicesStatusW(BindingHandle
,
892 (unsigned int)hSCManager
,
895 (unsigned char *)lpServices
,
901 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
902 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
904 if (lpStatusPtr
->lpServiceName
)
905 lpStatusPtr
->lpServiceName
=
906 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
908 if (lpStatusPtr
->lpDisplayName
)
909 lpStatusPtr
->lpDisplayName
=
910 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
915 if (dwError
!= ERROR_SUCCESS
)
917 DPRINT("ScmrEnumServicesStatusW() failed (Error %lu)\n", dwError
);
918 SetLastError(dwError
);
922 DPRINT("EnumServicesStatusW() done\n");
928 /**********************************************************************
929 * EnumServicesStatusExA
934 EnumServicesStatusExA(SC_HANDLE hSCManager
,
935 SC_ENUM_TYPE InfoLevel
,
937 DWORD dwServiceState
,
940 LPDWORD pcbBytesNeeded
,
941 LPDWORD lpServicesReturned
,
942 LPDWORD lpResumeHandle
,
945 LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtr
;
946 DWORD dwError
= ERROR_SUCCESS
;
949 DPRINT("EnumServicesStatusExA() called\n");
953 dwError
= ScmrEnumServicesStatusExA(BindingHandle
,
954 (unsigned int)hSCManager
,
955 (unsigned long)InfoLevel
,
958 (unsigned char *)lpServices
,
963 (char *)pszGroupName
);
965 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpServices
;
966 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
968 if (lpStatusPtr
->lpServiceName
)
969 lpStatusPtr
->lpServiceName
=
970 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
972 if (lpStatusPtr
->lpDisplayName
)
973 lpStatusPtr
->lpDisplayName
=
974 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
979 if (dwError
!= ERROR_SUCCESS
)
981 DPRINT1("ScmrEnumServicesStatusExA() failed (Error %lu)\n", dwError
);
982 SetLastError(dwError
);
986 DPRINT("EnumServicesStatusExA() done\n");
992 /**********************************************************************
993 * EnumServicesStatusExW
998 EnumServicesStatusExW(SC_HANDLE hSCManager
,
999 SC_ENUM_TYPE InfoLevel
,
1000 DWORD dwServiceType
,
1001 DWORD dwServiceState
,
1004 LPDWORD pcbBytesNeeded
,
1005 LPDWORD lpServicesReturned
,
1006 LPDWORD lpResumeHandle
,
1007 LPCWSTR pszGroupName
)
1009 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
1010 DWORD dwError
= ERROR_SUCCESS
;
1013 DPRINT("EnumServicesStatusExW() called\n");
1017 dwError
= ScmrEnumServicesStatusExW(BindingHandle
,
1018 (unsigned int)hSCManager
,
1019 (unsigned long)InfoLevel
,
1022 (unsigned char *)lpServices
,
1027 (wchar_t *)pszGroupName
);
1029 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpServices
;
1030 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1032 if (lpStatusPtr
->lpServiceName
)
1033 lpStatusPtr
->lpServiceName
=
1034 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1036 if (lpStatusPtr
->lpDisplayName
)
1037 lpStatusPtr
->lpDisplayName
=
1038 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1043 if (dwError
!= ERROR_SUCCESS
&&
1044 dwError
!= ERROR_MORE_DATA
)
1046 DPRINT1("ScmrEnumServicesStatusExW() failed (Error %lu)\n", dwError
);
1047 SetLastError(dwError
);
1051 DPRINT("EnumServicesStatusExW() done\n");
1057 /**********************************************************************
1058 * GetServiceDisplayNameA
1063 GetServiceDisplayNameA(SC_HANDLE hSCManager
,
1064 LPCSTR lpServiceName
,
1065 LPSTR lpDisplayName
,
1066 LPDWORD lpcchBuffer
)
1070 DPRINT("GetServiceDisplayNameA() called\n");
1074 dwError
= ScmrGetServiceDisplayNameA(BindingHandle
,
1075 (unsigned int)hSCManager
,
1076 (LPSTR
)lpServiceName
,
1079 if (dwError
!= ERROR_SUCCESS
)
1081 DPRINT1("ScmrGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
1082 SetLastError(dwError
);
1092 /**********************************************************************
1093 * GetServiceDisplayNameW
1098 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
1099 LPCWSTR lpServiceName
,
1100 LPWSTR lpDisplayName
,
1101 LPDWORD lpcchBuffer
)
1105 DPRINT("GetServiceDisplayNameW() called\n");
1109 dwError
= ScmrGetServiceDisplayNameW(BindingHandle
,
1110 (unsigned int)hSCManager
,
1111 (LPWSTR
)lpServiceName
,
1114 if (dwError
!= ERROR_SUCCESS
)
1116 DPRINT1("ScmrGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1117 SetLastError(dwError
);
1127 /**********************************************************************
1128 * GetServiceKeyNameA
1133 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1134 LPCSTR lpDisplayName
,
1135 LPSTR lpServiceName
,
1136 LPDWORD lpcchBuffer
)
1140 DPRINT("GetServiceKeyNameA() called\n");
1144 dwError
= ScmrGetServiceKeyNameA(BindingHandle
,
1145 (unsigned int)hSCManager
,
1146 (LPSTR
)lpDisplayName
,
1149 if (dwError
!= ERROR_SUCCESS
)
1151 DPRINT1("ScmrGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1152 SetLastError(dwError
);
1162 /**********************************************************************
1163 * GetServiceKeyNameW
1168 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1169 LPCWSTR lpDisplayName
,
1170 LPWSTR lpServiceName
,
1171 LPDWORD lpcchBuffer
)
1175 DPRINT("GetServiceKeyNameW() called\n");
1179 dwError
= ScmrGetServiceKeyNameW(BindingHandle
,
1180 (unsigned int)hSCManager
,
1181 (LPWSTR
)lpDisplayName
,
1184 if (dwError
!= ERROR_SUCCESS
)
1186 DPRINT1("ScmrGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1187 SetLastError(dwError
);
1197 /**********************************************************************
1198 * LockServiceDatabase
1203 LockServiceDatabase(SC_HANDLE hSCManager
)
1208 DPRINT("LockServiceDatabase(%x)\n", hSCManager
);
1212 /* Call to services.exe using RPC */
1213 dwError
= ScmrLockServiceDatabase(BindingHandle
,
1214 (unsigned int)hSCManager
,
1215 (unsigned int *)&hLock
);
1216 if (dwError
!= ERROR_SUCCESS
)
1218 DPRINT1("ScmrLockServiceDatabase() failed (Error %lu)\n", dwError
);
1219 SetLastError(dwError
);
1223 DPRINT("hLock = %p\n", hLock
);
1230 WaitForSCManager(VOID
)
1234 DPRINT("WaitForSCManager() called\n");
1236 /* Try to open the existing event */
1237 hEvent
= OpenEventW(SYNCHRONIZE
,
1239 L
"SvcctrlStartEvent_A3725DX");
1242 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1245 /* Try to create a new event */
1246 hEvent
= CreateEventW(NULL
,
1249 L
"SvcctrlStartEvent_A3725DX");
1252 /* Try to open the existing event again */
1253 hEvent
= OpenEventW(SYNCHRONIZE
,
1255 L
"SvcctrlStartEvent_A3725DX");
1261 /* Wait for 3 minutes */
1262 WaitForSingleObject(hEvent
, 180000);
1263 CloseHandle(hEvent
);
1265 DPRINT("ScmWaitForSCManager() done\n");
1269 /**********************************************************************
1275 OpenSCManagerA(LPCSTR lpMachineName
,
1276 LPCSTR lpDatabaseName
,
1277 DWORD dwDesiredAccess
)
1279 SC_HANDLE hScm
= NULL
;
1282 DPRINT("OpenSCManagerA(%s, %s, %lx)\n",
1283 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1289 /* Call to services.exe using RPC */
1290 dwError
= ScmrOpenSCManagerA(BindingHandle
,
1291 (LPSTR
)lpMachineName
,
1292 (LPSTR
)lpDatabaseName
,
1294 (unsigned int*)&hScm
);
1295 if (dwError
!= ERROR_SUCCESS
)
1297 DPRINT1("ScmrOpenSCManagerA() failed (Error %lu)\n", dwError
);
1298 SetLastError(dwError
);
1302 DPRINT("hScm = %p\n", hScm
);
1308 /**********************************************************************
1314 OpenSCManagerW(LPCWSTR lpMachineName
,
1315 LPCWSTR lpDatabaseName
,
1316 DWORD dwDesiredAccess
)
1318 SC_HANDLE hScm
= NULL
;
1321 DPRINT("OpenSCManagerW(%S, %S, %lx)\n",
1322 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1328 /* Call to services.exe using RPC */
1329 dwError
= ScmrOpenSCManagerW(BindingHandle
,
1330 (LPWSTR
)lpMachineName
,
1331 (LPWSTR
)lpDatabaseName
,
1333 (unsigned int*)&hScm
);
1334 if (dwError
!= ERROR_SUCCESS
)
1336 DPRINT1("ScmrOpenSCManagerW() failed (Error %lu)\n", dwError
);
1337 SetLastError(dwError
);
1341 DPRINT("hScm = %p\n", hScm
);
1347 /**********************************************************************
1353 OpenServiceA(SC_HANDLE hSCManager
,
1354 LPCSTR lpServiceName
,
1355 DWORD dwDesiredAccess
)
1357 SC_HANDLE hService
= NULL
;
1360 DPRINT("OpenServiceA(%p, %s, %lx)\n",
1361 hSCManager
, lpServiceName
, dwDesiredAccess
);
1365 /* Call to services.exe using RPC */
1366 dwError
= ScmrOpenServiceA(BindingHandle
,
1367 (unsigned int)hSCManager
,
1368 (LPSTR
)lpServiceName
,
1370 (unsigned int*)&hService
);
1371 if (dwError
!= ERROR_SUCCESS
)
1373 DPRINT1("ScmrOpenServiceA() failed (Error %lu)\n", dwError
);
1374 SetLastError(dwError
);
1378 DPRINT("hService = %p\n", hService
);
1384 /**********************************************************************
1390 OpenServiceW(SC_HANDLE hSCManager
,
1391 LPCWSTR lpServiceName
,
1392 DWORD dwDesiredAccess
)
1394 SC_HANDLE hService
= NULL
;
1397 DPRINT("OpenServiceW(%p, %S, %lx)\n",
1398 hSCManager
, lpServiceName
, dwDesiredAccess
);
1402 /* Call to services.exe using RPC */
1403 dwError
= ScmrOpenServiceW(BindingHandle
,
1404 (unsigned int)hSCManager
,
1405 (LPWSTR
)lpServiceName
,
1407 (unsigned int*)&hService
);
1408 if (dwError
!= ERROR_SUCCESS
)
1410 DPRINT("ScmrOpenServiceW() failed (Error %lu)\n", dwError
);
1411 SetLastError(dwError
);
1415 DPRINT("hService = %p\n", hService
);
1421 /**********************************************************************
1422 * QueryServiceConfigA
1427 QueryServiceConfigA(SC_HANDLE hService
,
1428 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
1430 LPDWORD pcbBytesNeeded
)
1434 DPRINT("QueryServiceConfigA(%p, %p, %lu, %p)\n",
1435 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1439 /* Call to services.exe using RPC */
1440 dwError
= ScmrQueryServiceConfigA(BindingHandle
,
1441 (unsigned int)hService
,
1442 (unsigned char *)lpServiceConfig
,
1445 if (dwError
!= ERROR_SUCCESS
)
1447 DPRINT("ScmrQueryServiceConfigA() failed (Error %lu)\n", dwError
);
1448 SetLastError(dwError
);
1452 /* Adjust the pointers */
1453 if (lpServiceConfig
->lpBinaryPathName
)
1454 lpServiceConfig
->lpBinaryPathName
=
1455 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1456 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1458 if (lpServiceConfig
->lpLoadOrderGroup
)
1459 lpServiceConfig
->lpLoadOrderGroup
=
1460 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1461 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1463 if (lpServiceConfig
->lpDependencies
)
1464 lpServiceConfig
->lpDependencies
=
1465 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1466 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1468 if (lpServiceConfig
->lpServiceStartName
)
1469 lpServiceConfig
->lpServiceStartName
=
1470 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1471 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1473 if (lpServiceConfig
->lpDisplayName
)
1474 lpServiceConfig
->lpDisplayName
=
1475 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1476 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1478 DPRINT("QueryServiceConfigA() done\n");
1484 /**********************************************************************
1485 * QueryServiceConfigW
1490 QueryServiceConfigW(SC_HANDLE hService
,
1491 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
1493 LPDWORD pcbBytesNeeded
)
1497 DPRINT("QueryServiceConfigW(%p, %p, %lu, %p)\n",
1498 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1502 /* Call to services.exe using RPC */
1503 dwError
= ScmrQueryServiceConfigW(BindingHandle
,
1504 (unsigned int)hService
,
1505 (unsigned char *)lpServiceConfig
,
1508 if (dwError
!= ERROR_SUCCESS
)
1510 DPRINT("ScmrQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1511 SetLastError(dwError
);
1515 /* Adjust the pointers */
1516 if (lpServiceConfig
->lpBinaryPathName
)
1517 lpServiceConfig
->lpBinaryPathName
=
1518 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1519 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1521 if (lpServiceConfig
->lpLoadOrderGroup
)
1522 lpServiceConfig
->lpLoadOrderGroup
=
1523 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1524 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1526 if (lpServiceConfig
->lpDependencies
)
1527 lpServiceConfig
->lpDependencies
=
1528 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1529 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1531 if (lpServiceConfig
->lpServiceStartName
)
1532 lpServiceConfig
->lpServiceStartName
=
1533 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1534 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1536 if (lpServiceConfig
->lpDisplayName
)
1537 lpServiceConfig
->lpDisplayName
=
1538 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1539 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1541 DPRINT("QueryServiceConfigW() done\n");
1547 /**********************************************************************
1548 * QueryServiceConfig2A
1553 QueryServiceConfig2A(SC_HANDLE hService
,
1557 LPDWORD pcbBytesNeeded
)
1561 DPRINT("QueryServiceConfig2A(%p, %lu, %p, %lu, %p)\n",
1562 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1566 /* Call to services.exe using RPC */
1567 dwError
= ScmrQueryServiceConfig2A(BindingHandle
,
1568 (unsigned int)hService
,
1570 (unsigned char *)lpBuffer
,
1573 if (dwError
!= ERROR_SUCCESS
)
1575 DPRINT("ScmrQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
1576 SetLastError(dwError
);
1580 switch (dwInfoLevel
)
1582 case SERVICE_CONFIG_DESCRIPTION
:
1584 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
1586 if (lpPtr
->lpDescription
!= NULL
)
1587 lpPtr
->lpDescription
=
1588 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1592 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1594 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpBuffer
;
1596 if (lpPtr
->lpRebootMsg
!= NULL
)
1597 lpPtr
->lpRebootMsg
=
1598 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1600 if (lpPtr
->lpCommand
!= NULL
)
1602 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1604 if (lpPtr
->lpsaActions
!= NULL
)
1605 lpPtr
->lpsaActions
=
1606 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1611 DPRINT1("Unknown info level 0x%lx\n", dwInfoLevel
);
1612 SetLastError(ERROR_INVALID_PARAMETER
);
1616 DPRINT("QueryServiceConfig2A() done\n");
1622 /**********************************************************************
1623 * QueryServiceConfig2W
1628 QueryServiceConfig2W(SC_HANDLE hService
,
1632 LPDWORD pcbBytesNeeded
)
1636 DPRINT("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
1637 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1641 /* Call to services.exe using RPC */
1642 dwError
= ScmrQueryServiceConfig2W(BindingHandle
,
1643 (unsigned int)hService
,
1645 (unsigned char *)lpBuffer
,
1648 if (dwError
!= ERROR_SUCCESS
)
1650 DPRINT("ScmrQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
1651 SetLastError(dwError
);
1655 switch (dwInfoLevel
)
1657 case SERVICE_CONFIG_DESCRIPTION
:
1659 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
1661 if (lpPtr
->lpDescription
!= NULL
)
1662 lpPtr
->lpDescription
=
1663 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1667 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1669 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
1671 if (lpPtr
->lpRebootMsg
!= NULL
)
1672 lpPtr
->lpRebootMsg
=
1673 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1675 if (lpPtr
->lpCommand
!= NULL
)
1677 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1679 if (lpPtr
->lpsaActions
!= NULL
)
1680 lpPtr
->lpsaActions
=
1681 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1686 DPRINT1("Unknown info level 0x%lx\n", dwInfoLevel
);
1687 SetLastError(ERROR_INVALID_PARAMETER
);
1691 DPRINT("QueryServiceConfig2W() done\n");
1697 /**********************************************************************
1698 * QueryServiceLockStatusA
1703 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
1704 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
1706 LPDWORD pcbBytesNeeded
)
1710 DPRINT("QueryServiceLockStatusA() called\n");
1714 /* Call to services.exe using RPC */
1715 dwError
= ScmrQueryServiceLockStatusA(BindingHandle
,
1716 (unsigned int)hSCManager
,
1717 (unsigned char *)lpLockStatus
,
1720 if (dwError
!= ERROR_SUCCESS
)
1722 DPRINT("ScmrQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
1723 SetLastError(dwError
);
1727 if (lpLockStatus
->lpLockOwner
!= NULL
)
1729 lpLockStatus
->lpLockOwner
=
1730 (LPSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
1733 DPRINT("QueryServiceLockStatusA() done\n");
1739 /**********************************************************************
1740 * QueryServiceLockStatusW
1745 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
1746 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
1748 LPDWORD pcbBytesNeeded
)
1752 DPRINT("QueryServiceLockStatusW() called\n");
1756 /* Call to services.exe using RPC */
1757 dwError
= ScmrQueryServiceLockStatusW(BindingHandle
,
1758 (unsigned int)hSCManager
,
1759 (unsigned char *)lpLockStatus
,
1762 if (dwError
!= ERROR_SUCCESS
)
1764 DPRINT("ScmrQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
1765 SetLastError(dwError
);
1769 if (lpLockStatus
->lpLockOwner
!= NULL
)
1771 lpLockStatus
->lpLockOwner
=
1772 (LPWSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
1775 DPRINT("QueryServiceLockStatusW() done\n");
1781 /**********************************************************************
1782 * QueryServiceObjectSecurity
1787 QueryServiceObjectSecurity(SC_HANDLE hService
,
1788 SECURITY_INFORMATION dwSecurityInformation
,
1789 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
1791 LPDWORD pcbBytesNeeded
)
1795 DPRINT("QueryServiceObjectSecurity(%p, %lu, %p)\n",
1796 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
1800 /* Call to services.exe using RPC */
1801 dwError
= ScmrQueryServiceObjectSecurity(BindingHandle
,
1802 (unsigned int)hService
,
1803 dwSecurityInformation
,
1804 (unsigned char *)lpSecurityDescriptor
,
1807 if (dwError
!= ERROR_SUCCESS
)
1809 DPRINT1("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
1810 SetLastError(dwError
);
1818 /**********************************************************************
1819 * QueryServiceStatus
1824 QueryServiceStatus(SC_HANDLE hService
,
1825 LPSERVICE_STATUS lpServiceStatus
)
1829 DPRINT("QueryServiceStatus(%p, %p)\n",
1830 hService
, lpServiceStatus
);
1834 /* Call to services.exe using RPC */
1835 dwError
= ScmrQueryServiceStatus(BindingHandle
,
1836 (unsigned int)hService
,
1838 if (dwError
!= ERROR_SUCCESS
)
1840 DPRINT1("ScmrQueryServiceStatus() failed (Error %lu)\n", dwError
);
1841 SetLastError(dwError
);
1849 /**********************************************************************
1850 * QueryServiceStatusEx
1855 QueryServiceStatusEx(SC_HANDLE hService
,
1856 SC_STATUS_TYPE InfoLevel
,
1859 LPDWORD pcbBytesNeeded
)
1863 DPRINT("QueryServiceStatusEx() called\n");
1867 /* Call to services.exe using RPC */
1868 dwError
= ScmrQueryServiceStatusEx(BindingHandle
,
1869 (unsigned int)hService
,
1874 if (dwError
!= ERROR_SUCCESS
)
1876 DPRINT("ScmrQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
1877 SetLastError(dwError
);
1885 /**********************************************************************
1886 * SetServiceObjectSecurity
1891 SetServiceObjectSecurity(SC_HANDLE hService
,
1892 SECURITY_INFORMATION dwSecurityInformation
,
1893 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
1895 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
1901 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
1904 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
1906 SetLastError(ERROR_INVALID_PARAMETER
);
1910 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
1911 if (SelfRelativeSD
== NULL
)
1913 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1917 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
1920 if (!NT_SUCCESS(Status
))
1922 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
1923 SetLastError(RtlNtStatusToDosError(Status
));
1929 /* Call to services.exe using RPC */
1930 dwError
= ScmrSetServiceObjectSecurity(BindingHandle
,
1931 (unsigned int)hService
,
1932 dwSecurityInformation
,
1933 (unsigned char *)SelfRelativeSD
,
1936 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
1938 if (dwError
!= ERROR_SUCCESS
)
1940 DPRINT1("ScmrServiceObjectSecurity() failed (Error %lu)\n", dwError
);
1941 SetLastError(dwError
);
1949 /**********************************************************************
1955 StartServiceA(SC_HANDLE hService
,
1956 DWORD dwNumServiceArgs
,
1957 LPCSTR
*lpServiceArgVectors
)
1966 for (i
= 0; i
< dwNumServiceArgs
; i
++)
1968 dwBufSize
+= (strlen(lpServiceArgVectors
[i
]) + 1);
1971 DPRINT1("dwBufSize: %lu\n", dwBufSize
);
1973 lpBuffer
= HeapAlloc(GetProcessHeap(), 0, dwBufSize
);
1974 if (lpBuffer
== NULL
)
1976 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1981 for (i
= 0; i
< dwNumServiceArgs
; i
++)
1983 strcpy(lpStr
, lpServiceArgVectors
[i
]);
1984 lpStr
+= (strlen(lpServiceArgVectors
[i
]) + 1);
1988 dwError
= ScmrStartServiceA(BindingHandle
,
1989 (unsigned int)hService
,
1991 (unsigned char *)lpBuffer
,
1994 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1996 if (dwError
!= ERROR_SUCCESS
)
1998 DPRINT1("ScmrStartServiceA() failed (Error %lu)\n", dwError
);
1999 SetLastError(dwError
);
2007 /**********************************************************************
2013 StartServiceW(SC_HANDLE hService
,
2014 DWORD dwNumServiceArgs
,
2015 LPCWSTR
*lpServiceArgVectors
)
2024 for (i
= 0; i
< dwNumServiceArgs
; i
++)
2026 dwBufSize
+= ((wcslen(lpServiceArgVectors
[i
]) + 1) * sizeof(WCHAR
));
2028 dwBufSize
+= sizeof(WCHAR
);
2029 DPRINT("dwBufSize: %lu\n", dwBufSize
);
2031 lpBuffer
= HeapAlloc(GetProcessHeap(), 0, dwBufSize
);
2032 if (lpBuffer
== NULL
)
2034 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2039 for (i
= 0; i
< dwNumServiceArgs
; i
++)
2041 wcscpy(lpStr
, lpServiceArgVectors
[i
]);
2042 lpStr
+= (wcslen(lpServiceArgVectors
[i
]) + 1);
2046 dwError
= ScmrStartServiceW(BindingHandle
,
2047 (unsigned int)hService
,
2049 (unsigned char *)lpBuffer
,
2052 HeapFree(GetProcessHeap(), 0, lpBuffer
);
2054 if (dwError
!= ERROR_SUCCESS
)
2056 DPRINT1("ScmrStartServiceW() failed (Error %lu)\n", dwError
);
2057 SetLastError(dwError
);
2065 /**********************************************************************
2066 * UnlockServiceDatabase
2071 UnlockServiceDatabase(SC_LOCK ScLock
)
2075 DPRINT("UnlockServiceDatabase(%x)\n", ScLock
);
2079 /* Call to services.exe using RPC */
2080 dwError
= ScmrUnlockServiceDatabase(BindingHandle
,
2081 (unsigned int)ScLock
);
2082 if (dwError
!= ERROR_SUCCESS
)
2084 DPRINT1("ScmrUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2085 SetLastError(dwError
);
2093 /**********************************************************************
2094 * NotifyBootConfigStatus
2099 NotifyBootConfigStatus(BOOL BootAcceptable
)
2103 DPRINT1("NotifyBootConfigStatus()\n");
2107 /* Call to services.exe using RPC */
2108 dwError
= ScmrNotifyBootConfigStatus(BindingHandle
,
2110 if (dwError
!= ERROR_SUCCESS
)
2112 DPRINT1("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
2113 SetLastError(dwError
);
2121 void __RPC_FAR
* __RPC_USER
midl_user_allocate(size_t len
)
2123 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
2127 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
2129 HeapFree(GetProcessHeap(), 0, ptr
);