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 if (dwError
== ERROR_MORE_DATA
)
967 DPRINT("Required buffer size %ul\n", *pcbBytesNeeded
);
968 SetLastError(dwError
);
971 else if (dwError
== ERROR_SUCCESS
)
973 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpServices
;
974 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
976 if (lpStatusPtr
->lpServiceName
)
977 lpStatusPtr
->lpServiceName
=
978 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
980 if (lpStatusPtr
->lpDisplayName
)
981 lpStatusPtr
->lpDisplayName
=
982 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
989 DPRINT1("ScmrEnumServicesStatusExA() failed (Error %lu)\n", dwError
);
990 SetLastError(dwError
);
994 DPRINT("EnumServicesStatusExA() done\n");
1000 /**********************************************************************
1001 * EnumServicesStatusExW
1006 EnumServicesStatusExW(SC_HANDLE hSCManager
,
1007 SC_ENUM_TYPE InfoLevel
,
1008 DWORD dwServiceType
,
1009 DWORD dwServiceState
,
1012 LPDWORD pcbBytesNeeded
,
1013 LPDWORD lpServicesReturned
,
1014 LPDWORD lpResumeHandle
,
1015 LPCWSTR pszGroupName
)
1017 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
1018 DWORD dwError
= ERROR_SUCCESS
;
1021 DPRINT("EnumServicesStatusExW() called\n");
1025 dwError
= ScmrEnumServicesStatusExW(BindingHandle
,
1026 (unsigned int)hSCManager
,
1027 (unsigned long)InfoLevel
,
1030 (unsigned char *)lpServices
,
1035 (wchar_t *)pszGroupName
);
1037 if (dwError
== ERROR_MORE_DATA
)
1039 DPRINT("Required buffer size %ul\n", *pcbBytesNeeded
);
1040 SetLastError(dwError
);
1043 else if (dwError
== ERROR_SUCCESS
)
1045 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpServices
;
1046 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1048 if (lpStatusPtr
->lpServiceName
)
1049 lpStatusPtr
->lpServiceName
=
1050 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1052 if (lpStatusPtr
->lpDisplayName
)
1053 lpStatusPtr
->lpDisplayName
=
1054 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1061 DPRINT1("ScmrEnumServicesStatusExW() failed (Error %lu)\n", dwError
);
1062 SetLastError(dwError
);
1066 DPRINT("EnumServicesStatusExW() done\n");
1072 /**********************************************************************
1073 * GetServiceDisplayNameA
1078 GetServiceDisplayNameA(SC_HANDLE hSCManager
,
1079 LPCSTR lpServiceName
,
1080 LPSTR lpDisplayName
,
1081 LPDWORD lpcchBuffer
)
1085 DPRINT("GetServiceDisplayNameA() called\n");
1089 dwError
= ScmrGetServiceDisplayNameA(BindingHandle
,
1090 (unsigned int)hSCManager
,
1091 (LPSTR
)lpServiceName
,
1094 if (dwError
!= ERROR_SUCCESS
)
1096 DPRINT1("ScmrGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
1097 SetLastError(dwError
);
1107 /**********************************************************************
1108 * GetServiceDisplayNameW
1113 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
1114 LPCWSTR lpServiceName
,
1115 LPWSTR lpDisplayName
,
1116 LPDWORD lpcchBuffer
)
1120 DPRINT("GetServiceDisplayNameW() called\n");
1124 dwError
= ScmrGetServiceDisplayNameW(BindingHandle
,
1125 (unsigned int)hSCManager
,
1126 (LPWSTR
)lpServiceName
,
1129 if (dwError
!= ERROR_SUCCESS
)
1131 DPRINT1("ScmrGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1132 SetLastError(dwError
);
1142 /**********************************************************************
1143 * GetServiceKeyNameA
1148 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1149 LPCSTR lpDisplayName
,
1150 LPSTR lpServiceName
,
1151 LPDWORD lpcchBuffer
)
1155 DPRINT("GetServiceKeyNameA() called\n");
1159 dwError
= ScmrGetServiceKeyNameA(BindingHandle
,
1160 (unsigned int)hSCManager
,
1161 (LPSTR
)lpDisplayName
,
1164 if (dwError
!= ERROR_SUCCESS
)
1166 DPRINT1("ScmrGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1167 SetLastError(dwError
);
1177 /**********************************************************************
1178 * GetServiceKeyNameW
1183 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1184 LPCWSTR lpDisplayName
,
1185 LPWSTR lpServiceName
,
1186 LPDWORD lpcchBuffer
)
1190 DPRINT("GetServiceKeyNameW() called\n");
1194 dwError
= ScmrGetServiceKeyNameW(BindingHandle
,
1195 (unsigned int)hSCManager
,
1196 (LPWSTR
)lpDisplayName
,
1199 if (dwError
!= ERROR_SUCCESS
)
1201 DPRINT1("ScmrGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1202 SetLastError(dwError
);
1212 /**********************************************************************
1213 * LockServiceDatabase
1218 LockServiceDatabase(SC_HANDLE hSCManager
)
1223 DPRINT("LockServiceDatabase(%x)\n", hSCManager
);
1227 /* Call to services.exe using RPC */
1228 dwError
= ScmrLockServiceDatabase(BindingHandle
,
1229 (unsigned int)hSCManager
,
1230 (unsigned int *)&hLock
);
1231 if (dwError
!= ERROR_SUCCESS
)
1233 DPRINT1("ScmrLockServiceDatabase() failed (Error %lu)\n", dwError
);
1234 SetLastError(dwError
);
1238 DPRINT("hLock = %p\n", hLock
);
1245 WaitForSCManager(VOID
)
1249 DPRINT("WaitForSCManager() called\n");
1251 /* Try to open the existing event */
1252 hEvent
= OpenEventW(SYNCHRONIZE
,
1254 L
"SvcctrlStartEvent_A3752DX");
1257 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1260 /* Try to create a new event */
1261 hEvent
= CreateEventW(NULL
,
1264 L
"SvcctrlStartEvent_A3752DX");
1267 /* Try to open the existing event again */
1268 hEvent
= OpenEventW(SYNCHRONIZE
,
1270 L
"SvcctrlStartEvent_A3752DX");
1276 /* Wait for 3 minutes */
1277 WaitForSingleObject(hEvent
, 180000);
1278 CloseHandle(hEvent
);
1280 DPRINT("ScmWaitForSCManager() done\n");
1284 /**********************************************************************
1290 OpenSCManagerA(LPCSTR lpMachineName
,
1291 LPCSTR lpDatabaseName
,
1292 DWORD dwDesiredAccess
)
1294 SC_HANDLE hScm
= NULL
;
1297 DPRINT("OpenSCManagerA(%s, %s, %lx)\n",
1298 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1304 /* Call to services.exe using RPC */
1305 dwError
= ScmrOpenSCManagerA(BindingHandle
,
1306 (LPSTR
)lpMachineName
,
1307 (LPSTR
)lpDatabaseName
,
1309 (unsigned int*)&hScm
);
1310 if (dwError
!= ERROR_SUCCESS
)
1312 DPRINT1("ScmrOpenSCManagerA() failed (Error %lu)\n", dwError
);
1313 SetLastError(dwError
);
1317 DPRINT("hScm = %p\n", hScm
);
1323 /**********************************************************************
1329 OpenSCManagerW(LPCWSTR lpMachineName
,
1330 LPCWSTR lpDatabaseName
,
1331 DWORD dwDesiredAccess
)
1333 SC_HANDLE hScm
= NULL
;
1336 DPRINT("OpenSCManagerW(%S, %S, %lx)\n",
1337 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1343 /* Call to services.exe using RPC */
1344 dwError
= ScmrOpenSCManagerW(BindingHandle
,
1345 (LPWSTR
)lpMachineName
,
1346 (LPWSTR
)lpDatabaseName
,
1348 (unsigned int*)&hScm
);
1349 if (dwError
!= ERROR_SUCCESS
)
1351 DPRINT1("ScmrOpenSCManagerW() failed (Error %lu)\n", dwError
);
1352 SetLastError(dwError
);
1356 DPRINT("hScm = %p\n", hScm
);
1362 /**********************************************************************
1368 OpenServiceA(SC_HANDLE hSCManager
,
1369 LPCSTR lpServiceName
,
1370 DWORD dwDesiredAccess
)
1372 SC_HANDLE hService
= NULL
;
1375 DPRINT("OpenServiceA(%p, %s, %lx)\n",
1376 hSCManager
, lpServiceName
, dwDesiredAccess
);
1380 /* Call to services.exe using RPC */
1381 dwError
= ScmrOpenServiceA(BindingHandle
,
1382 (unsigned int)hSCManager
,
1383 (LPSTR
)lpServiceName
,
1385 (unsigned int*)&hService
);
1386 if (dwError
!= ERROR_SUCCESS
)
1388 DPRINT1("ScmrOpenServiceA() failed (Error %lu)\n", dwError
);
1389 SetLastError(dwError
);
1393 DPRINT("hService = %p\n", hService
);
1399 /**********************************************************************
1405 OpenServiceW(SC_HANDLE hSCManager
,
1406 LPCWSTR lpServiceName
,
1407 DWORD dwDesiredAccess
)
1409 SC_HANDLE hService
= NULL
;
1412 DPRINT("OpenServiceW(%p, %S, %lx)\n",
1413 hSCManager
, lpServiceName
, dwDesiredAccess
);
1417 /* Call to services.exe using RPC */
1418 dwError
= ScmrOpenServiceW(BindingHandle
,
1419 (unsigned int)hSCManager
,
1420 (LPWSTR
)lpServiceName
,
1422 (unsigned int*)&hService
);
1423 if (dwError
!= ERROR_SUCCESS
)
1425 DPRINT("ScmrOpenServiceW() failed (Error %lu)\n", dwError
);
1426 SetLastError(dwError
);
1430 DPRINT("hService = %p\n", hService
);
1436 /**********************************************************************
1437 * QueryServiceConfigA
1442 QueryServiceConfigA(SC_HANDLE hService
,
1443 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
1445 LPDWORD pcbBytesNeeded
)
1449 DPRINT("QueryServiceConfigA(%p, %p, %lu, %p)\n",
1450 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1454 /* Call to services.exe using RPC */
1455 dwError
= ScmrQueryServiceConfigA(BindingHandle
,
1456 (unsigned int)hService
,
1457 (unsigned char *)lpServiceConfig
,
1460 if (dwError
!= ERROR_SUCCESS
)
1462 DPRINT("ScmrQueryServiceConfigA() failed (Error %lu)\n", dwError
);
1463 SetLastError(dwError
);
1467 /* Adjust the pointers */
1468 if (lpServiceConfig
->lpBinaryPathName
)
1469 lpServiceConfig
->lpBinaryPathName
=
1470 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1471 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1473 if (lpServiceConfig
->lpLoadOrderGroup
)
1474 lpServiceConfig
->lpLoadOrderGroup
=
1475 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1476 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1478 if (lpServiceConfig
->lpDependencies
)
1479 lpServiceConfig
->lpDependencies
=
1480 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1481 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1483 if (lpServiceConfig
->lpServiceStartName
)
1484 lpServiceConfig
->lpServiceStartName
=
1485 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1486 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1488 if (lpServiceConfig
->lpDisplayName
)
1489 lpServiceConfig
->lpDisplayName
=
1490 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1491 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1493 DPRINT("QueryServiceConfigA() done\n");
1499 /**********************************************************************
1500 * QueryServiceConfigW
1505 QueryServiceConfigW(SC_HANDLE hService
,
1506 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
1508 LPDWORD pcbBytesNeeded
)
1512 DPRINT("QueryServiceConfigW(%p, %p, %lu, %p)\n",
1513 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1517 /* Call to services.exe using RPC */
1518 dwError
= ScmrQueryServiceConfigW(BindingHandle
,
1519 (unsigned int)hService
,
1520 (unsigned char *)lpServiceConfig
,
1523 if (dwError
!= ERROR_SUCCESS
)
1525 DPRINT("ScmrQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1526 SetLastError(dwError
);
1530 /* Adjust the pointers */
1531 if (lpServiceConfig
->lpBinaryPathName
)
1532 lpServiceConfig
->lpBinaryPathName
=
1533 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1534 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1536 if (lpServiceConfig
->lpLoadOrderGroup
)
1537 lpServiceConfig
->lpLoadOrderGroup
=
1538 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1539 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1541 if (lpServiceConfig
->lpDependencies
)
1542 lpServiceConfig
->lpDependencies
=
1543 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1544 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1546 if (lpServiceConfig
->lpServiceStartName
)
1547 lpServiceConfig
->lpServiceStartName
=
1548 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1549 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1551 if (lpServiceConfig
->lpDisplayName
)
1552 lpServiceConfig
->lpDisplayName
=
1553 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1554 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1556 DPRINT("QueryServiceConfigW() done\n");
1562 /**********************************************************************
1563 * QueryServiceConfig2A
1568 QueryServiceConfig2A(SC_HANDLE hService
,
1572 LPDWORD pcbBytesNeeded
)
1576 DPRINT("QueryServiceConfig2A(%p, %lu, %p, %lu, %p)\n",
1577 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1581 /* Call to services.exe using RPC */
1582 dwError
= ScmrQueryServiceConfig2A(BindingHandle
,
1583 (unsigned int)hService
,
1585 (unsigned char *)lpBuffer
,
1588 if (dwError
!= ERROR_SUCCESS
)
1590 DPRINT("ScmrQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
1591 SetLastError(dwError
);
1595 switch (dwInfoLevel
)
1597 case SERVICE_CONFIG_DESCRIPTION
:
1599 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
1601 if (lpPtr
->lpDescription
!= NULL
)
1602 lpPtr
->lpDescription
=
1603 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1607 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1609 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpBuffer
;
1611 if (lpPtr
->lpRebootMsg
!= NULL
)
1612 lpPtr
->lpRebootMsg
=
1613 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1615 if (lpPtr
->lpCommand
!= NULL
)
1617 (LPSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1619 if (lpPtr
->lpsaActions
!= NULL
)
1620 lpPtr
->lpsaActions
=
1621 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1626 DPRINT1("Unknown info level 0x%lx\n", dwInfoLevel
);
1627 SetLastError(ERROR_INVALID_PARAMETER
);
1631 DPRINT("QueryServiceConfig2A() done\n");
1637 /**********************************************************************
1638 * QueryServiceConfig2W
1643 QueryServiceConfig2W(SC_HANDLE hService
,
1647 LPDWORD pcbBytesNeeded
)
1651 DPRINT("QueryServiceConfig2W(%p, %lu, %p, %lu, %p)\n",
1652 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
1656 /* Call to services.exe using RPC */
1657 dwError
= ScmrQueryServiceConfig2W(BindingHandle
,
1658 (unsigned int)hService
,
1660 (unsigned char *)lpBuffer
,
1663 if (dwError
!= ERROR_SUCCESS
)
1665 DPRINT("ScmrQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
1666 SetLastError(dwError
);
1670 switch (dwInfoLevel
)
1672 case SERVICE_CONFIG_DESCRIPTION
:
1674 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
1676 if (lpPtr
->lpDescription
!= NULL
)
1677 lpPtr
->lpDescription
=
1678 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpDescription
);
1682 case SERVICE_CONFIG_FAILURE_ACTIONS
:
1684 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
1686 if (lpPtr
->lpRebootMsg
!= NULL
)
1687 lpPtr
->lpRebootMsg
=
1688 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpRebootMsg
);
1690 if (lpPtr
->lpCommand
!= NULL
)
1692 (LPWSTR
)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpCommand
);
1694 if (lpPtr
->lpsaActions
!= NULL
)
1695 lpPtr
->lpsaActions
=
1696 (SC_ACTION
*)((UINT_PTR
)lpPtr
+ (UINT_PTR
)lpPtr
->lpsaActions
);
1701 DPRINT1("Unknown info level 0x%lx\n", dwInfoLevel
);
1702 SetLastError(ERROR_INVALID_PARAMETER
);
1706 DPRINT("QueryServiceConfig2W() done\n");
1712 /**********************************************************************
1713 * QueryServiceLockStatusA
1718 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
1719 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
1721 LPDWORD pcbBytesNeeded
)
1725 DPRINT("QueryServiceLockStatusA() called\n");
1729 /* Call to services.exe using RPC */
1730 dwError
= ScmrQueryServiceLockStatusA(BindingHandle
,
1731 (unsigned int)hSCManager
,
1732 (unsigned char *)lpLockStatus
,
1735 if (dwError
!= ERROR_SUCCESS
)
1737 DPRINT("ScmrQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
1738 SetLastError(dwError
);
1742 if (lpLockStatus
->lpLockOwner
!= NULL
)
1744 lpLockStatus
->lpLockOwner
=
1745 (LPSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
1748 DPRINT("QueryServiceLockStatusA() done\n");
1754 /**********************************************************************
1755 * QueryServiceLockStatusW
1760 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
1761 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
1763 LPDWORD pcbBytesNeeded
)
1767 DPRINT("QueryServiceLockStatusW() called\n");
1771 /* Call to services.exe using RPC */
1772 dwError
= ScmrQueryServiceLockStatusW(BindingHandle
,
1773 (unsigned int)hSCManager
,
1774 (unsigned char *)lpLockStatus
,
1777 if (dwError
!= ERROR_SUCCESS
)
1779 DPRINT("ScmrQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
1780 SetLastError(dwError
);
1784 if (lpLockStatus
->lpLockOwner
!= NULL
)
1786 lpLockStatus
->lpLockOwner
=
1787 (LPWSTR
)((UINT_PTR
)lpLockStatus
+ (UINT_PTR
)lpLockStatus
->lpLockOwner
);
1790 DPRINT("QueryServiceLockStatusW() done\n");
1796 /**********************************************************************
1797 * QueryServiceObjectSecurity
1802 QueryServiceObjectSecurity(SC_HANDLE hService
,
1803 SECURITY_INFORMATION dwSecurityInformation
,
1804 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
1806 LPDWORD pcbBytesNeeded
)
1810 DPRINT("QueryServiceObjectSecurity(%p, %lu, %p)\n",
1811 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
1815 /* Call to services.exe using RPC */
1816 dwError
= ScmrQueryServiceObjectSecurity(BindingHandle
,
1817 (unsigned int)hService
,
1818 dwSecurityInformation
,
1819 (unsigned char *)lpSecurityDescriptor
,
1822 if (dwError
!= ERROR_SUCCESS
)
1824 DPRINT1("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
1825 SetLastError(dwError
);
1832 /**********************************************************************
1833 * SetServiceObjectSecurity
1838 SetServiceObjectSecurity(SC_HANDLE hService
,
1839 SECURITY_INFORMATION dwSecurityInformation
,
1840 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
1842 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
1848 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
1851 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
1853 SetLastError(ERROR_INVALID_PARAMETER
);
1857 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
1858 if (SelfRelativeSD
== NULL
)
1860 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1864 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
1867 if (!NT_SUCCESS(Status
))
1869 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
1870 SetLastError(RtlNtStatusToDosError(Status
));
1876 /* Call to services.exe using RPC */
1877 dwError
= ScmrSetServiceObjectSecurity(BindingHandle
,
1878 (unsigned int)hService
,
1879 dwSecurityInformation
,
1880 (unsigned char *)SelfRelativeSD
,
1883 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
1885 if (dwError
!= ERROR_SUCCESS
)
1887 DPRINT1("ScmrServiceObjectSecurity() failed (Error %lu)\n", dwError
);
1888 SetLastError(dwError
);
1896 /**********************************************************************
1897 * QueryServiceStatus
1902 QueryServiceStatus(SC_HANDLE hService
,
1903 LPSERVICE_STATUS lpServiceStatus
)
1907 DPRINT("QueryServiceStatus(%p, %p)\n",
1908 hService
, lpServiceStatus
);
1912 /* Call to services.exe using RPC */
1913 dwError
= ScmrQueryServiceStatus(BindingHandle
,
1914 (unsigned int)hService
,
1916 if (dwError
!= ERROR_SUCCESS
)
1918 DPRINT1("ScmrQueryServiceStatus() failed (Error %lu)\n", dwError
);
1919 SetLastError(dwError
);
1927 /**********************************************************************
1928 * QueryServiceStatusEx
1933 QueryServiceStatusEx(SC_HANDLE hService
,
1934 SC_STATUS_TYPE InfoLevel
,
1937 LPDWORD pcbBytesNeeded
)
1941 DPRINT("QueryServiceStatusEx() called\n");
1945 /* Call to services.exe using RPC */
1946 dwError
= ScmrQueryServiceStatusEx(BindingHandle
,
1947 (unsigned int)hService
,
1952 if (dwError
!= ERROR_SUCCESS
)
1954 DPRINT("ScmrQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
1955 SetLastError(dwError
);
1962 /**********************************************************************
1968 SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus
,
1969 LPSERVICE_STATUS lpServiceStatus
)
1973 DPRINT("SetServiceStatus() called\n");
1974 DPRINT("ThreadId %lu, data addr %p called\n", hServiceStatus
, lpServiceStatus
);
1978 /* Call to services.exe using RPC */
1979 dwError
= ScmrSetServiceStatus(BindingHandle
,
1980 (unsigned long)hServiceStatus
,
1982 if (dwError
!= ERROR_SUCCESS
)
1984 DPRINT1("ScmrSetServiceStatus() failed (Error %lu)\n", dwError
);
1985 SetLastError(dwError
);
1989 DPRINT("SetServiceStatus() done (ret %lu\n", dwError
);
1995 /**********************************************************************
2001 StartServiceA(SC_HANDLE hService
,
2002 DWORD dwNumServiceArgs
,
2003 LPCSTR
*lpServiceArgVectors
)
2012 for (i
= 0; i
< dwNumServiceArgs
; i
++)
2014 dwBufSize
+= (strlen(lpServiceArgVectors
[i
]) + 1);
2017 DPRINT1("dwBufSize: %lu\n", dwBufSize
);
2019 lpBuffer
= HeapAlloc(GetProcessHeap(), 0, dwBufSize
);
2020 if (lpBuffer
== NULL
)
2022 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2027 for (i
= 0; i
< dwNumServiceArgs
; i
++)
2029 strcpy(lpStr
, lpServiceArgVectors
[i
]);
2030 lpStr
+= (strlen(lpServiceArgVectors
[i
]) + 1);
2034 dwError
= ScmrStartServiceA(BindingHandle
,
2035 (unsigned int)hService
,
2037 (unsigned char *)lpBuffer
,
2040 HeapFree(GetProcessHeap(), 0, lpBuffer
);
2042 if (dwError
!= ERROR_SUCCESS
)
2044 DPRINT1("ScmrStartServiceA() failed (Error %lu)\n", dwError
);
2045 SetLastError(dwError
);
2053 /**********************************************************************
2059 StartServiceW(SC_HANDLE hService
,
2060 DWORD dwNumServiceArgs
,
2061 LPCWSTR
*lpServiceArgVectors
)
2070 for (i
= 0; i
< dwNumServiceArgs
; i
++)
2072 dwBufSize
+= ((wcslen(lpServiceArgVectors
[i
]) + 1) * sizeof(WCHAR
));
2074 dwBufSize
+= sizeof(WCHAR
);
2075 DPRINT("dwBufSize: %lu\n", dwBufSize
);
2077 lpBuffer
= HeapAlloc(GetProcessHeap(), 0, dwBufSize
);
2078 if (lpBuffer
== NULL
)
2080 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2085 for (i
= 0; i
< dwNumServiceArgs
; i
++)
2087 wcscpy(lpStr
, lpServiceArgVectors
[i
]);
2088 lpStr
+= (wcslen(lpServiceArgVectors
[i
]) + 1);
2092 dwError
= ScmrStartServiceW(BindingHandle
,
2093 (unsigned int)hService
,
2095 (unsigned char *)lpBuffer
,
2098 HeapFree(GetProcessHeap(), 0, lpBuffer
);
2100 if (dwError
!= ERROR_SUCCESS
)
2102 DPRINT1("ScmrStartServiceW() failed (Error %lu)\n", dwError
);
2103 SetLastError(dwError
);
2111 /**********************************************************************
2112 * UnlockServiceDatabase
2117 UnlockServiceDatabase(SC_LOCK ScLock
)
2121 DPRINT("UnlockServiceDatabase(%x)\n", ScLock
);
2125 /* Call to services.exe using RPC */
2126 dwError
= ScmrUnlockServiceDatabase(BindingHandle
,
2127 (unsigned int)ScLock
);
2128 if (dwError
!= ERROR_SUCCESS
)
2130 DPRINT1("ScmrUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2131 SetLastError(dwError
);
2139 /**********************************************************************
2140 * NotifyBootConfigStatus
2145 NotifyBootConfigStatus(BOOL BootAcceptable
)
2149 DPRINT1("NotifyBootConfigStatus()\n");
2153 /* Call to services.exe using RPC */
2154 dwError
= ScmrNotifyBootConfigStatus(BindingHandle
,
2156 if (dwError
!= ERROR_SUCCESS
)
2158 DPRINT1("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
2159 SetLastError(dwError
);