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 ******************************************************************/
21 /* FUNCTIONS *****************************************************************/
23 handle_t BindingHandle
= NULL
;
28 LPWSTR pszStringBinding
;
31 if (BindingHandle
!= NULL
)
34 status
= RpcStringBindingComposeW(NULL
,
42 DPRINT1("RpcStringBindingCompose returned 0x%x\n", status
);
46 /* Set the binding handle that will be used to bind to the server. */
47 status
= RpcBindingFromStringBindingW(pszStringBinding
,
51 DPRINT1("RpcBindingFromStringBinding returned 0x%x\n", status
);
54 status
= RpcStringFreeW(&pszStringBinding
);
57 DPRINT1("RpcStringFree returned 0x%x\n", status
);
68 if (BindingHandle
== NULL
)
71 status
= RpcBindingFree(&BindingHandle
);
74 DPRINT1("RpcBindingFree returned 0x%x\n", status
);
80 /**********************************************************************
81 * ChangeServiceConfigA
86 ChangeServiceConfigA(SC_HANDLE hService
,
90 LPCSTR lpBinaryPathName
,
91 LPCSTR lpLoadOrderGroup
,
93 LPCSTR lpDependencies
,
94 LPCSTR lpServiceStartName
,
99 DWORD dwDependenciesLength
= 0;
103 DPRINT("ChangeServiceConfigA() called\n");
105 /* Calculate the Dependencies length*/
106 if (lpDependencies
!= NULL
)
108 lpStr
= (LPSTR
)lpDependencies
;
111 dwLength
= strlen(lpStr
) + 1;
112 dwDependenciesLength
+= dwLength
;
113 lpStr
= lpStr
+ dwLength
;
115 dwDependenciesLength
++;
118 /* FIXME: Encrypt the password */
122 /* Call to services.exe using RPC */
123 dwError
= ScmrChangeServiceConfigA(BindingHandle
,
124 (unsigned int)hService
,
128 (LPSTR
)lpBinaryPathName
,
129 (LPSTR
)lpLoadOrderGroup
,
131 (LPSTR
)lpDependencies
,
132 dwDependenciesLength
,
133 (LPSTR
)lpServiceStartName
,
134 NULL
, /* FIXME: lpPassword */
135 0, /* FIXME: dwPasswordLength */
136 (LPSTR
)lpDisplayName
);
137 if (dwError
!= ERROR_SUCCESS
)
139 DPRINT1("ScmrChangeServiceConfigA() failed (Error %lu)\n", dwError
);
140 SetLastError(dwError
);
148 /**********************************************************************
149 * ChangeServiceConfigW
154 ChangeServiceConfigW(SC_HANDLE hService
,
157 DWORD dwErrorControl
,
158 LPCWSTR lpBinaryPathName
,
159 LPCWSTR lpLoadOrderGroup
,
161 LPCWSTR lpDependencies
,
162 LPCWSTR lpServiceStartName
,
164 LPCWSTR lpDisplayName
)
167 DWORD dwDependenciesLength
= 0;
171 DPRINT("ChangeServiceConfigW() called\n");
173 /* Calculate the Dependencies length*/
174 if (lpDependencies
!= NULL
)
176 lpStr
= (LPWSTR
)lpDependencies
;
179 dwLength
= wcslen(lpStr
) + 1;
180 dwDependenciesLength
+= dwLength
;
181 lpStr
= lpStr
+ dwLength
;
183 dwDependenciesLength
++;
186 /* FIXME: Encrypt the password */
190 /* Call to services.exe using RPC */
191 dwError
= ScmrChangeServiceConfigW(BindingHandle
,
192 (unsigned int)hService
,
196 (LPWSTR
)lpBinaryPathName
,
197 (LPWSTR
)lpLoadOrderGroup
,
199 (LPWSTR
)lpDependencies
,
200 dwDependenciesLength
,
201 (LPWSTR
)lpServiceStartName
,
202 NULL
, /* FIXME: lpPassword */
203 0, /* FIXME: dwPasswordLength */
204 (LPWSTR
)lpDisplayName
);
205 if (dwError
!= ERROR_SUCCESS
)
207 DPRINT1("ScmrChangeServiceConfigW() failed (Error %lu)\n", dwError
);
208 SetLastError(dwError
);
216 /**********************************************************************
222 CloseServiceHandle(SC_HANDLE hSCObject
)
226 DPRINT("CloseServiceHandle() called\n");
230 /* Call to services.exe using RPC */
231 dwError
= ScmrCloseServiceHandle(BindingHandle
,
232 (unsigned int)hSCObject
);
235 DPRINT1("ScmrCloseServiceHandle() failed (Error %lu)\n", dwError
);
236 SetLastError(dwError
);
240 DPRINT("CloseServiceHandle() done\n");
246 /**********************************************************************
252 ControlService(SC_HANDLE hService
,
254 LPSERVICE_STATUS lpServiceStatus
)
258 DPRINT("ControlService(%x, %x, %p)\n",
259 hService
, dwControl
, lpServiceStatus
);
263 /* Call to services.exe using RPC */
264 dwError
= ScmrControlService(BindingHandle
,
265 (unsigned int)hService
,
268 if (dwError
!= ERROR_SUCCESS
)
270 DPRINT1("ScmrControlService() failed (Error %lu)\n", dwError
);
271 SetLastError(dwError
);
275 DPRINT("ControlService() done\n");
281 /**********************************************************************
287 ControlServiceEx(IN SC_HANDLE hService
,
289 IN DWORD dwInfoLevel
,
290 IN OUT PVOID pControlParams
)
292 DPRINT1("ControlServiceEx(0x%p, 0x%x, 0x%x, 0x%p) UNIMPLEMENTED!\n",
293 hService
, dwControl
, dwInfoLevel
, pControlParams
);
294 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
300 /**********************************************************************
307 CreateServiceA(SC_HANDLE hSCManager
,
308 LPCSTR lpServiceName
,
309 LPCSTR lpDisplayName
,
310 DWORD dwDesiredAccess
,
313 DWORD dwErrorControl
,
314 LPCSTR lpBinaryPathName
,
315 LPCSTR lpLoadOrderGroup
,
317 LPCSTR lpDependencies
,
318 LPCSTR lpServiceStartName
,
321 SC_HANDLE RetVal
= NULL
;
322 LPWSTR lpServiceNameW
= NULL
;
323 LPWSTR lpDisplayNameW
= NULL
;
324 LPWSTR lpBinaryPathNameW
= NULL
;
325 LPWSTR lpLoadOrderGroupW
= NULL
;
326 LPWSTR lpDependenciesW
= NULL
;
327 LPWSTR lpServiceStartNameW
= NULL
;
328 LPWSTR lpPasswordW
= NULL
;
329 DWORD dwDependenciesLength
= 0;
333 int len
= MultiByteToWideChar(CP_ACP
, 0, lpServiceName
, -1, NULL
, 0);
334 lpServiceNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
337 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
340 MultiByteToWideChar(CP_ACP
, 0, lpServiceName
, -1, lpServiceNameW
, len
);
342 len
= MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, NULL
, 0);
343 lpDisplayNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
346 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
349 MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, lpDisplayNameW
, len
);
351 len
= MultiByteToWideChar(CP_ACP
, 0, lpBinaryPathName
, -1, NULL
, 0);
352 lpBinaryPathNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
353 if (!lpBinaryPathNameW
)
355 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
358 MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, lpBinaryPathNameW
, len
);
360 len
= MultiByteToWideChar(CP_ACP
, 0, lpLoadOrderGroup
, -1, NULL
, 0);
361 lpLoadOrderGroupW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
362 if (!lpLoadOrderGroupW
)
364 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
367 MultiByteToWideChar(CP_ACP
, 0, lpLoadOrderGroup
, -1, lpLoadOrderGroupW
, len
);
369 if (lpDependencies
!= NULL
)
371 lpStr
= (LPSTR
)lpDependencies
;
374 dwLength
= strlen(lpStr
) + 1;
375 dwDependenciesLength
+= dwLength
;
376 lpStr
= lpStr
+ dwLength
;
378 dwDependenciesLength
++;
381 lpDependenciesW
= HeapAlloc(GetProcessHeap(), 0, dwDependenciesLength
* sizeof(WCHAR
));
382 if (!lpDependenciesW
)
384 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
387 MultiByteToWideChar(CP_ACP
, 0, lpDependencies
, -1, lpDependenciesW
, dwDependenciesLength
);
389 len
= MultiByteToWideChar(CP_ACP
, 0, lpServiceStartName
, -1, NULL
, 0);
390 lpServiceStartName
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
391 if (!lpServiceStartNameW
)
393 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
396 MultiByteToWideChar(CP_ACP
, 0, lpServiceStartName
, -1, lpServiceStartNameW
, len
);
398 len
= MultiByteToWideChar(CP_ACP
, 0, lpPassword
, -1, NULL
, 0);
399 lpPasswordW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
402 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
405 MultiByteToWideChar(CP_ACP
, 0, lpPassword
, -1, lpPasswordW
, len
);
407 RetVal
= CreateServiceW(hSCManager
,
422 HeapFree(GetProcessHeap(), 0, lpServiceNameW
);
423 HeapFree(GetProcessHeap(), 0, lpDisplayNameW
);
424 HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW
);
425 HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW
);
426 HeapFree(GetProcessHeap(), 0, lpDependenciesW
);
427 HeapFree(GetProcessHeap(), 0, lpServiceStartNameW
);
428 HeapFree(GetProcessHeap(), 0, lpPasswordW
);
434 /**********************************************************************
440 CreateServiceW(SC_HANDLE hSCManager
,
441 LPCWSTR lpServiceName
,
442 LPCWSTR lpDisplayName
,
443 DWORD dwDesiredAccess
,
446 DWORD dwErrorControl
,
447 LPCWSTR lpBinaryPathName
,
448 LPCWSTR lpLoadOrderGroup
,
450 LPCWSTR lpDependencies
,
451 LPCWSTR lpServiceStartName
,
454 SC_HANDLE hService
= NULL
;
456 DWORD dwDependenciesLength
= 0;
460 DPRINT1("CreateServiceW() called\n");
462 /* Calculate the Dependencies length*/
463 if (lpDependencies
!= NULL
)
465 lpStr
= (LPWSTR
)lpDependencies
;
468 dwLength
= wcslen(lpStr
) + 1;
469 dwDependenciesLength
+= dwLength
;
470 lpStr
= lpStr
+ dwLength
;
472 dwDependenciesLength
++;
475 /* FIXME: Encrypt the password */
479 /* Call to services.exe using RPC */
480 dwError
= ScmrCreateServiceW(BindingHandle
,
481 (unsigned int)hSCManager
,
482 (LPWSTR
)lpServiceName
,
483 (LPWSTR
)lpDisplayName
,
488 (LPWSTR
)lpBinaryPathName
,
489 (LPWSTR
)lpLoadOrderGroup
,
491 (LPWSTR
)lpDependencies
,
492 dwDependenciesLength
,
493 (LPWSTR
)lpServiceStartName
,
494 NULL
, /* FIXME: lpPassword */
495 0, /* FIXME: dwPasswordLength */
496 (unsigned int *)&hService
);
497 if (dwError
!= ERROR_SUCCESS
)
499 DPRINT1("ScmrCreateServiceW() failed (Error %lu)\n", dwError
);
500 SetLastError(dwError
);
508 /**********************************************************************
514 DeleteService(SC_HANDLE hService
)
518 DPRINT("DeleteService(%x)\n", hService
);
522 /* Call to services.exe using RPC */
523 dwError
= ScmrDeleteService(BindingHandle
,
524 (unsigned int)hService
);
525 if (dwError
!= ERROR_SUCCESS
)
527 DPRINT1("ScmrDeleteService() failed (Error %lu)\n", dwError
);
528 SetLastError(dwError
);
536 /**********************************************************************
537 * EnumDependentServicesA
543 EnumDependentServicesA(
545 DWORD dwServiceState
,
546 LPENUM_SERVICE_STATUSA lpServices
,
548 LPDWORD pcbBytesNeeded
,
549 LPDWORD lpServicesReturned
)
551 DPRINT1("EnumDependentServicesA is unimplemented\n");
552 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
557 /**********************************************************************
558 * EnumDependentServicesW
564 EnumDependentServicesW(SC_HANDLE hService
,
565 DWORD dwServiceState
,
566 LPENUM_SERVICE_STATUSW lpServices
,
568 LPDWORD pcbBytesNeeded
,
569 LPDWORD lpServicesReturned
)
571 DPRINT1("EnumDependentServicesW is unimplemented\n");
572 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
577 /**********************************************************************
585 SC_HANDLE hSCManager
,
587 DWORD dwServiceState
,
588 LPENUM_SERVICE_STATUSA lpServices
,
590 LPDWORD pcbBytesNeeded
,
591 LPDWORD lpServicesReturned
,
592 LPDWORD lpResumeHandle
,
595 DPRINT1("EnumServiceGroupW is unimplemented\n");
596 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
601 /**********************************************************************
602 * EnumServicesStatusA
609 SC_HANDLE hSCManager
,
611 DWORD dwServiceState
,
612 LPENUM_SERVICE_STATUSA lpServices
,
614 LPDWORD pcbBytesNeeded
,
615 LPDWORD lpServicesReturned
,
616 LPDWORD lpResumeHandle
)
618 DPRINT1("EnumServicesStatusA is unimplemented\n");
619 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
624 /**********************************************************************
625 * EnumServicesStatusW
630 EnumServicesStatusW(SC_HANDLE hSCManager
,
632 DWORD dwServiceState
,
633 LPENUM_SERVICE_STATUSW lpServices
,
635 LPDWORD pcbBytesNeeded
,
636 LPDWORD lpServicesReturned
,
637 LPDWORD lpResumeHandle
)
639 LPENUM_SERVICE_STATUSW lpStatusPtr
;
640 DWORD dwError
= ERROR_SUCCESS
;
643 DPRINT("EnumServicesStatusW() called\n");
647 dwError
= ScmrEnumServicesStatusW(BindingHandle
,
648 (unsigned int)hSCManager
,
651 (unsigned char *)lpServices
,
657 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpServices
;
658 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
660 if (lpStatusPtr
->lpServiceName
)
661 lpStatusPtr
->lpServiceName
=
662 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
664 if (lpStatusPtr
->lpDisplayName
)
665 lpStatusPtr
->lpDisplayName
=
666 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
671 if (dwError
!= ERROR_SUCCESS
)
673 DPRINT("ScmrEnumServicesStatusW() failed (Error %lu)\n", dwError
);
674 SetLastError(dwError
);
678 DPRINT("ScmrEnumServicesStatusW() done\n");
684 /**********************************************************************
685 * EnumServicesStatusExA
691 EnumServicesStatusExA(SC_HANDLE hSCManager
,
692 SC_ENUM_TYPE InfoLevel
,
694 DWORD dwServiceState
,
697 LPDWORD pcbBytesNeeded
,
698 LPDWORD lpServicesReturned
,
699 LPDWORD lpResumeHandle
,
702 DPRINT1("EnumServicesStatusExA is unimplemented\n");
703 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
708 /**********************************************************************
709 * EnumServicesStatusExW
714 EnumServicesStatusExW(SC_HANDLE hSCManager
,
715 SC_ENUM_TYPE InfoLevel
,
717 DWORD dwServiceState
,
720 LPDWORD pcbBytesNeeded
,
721 LPDWORD lpServicesReturned
,
722 LPDWORD lpResumeHandle
,
723 LPCWSTR pszGroupName
)
725 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
726 DWORD dwError
= ERROR_SUCCESS
;
729 DPRINT1("EnumServicesStatusExW() called\n");
733 dwError
= ScmrEnumServicesStatusExW(BindingHandle
,
734 (unsigned int)hSCManager
,
735 (unsigned long)InfoLevel
,
738 (unsigned char *)lpServices
,
743 (wchar_t *)pszGroupName
);
745 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpServices
;
746 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
748 if (lpStatusPtr
->lpServiceName
)
749 lpStatusPtr
->lpServiceName
=
750 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
752 if (lpStatusPtr
->lpDisplayName
)
753 lpStatusPtr
->lpDisplayName
=
754 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
759 if (dwError
!= ERROR_SUCCESS
)
761 DPRINT1("ScmrEnumServicesStatusExW() failed (Error %lu)\n", dwError
);
762 SetLastError(dwError
);
766 DPRINT1("ScmrEnumServicesStatusExW() done\n");
772 /**********************************************************************
773 * GetServiceDisplayNameA
778 GetServiceDisplayNameA(SC_HANDLE hSCManager
,
779 LPCSTR lpServiceName
,
785 DPRINT("GetServiceDisplayNameA() called\n");
789 dwError
= ScmrGetServiceDisplayNameA(BindingHandle
,
790 (unsigned int)hSCManager
,
791 (LPSTR
)lpServiceName
,
794 if (dwError
!= ERROR_SUCCESS
)
796 DPRINT1("ScmrGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
797 SetLastError(dwError
);
807 /**********************************************************************
808 * GetServiceDisplayNameW
813 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
814 LPCWSTR lpServiceName
,
815 LPWSTR lpDisplayName
,
820 DPRINT("GetServiceDisplayNameW() called\n");
824 dwError
= ScmrGetServiceDisplayNameW(BindingHandle
,
825 (unsigned int)hSCManager
,
826 (LPWSTR
)lpServiceName
,
829 if (dwError
!= ERROR_SUCCESS
)
831 DPRINT1("ScmrGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
832 SetLastError(dwError
);
842 /**********************************************************************
848 GetServiceKeyNameA(SC_HANDLE hSCManager
,
849 LPCSTR lpDisplayName
,
855 DPRINT("GetServiceKeyNameA() called\n");
859 dwError
= ScmrGetServiceKeyNameA(BindingHandle
,
860 (unsigned int)hSCManager
,
861 (LPSTR
)lpDisplayName
,
864 if (dwError
!= ERROR_SUCCESS
)
866 DPRINT1("ScmrGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
867 SetLastError(dwError
);
877 /**********************************************************************
883 GetServiceKeyNameW(SC_HANDLE hSCManager
,
884 LPCWSTR lpDisplayName
,
885 LPWSTR lpServiceName
,
890 DPRINT("GetServiceKeyNameW() called\n");
894 dwError
= ScmrGetServiceKeyNameW(BindingHandle
,
895 (unsigned int)hSCManager
,
896 (LPWSTR
)lpDisplayName
,
899 if (dwError
!= ERROR_SUCCESS
)
901 DPRINT1("ScmrGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
902 SetLastError(dwError
);
912 /**********************************************************************
913 * LockServiceDatabase
918 LockServiceDatabase(SC_HANDLE hSCManager
)
923 DPRINT("LockServiceDatabase(%x)\n", hSCManager
);
927 /* Call to services.exe using RPC */
928 dwError
= ScmrLockServiceDatabase(BindingHandle
,
929 (unsigned int)hSCManager
,
930 (unsigned int *)&hLock
);
931 if (dwError
!= ERROR_SUCCESS
)
933 DPRINT1("ScmrLockServiceDatabase() failed (Error %lu)\n", dwError
);
934 SetLastError(dwError
);
938 DPRINT("hLock = %p\n", hLock
);
945 WaitForSCManager(VOID
)
949 DPRINT("WaitForSCManager() called\n");
951 /* Try to open the existing event */
952 hEvent
= OpenEventW(SYNCHRONIZE
,
954 L
"SvcctrlStartEvent_A3725DX");
957 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
960 /* Try to create a new event */
961 hEvent
= CreateEventW(NULL
,
964 L
"SvcctrlStartEvent_A3725DX");
967 /* Try to open the existing event again */
968 hEvent
= OpenEventW(SYNCHRONIZE
,
970 L
"SvcctrlStartEvent_A3725DX");
976 /* Wait for 3 minutes */
977 WaitForSingleObject(hEvent
, 180000);
980 DPRINT("ScmWaitForSCManager() done\n");
984 /**********************************************************************
990 OpenSCManagerA(LPCSTR lpMachineName
,
991 LPCSTR lpDatabaseName
,
992 DWORD dwDesiredAccess
)
994 SC_HANDLE hScm
= NULL
;
997 DPRINT("OpenSCManagerA(%s, %s, %lx)\n",
998 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1004 /* Call to services.exe using RPC */
1005 dwError
= ScmrOpenSCManagerA(BindingHandle
,
1006 (LPSTR
)lpMachineName
,
1007 (LPSTR
)lpDatabaseName
,
1009 (unsigned int*)&hScm
);
1010 if (dwError
!= ERROR_SUCCESS
)
1012 DPRINT1("ScmrOpenSCManagerA() failed (Error %lu)\n", dwError
);
1013 SetLastError(dwError
);
1017 DPRINT("hScm = %p\n", hScm
);
1023 /**********************************************************************
1029 OpenSCManagerW(LPCWSTR lpMachineName
,
1030 LPCWSTR lpDatabaseName
,
1031 DWORD dwDesiredAccess
)
1033 SC_HANDLE hScm
= NULL
;
1036 DPRINT("OpenSCManagerW(%S, %S, %lx)\n",
1037 lpMachineName
, lpDatabaseName
, dwDesiredAccess
);
1043 /* Call to services.exe using RPC */
1044 dwError
= ScmrOpenSCManagerW(BindingHandle
,
1045 (LPWSTR
)lpMachineName
,
1046 (LPWSTR
)lpDatabaseName
,
1048 (unsigned int*)&hScm
);
1049 if (dwError
!= ERROR_SUCCESS
)
1051 DPRINT1("ScmrOpenSCManagerW() failed (Error %lu)\n", dwError
);
1052 SetLastError(dwError
);
1056 DPRINT("hScm = %p\n", hScm
);
1062 /**********************************************************************
1068 OpenServiceA(SC_HANDLE hSCManager
,
1069 LPCSTR lpServiceName
,
1070 DWORD dwDesiredAccess
)
1072 SC_HANDLE hService
= NULL
;
1075 DPRINT("OpenServiceA(%p, %s, %lx)\n",
1076 hSCManager
, lpServiceName
, dwDesiredAccess
);
1080 /* Call to services.exe using RPC */
1081 dwError
= ScmrOpenServiceA(BindingHandle
,
1082 (unsigned int)hSCManager
,
1083 (LPSTR
)lpServiceName
,
1085 (unsigned int*)&hService
);
1086 if (dwError
!= ERROR_SUCCESS
)
1088 DPRINT1("ScmrOpenServiceA() failed (Error %lu)\n", dwError
);
1089 SetLastError(dwError
);
1093 DPRINT("hService = %p\n", hService
);
1099 /**********************************************************************
1105 OpenServiceW(SC_HANDLE hSCManager
,
1106 LPCWSTR lpServiceName
,
1107 DWORD dwDesiredAccess
)
1109 SC_HANDLE hService
= NULL
;
1112 DPRINT("OpenServiceW(%p, %S, %lx)\n",
1113 hSCManager
, lpServiceName
, dwDesiredAccess
);
1117 /* Call to services.exe using RPC */
1118 dwError
= ScmrOpenServiceW(BindingHandle
,
1119 (unsigned int)hSCManager
,
1120 (LPWSTR
)lpServiceName
,
1122 (unsigned int*)&hService
);
1123 if (dwError
!= ERROR_SUCCESS
)
1125 DPRINT1("ScmrOpenServiceW() failed (Error %lu)\n", dwError
);
1126 SetLastError(dwError
);
1130 DPRINT("hService = %p\n", hService
);
1136 /**********************************************************************
1137 * QueryServiceConfigA
1142 QueryServiceConfigA(SC_HANDLE hService
,
1143 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
1145 LPDWORD pcbBytesNeeded
)
1149 DPRINT("QueryServiceConfigA(%p, %p, %lu, %p)\n",
1150 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1154 /* Call to services.exe using RPC */
1155 dwError
= ScmrQueryServiceConfigA(BindingHandle
,
1156 (unsigned int)hService
,
1157 (unsigned char *)lpServiceConfig
,
1160 if (dwError
!= ERROR_SUCCESS
)
1162 DPRINT("ScmrQueryServiceConfigA() failed (Error %lu)\n", dwError
);
1163 SetLastError(dwError
);
1167 /* Adjust the pointers */
1168 if (lpServiceConfig
->lpBinaryPathName
)
1169 lpServiceConfig
->lpBinaryPathName
=
1170 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1171 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1173 if (lpServiceConfig
->lpLoadOrderGroup
)
1174 lpServiceConfig
->lpLoadOrderGroup
=
1175 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1176 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1178 if (lpServiceConfig
->lpDependencies
)
1179 lpServiceConfig
->lpDependencies
=
1180 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1181 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1183 if (lpServiceConfig
->lpServiceStartName
)
1184 lpServiceConfig
->lpServiceStartName
=
1185 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1186 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1188 if (lpServiceConfig
->lpDisplayName
)
1189 lpServiceConfig
->lpDisplayName
=
1190 (LPSTR
)((ULONG_PTR
)lpServiceConfig
+
1191 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1193 DPRINT("QueryServiceConfigA() done\n");
1199 /**********************************************************************
1200 * QueryServiceConfigW
1205 QueryServiceConfigW(SC_HANDLE hService
,
1206 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
1208 LPDWORD pcbBytesNeeded
)
1212 DPRINT("QueryServiceConfigW(%p, %p, %lu, %p)\n",
1213 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
1217 /* Call to services.exe using RPC */
1218 dwError
= ScmrQueryServiceConfigW(BindingHandle
,
1219 (unsigned int)hService
,
1220 (unsigned char *)lpServiceConfig
,
1223 if (dwError
!= ERROR_SUCCESS
)
1225 DPRINT("ScmrQueryServiceConfigW() failed (Error %lu)\n", dwError
);
1226 SetLastError(dwError
);
1230 /* Adjust the pointers */
1231 if (lpServiceConfig
->lpBinaryPathName
)
1232 lpServiceConfig
->lpBinaryPathName
=
1233 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1234 (ULONG_PTR
)lpServiceConfig
->lpBinaryPathName
);
1236 if (lpServiceConfig
->lpLoadOrderGroup
)
1237 lpServiceConfig
->lpLoadOrderGroup
=
1238 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1239 (ULONG_PTR
)lpServiceConfig
->lpLoadOrderGroup
);
1241 if (lpServiceConfig
->lpDependencies
)
1242 lpServiceConfig
->lpDependencies
=
1243 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1244 (ULONG_PTR
)lpServiceConfig
->lpDependencies
);
1246 if (lpServiceConfig
->lpServiceStartName
)
1247 lpServiceConfig
->lpServiceStartName
=
1248 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1249 (ULONG_PTR
)lpServiceConfig
->lpServiceStartName
);
1251 if (lpServiceConfig
->lpDisplayName
)
1252 lpServiceConfig
->lpDisplayName
=
1253 (LPWSTR
)((ULONG_PTR
)lpServiceConfig
+
1254 (ULONG_PTR
)lpServiceConfig
->lpDisplayName
);
1256 DPRINT("QueryServiceConfigW() done\n");
1262 /**********************************************************************
1263 * QueryServiceConfig2A
1269 QueryServiceConfig2A(
1274 LPDWORD pcbBytesNeeded
)
1276 DPRINT1("QueryServiceConfig2A is unimplemented\n");
1281 /**********************************************************************
1282 * QueryServiceConfig2W
1288 QueryServiceConfig2W(
1293 LPDWORD pcbBytesNeeded
)
1295 DPRINT1("QueryServiceConfig2W is unimplemented\n");
1300 /**********************************************************************
1301 * QueryServiceLockStatusA
1307 QueryServiceLockStatusA(
1308 SC_HANDLE hSCManager
,
1309 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
1311 LPDWORD pcbBytesNeeded
)
1313 DPRINT1("QueryServiceLockStatusA is unimplemented\n");
1314 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1319 /**********************************************************************
1320 * QueryServiceLockStatusW
1326 QueryServiceLockStatusW(
1327 SC_HANDLE hSCManager
,
1328 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
1330 LPDWORD pcbBytesNeeded
)
1332 DPRINT1("QueryServiceLockStatusW is unimplemented\n");
1333 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1338 /**********************************************************************
1339 * QueryServiceObjectSecurity
1344 QueryServiceObjectSecurity(SC_HANDLE hService
,
1345 SECURITY_INFORMATION dwSecurityInformation
,
1346 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
1348 LPDWORD pcbBytesNeeded
)
1352 DPRINT("QueryServiceObjectSecurity(%p, %lu, %p)\n",
1353 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
1357 /* Call to services.exe using RPC */
1358 dwError
= ScmrQueryServiceObjectSecurity(BindingHandle
,
1359 (unsigned int)hService
,
1360 dwSecurityInformation
,
1361 (unsigned char *)lpSecurityDescriptor
,
1364 if (dwError
!= ERROR_SUCCESS
)
1366 DPRINT1("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
1367 SetLastError(dwError
);
1375 /**********************************************************************
1376 * QueryServiceStatus
1381 QueryServiceStatus(SC_HANDLE hService
,
1382 LPSERVICE_STATUS lpServiceStatus
)
1386 DPRINT("QueryServiceStatus(%p, %p)\n",
1387 hService
, lpServiceStatus
);
1391 /* Call to services.exe using RPC */
1392 dwError
= ScmrQueryServiceStatus(BindingHandle
,
1393 (unsigned int)hService
,
1395 if (dwError
!= ERROR_SUCCESS
)
1397 DPRINT1("ScmrQueryServiceStatus() failed (Error %lu)\n", dwError
);
1398 SetLastError(dwError
);
1406 /**********************************************************************
1407 * QueryServiceStatusEx
1412 QueryServiceStatusEx(SC_HANDLE hService
,
1413 SC_STATUS_TYPE InfoLevel
,
1416 LPDWORD pcbBytesNeeded
)
1420 DPRINT("QueryServiceStatusEx() called\n");
1424 /* Call to services.exe using RPC */
1425 dwError
= ScmrQueryServiceStatusEx(BindingHandle
,
1426 (unsigned int)hService
,
1431 if (dwError
!= ERROR_SUCCESS
)
1433 DPRINT("ScmrQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
1434 SetLastError(dwError
);
1442 /**********************************************************************
1443 * SetServiceObjectSecurity
1448 SetServiceObjectSecurity(SC_HANDLE hService
,
1449 SECURITY_INFORMATION dwSecurityInformation
,
1450 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
1452 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
1458 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
1461 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
1463 SetLastError(ERROR_INVALID_PARAMETER
);
1467 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
1468 if (SelfRelativeSD
== NULL
)
1470 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1474 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
1477 if (!NT_SUCCESS(Status
))
1479 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
1480 SetLastError(RtlNtStatusToDosError(Status
));
1486 /* Call to services.exe using RPC */
1487 dwError
= ScmrSetServiceObjectSecurity(BindingHandle
,
1488 (unsigned int)hService
,
1489 dwSecurityInformation
,
1490 (unsigned char *)SelfRelativeSD
,
1493 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
1495 if (dwError
!= ERROR_SUCCESS
)
1497 DPRINT1("ScmrServiceObjectSecurity() failed (Error %lu)\n", dwError
);
1498 SetLastError(dwError
);
1506 /**********************************************************************
1515 DWORD dwNumServiceArgs
,
1516 LPCSTR
*lpServiceArgVectors
)
1518 DPRINT1("StartServiceA is unimplemented\n");
1519 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1524 /**********************************************************************
1533 DWORD dwNumServiceArgs
,
1534 LPCWSTR
*lpServiceArgVectors
)
1539 DPRINT("StartServiceW()\n", ScLock
);
1543 /* Call to services.exe using RPC */
1544 dwError
= ScmrStartServiceW(BindingHandle
,
1546 lpServiceArgVectors
);
1547 if (dwError
!= ERROR_SUCCESS
)
1549 DPRINT1("ScmrStartServiceW() failed (Error %lu)\n", dwError
);
1550 SetLastError(dwError
);
1556 DPRINT1("StartServiceW is unimplemented, but returns success...\n");
1557 //SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1563 /**********************************************************************
1564 * UnlockServiceDatabase
1569 UnlockServiceDatabase(SC_LOCK ScLock
)
1573 DPRINT("UnlockServiceDatabase(%x)\n", ScLock
);
1577 /* Call to services.exe using RPC */
1578 dwError
= ScmrUnlockServiceDatabase(BindingHandle
,
1579 (unsigned int)ScLock
);
1580 if (dwError
!= ERROR_SUCCESS
)
1582 DPRINT1("ScmrUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
1583 SetLastError(dwError
);
1591 /**********************************************************************
1592 * NotifyBootConfigStatus
1597 NotifyBootConfigStatus(BOOL BootAcceptable
)
1601 DPRINT1("NotifyBootConfigStatus()\n");
1605 /* Call to services.exe using RPC */
1606 dwError
= ScmrNotifyBootConfigStatus(BindingHandle
,
1608 if (dwError
!= ERROR_SUCCESS
)
1610 DPRINT1("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
1611 SetLastError(dwError
);
1619 void __RPC_FAR
* __RPC_USER
midl_user_allocate(size_t len
)
1621 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
1625 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
1627 HeapFree(GetProcessHeap(), 0, ptr
);