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
10 /* INCLUDES ******************************************************************/
13 WINE_DEFAULT_DEBUG_CHANNEL(advapi
);
18 const struct ustring
*in
,
19 const struct ustring
*key
,
22 /* FUNCTIONS *****************************************************************/
25 SVCCTL_HANDLEA_bind(SVCCTL_HANDLEA szMachineName
)
27 handle_t hBinding
= NULL
;
28 RPC_CSTR pszStringBinding
;
31 TRACE("SVCCTL_HANDLEA_bind(%s)\n",
32 debugstr_a(szMachineName
));
34 status
= RpcStringBindingComposeA(NULL
,
36 (RPC_CSTR
)szMachineName
,
37 (RPC_CSTR
)"\\pipe\\ntsvcs",
40 if (status
!= RPC_S_OK
)
42 ERR("RpcStringBindingCompose returned 0x%x\n", status
);
46 /* Set the binding handle that will be used to bind to the server. */
47 status
= RpcBindingFromStringBindingA(pszStringBinding
,
49 if (status
!= RPC_S_OK
)
51 ERR("RpcBindingFromStringBinding returned 0x%x\n", status
);
54 status
= RpcStringFreeA(&pszStringBinding
);
55 if (status
!= RPC_S_OK
)
57 ERR("RpcStringFree returned 0x%x\n", status
);
65 SVCCTL_HANDLEA_unbind(SVCCTL_HANDLEA szMachineName
,
70 TRACE("SVCCTL_HANDLEA_unbind(%s %p)\n",
71 debugstr_a(szMachineName
), hBinding
);
73 status
= RpcBindingFree(&hBinding
);
74 if (status
!= RPC_S_OK
)
76 ERR("RpcBindingFree returned 0x%x\n", status
);
82 SVCCTL_HANDLEW_bind(SVCCTL_HANDLEW szMachineName
)
84 handle_t hBinding
= NULL
;
85 RPC_WSTR pszStringBinding
;
88 TRACE("SVCCTL_HANDLEW_bind(%s)\n",
89 debugstr_w(szMachineName
));
91 status
= RpcStringBindingComposeW(NULL
,
97 if (status
!= RPC_S_OK
)
99 ERR("RpcStringBindingCompose returned 0x%x\n", status
);
103 /* Set the binding handle that will be used to bind to the server. */
104 status
= RpcBindingFromStringBindingW(pszStringBinding
,
106 if (status
!= RPC_S_OK
)
108 ERR("RpcBindingFromStringBinding returned 0x%x\n", status
);
111 status
= RpcStringFreeW(&pszStringBinding
);
112 if (status
!= RPC_S_OK
)
114 ERR("RpcStringFree returned 0x%x\n", status
);
122 SVCCTL_HANDLEW_unbind(SVCCTL_HANDLEW szMachineName
,
127 TRACE("SVCCTL_HANDLEW_unbind(%s %p)\n",
128 debugstr_w(szMachineName
), hBinding
);
130 status
= RpcBindingFree(&hBinding
);
131 if (status
!= RPC_S_OK
)
133 ERR("RpcBindingFree returned 0x%x\n", status
);
139 ScmRpcStatusToWinError(RPC_STATUS Status
)
141 TRACE("ScmRpcStatusToWinError(%lx)\n",
146 case STATUS_ACCESS_VIOLATION
:
147 case RPC_S_INVALID_BINDING
:
148 case RPC_X_SS_IN_NULL_CONTEXT
:
149 return ERROR_INVALID_HANDLE
;
151 case RPC_X_ENUM_VALUE_OUT_OF_RANGE
:
152 case RPC_X_BYTE_COUNT_TOO_SMALL
:
153 return ERROR_INVALID_PARAMETER
;
155 case RPC_X_NULL_REF_POINTER
:
156 return ERROR_INVALID_ADDRESS
;
159 return (DWORD
)Status
;
167 _In_ PCWSTR pClearTextPassword
,
168 _Out_ PBYTE
*pEncryptedPassword
,
169 _Out_ PDWORD pEncryptedPasswordSize
)
171 struct ustring inData
, keyData
, outData
;
172 PCHAR pszKey
= "TestEncryptionKey";
176 inData
.Length
= (wcslen(pClearTextPassword
) + 1) * sizeof(WCHAR
);
177 inData
.MaximumLength
= inData
.Length
;
178 inData
.Buffer
= (unsigned char *)pClearTextPassword
;
180 keyData
.Length
= strlen(pszKey
);
181 keyData
.MaximumLength
= keyData
.Length
;
182 keyData
.Buffer
= (unsigned char *)pszKey
;
185 outData
.MaximumLength
= 0;
186 outData
.Buffer
= NULL
;
188 /* Get the required buffer size */
189 Status
= SystemFunction004(&inData
,
192 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
194 ERR("SystemFunction004 failed (Status 0x%08lx)\n", Status
);
195 return RtlNtStatusToDosError(Status
);
198 /* Allocate a buffer for the encrypted password */
199 pBuffer
= HeapAlloc(GetProcessHeap(), 0, outData
.Length
);
201 return ERROR_OUTOFMEMORY
;
203 outData
.MaximumLength
= outData
.Length
;
204 outData
.Buffer
= pBuffer
;
206 /* Encrypt the password */
207 Status
= SystemFunction004(&inData
,
210 if (!NT_SUCCESS(Status
))
212 ERR("SystemFunction004 failed (Status 0x%08lx)\n", Status
);
213 HeapFree(GetProcessHeap(), 0, pBuffer
);
214 return RtlNtStatusToDosError(Status
);
217 *pEncryptedPassword
= outData
.Buffer
;
218 *pEncryptedPasswordSize
= outData
.Length
;
220 return ERROR_SUCCESS
;
224 /**********************************************************************
225 * ChangeServiceConfig2A
230 ChangeServiceConfig2A(SC_HANDLE hService
,
234 SC_RPC_CONFIG_INFOA Info
;
237 TRACE("ChangeServiceConfig2A(%p %lu %p)\n",
238 hService
, dwInfoLevel
, lpInfo
);
240 if (lpInfo
== NULL
) return TRUE
;
242 /* Fill relevant field of the Info structure */
243 Info
.dwInfoLevel
= dwInfoLevel
;
246 case SERVICE_CONFIG_DESCRIPTION
:
250 case SERVICE_CONFIG_FAILURE_ACTIONS
:
255 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
256 SetLastError(ERROR_INVALID_PARAMETER
);
262 dwError
= RChangeServiceConfig2A((SC_RPC_HANDLE
)hService
,
265 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
267 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
271 if (dwError
!= ERROR_SUCCESS
)
273 TRACE("RChangeServiceConfig2A() failed (Error %lu)\n", dwError
);
274 SetLastError(dwError
);
282 /**********************************************************************
283 * ChangeServiceConfig2W
288 ChangeServiceConfig2W(SC_HANDLE hService
,
292 SC_RPC_CONFIG_INFOW Info
;
295 TRACE("ChangeServiceConfig2W(%p %lu %p)\n",
296 hService
, dwInfoLevel
, lpInfo
);
298 if (lpInfo
== NULL
) return TRUE
;
300 /* Fill relevant field of the Info structure */
301 Info
.dwInfoLevel
= dwInfoLevel
;
304 case SERVICE_CONFIG_DESCRIPTION
:
308 case SERVICE_CONFIG_FAILURE_ACTIONS
:
313 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
314 SetLastError(ERROR_INVALID_PARAMETER
);
320 dwError
= RChangeServiceConfig2W((SC_RPC_HANDLE
)hService
,
323 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
325 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
329 if (dwError
!= ERROR_SUCCESS
)
331 TRACE("RChangeServiceConfig2W() failed (Error %lu)\n", dwError
);
332 SetLastError(dwError
);
340 /**********************************************************************
341 * ChangeServiceConfigA
346 ChangeServiceConfigA(SC_HANDLE hService
,
349 DWORD dwErrorControl
,
350 LPCSTR lpBinaryPathName
,
351 LPCSTR lpLoadOrderGroup
,
353 LPCSTR lpDependencies
,
354 LPCSTR lpServiceStartName
,
356 LPCSTR lpDisplayName
)
359 DWORD dwDependenciesLength
= 0;
362 DWORD dwPasswordSize
= 0;
363 LPWSTR lpPasswordW
= NULL
;
364 LPBYTE lpEncryptedPassword
= NULL
;
366 TRACE("ChangeServiceConfigA(%p %lu %lu %lu %s %s %p %s %s %s %s)\n",
367 hService
, dwServiceType
, dwStartType
, dwErrorControl
, debugstr_a(lpBinaryPathName
),
368 debugstr_a(lpLoadOrderGroup
), lpdwTagId
, debugstr_a(lpDependencies
),
369 debugstr_a(lpServiceStartName
), debugstr_a(lpPassword
), debugstr_a(lpDisplayName
));
371 /* Calculate the Dependencies length*/
372 if (lpDependencies
!= NULL
)
374 lpStr
= lpDependencies
;
377 cchLength
= strlen(lpStr
) + 1;
378 dwDependenciesLength
+= (DWORD
)cchLength
;
379 lpStr
= lpStr
+ cchLength
;
381 dwDependenciesLength
++;
384 if (lpPassword
!= NULL
)
386 /* Convert the password to unicode */
387 lpPasswordW
= HeapAlloc(GetProcessHeap(),
389 (strlen(lpPassword
) + 1) * sizeof(WCHAR
));
390 if (lpPasswordW
== NULL
)
392 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
396 MultiByteToWideChar(CP_ACP
,
401 (int)(strlen(lpPassword
) + 1));
403 /* Encrypt the unicode password */
404 dwError
= ScmEncryptPassword(lpPasswordW
,
405 &lpEncryptedPassword
,
407 if (dwError
!= ERROR_SUCCESS
)
413 dwError
= RChangeServiceConfigA((SC_RPC_HANDLE
)hService
,
417 (LPSTR
)lpBinaryPathName
,
418 (LPSTR
)lpLoadOrderGroup
,
420 (LPBYTE
)lpDependencies
,
421 dwDependenciesLength
,
422 (LPSTR
)lpServiceStartName
,
425 (LPSTR
)lpDisplayName
);
427 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
429 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
434 if (lpPasswordW
!= NULL
)
436 /* Wipe and release the password buffers */
437 SecureZeroMemory(lpPasswordW
, (wcslen(lpPasswordW
) + 1) * sizeof(WCHAR
));
438 HeapFree(GetProcessHeap(), 0, lpPasswordW
);
440 if (lpEncryptedPassword
!= NULL
)
442 SecureZeroMemory(lpEncryptedPassword
, dwPasswordSize
);
443 HeapFree(GetProcessHeap(), 0, lpEncryptedPassword
);
447 if (dwError
!= ERROR_SUCCESS
)
449 TRACE("RChangeServiceConfigA() failed (Error %lu)\n", dwError
);
450 SetLastError(dwError
);
458 /**********************************************************************
459 * ChangeServiceConfigW
464 ChangeServiceConfigW(SC_HANDLE hService
,
467 DWORD dwErrorControl
,
468 LPCWSTR lpBinaryPathName
,
469 LPCWSTR lpLoadOrderGroup
,
471 LPCWSTR lpDependencies
,
472 LPCWSTR lpServiceStartName
,
474 LPCWSTR lpDisplayName
)
477 DWORD dwDependenciesLength
= 0;
480 DWORD dwPasswordSize
= 0;
481 LPBYTE lpEncryptedPassword
= NULL
;
483 TRACE("ChangeServiceConfigW(%p %lu %lu %lu %s %s %p %s %s %s %s)\n",
484 hService
, dwServiceType
, dwStartType
, dwErrorControl
, debugstr_w(lpBinaryPathName
),
485 debugstr_w(lpLoadOrderGroup
), lpdwTagId
, debugstr_w(lpDependencies
),
486 debugstr_w(lpServiceStartName
), debugstr_w(lpPassword
), debugstr_w(lpDisplayName
));
488 /* Calculate the Dependencies length*/
489 if (lpDependencies
!= NULL
)
491 lpStr
= lpDependencies
;
494 cchLength
= wcslen(lpStr
) + 1;
495 dwDependenciesLength
+= (DWORD
)cchLength
;
496 lpStr
= lpStr
+ cchLength
;
498 dwDependenciesLength
++;
499 dwDependenciesLength
*= sizeof(WCHAR
);
502 if (lpPassword
!= NULL
)
504 dwError
= ScmEncryptPassword(lpPassword
,
505 &lpEncryptedPassword
,
507 if (dwError
!= ERROR_SUCCESS
)
509 ERR("ScmEncryptPassword failed (Error %lu)\n", dwError
);
516 dwError
= RChangeServiceConfigW((SC_RPC_HANDLE
)hService
,
520 (LPWSTR
)lpBinaryPathName
,
521 (LPWSTR
)lpLoadOrderGroup
,
523 (LPBYTE
)lpDependencies
,
524 dwDependenciesLength
,
525 (LPWSTR
)lpServiceStartName
,
528 (LPWSTR
)lpDisplayName
);
530 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
532 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
537 if (lpEncryptedPassword
!= NULL
)
539 /* Wipe and release the password buffer */
540 SecureZeroMemory(lpEncryptedPassword
, dwPasswordSize
);
541 HeapFree(GetProcessHeap(), 0, lpEncryptedPassword
);
544 if (dwError
!= ERROR_SUCCESS
)
546 TRACE("RChangeServiceConfigW() failed (Error %lu)\n", dwError
);
547 SetLastError(dwError
);
555 /**********************************************************************
561 CloseServiceHandle(SC_HANDLE hSCObject
)
565 TRACE("CloseServiceHandle(%p)\n",
570 SetLastError(ERROR_INVALID_HANDLE
);
576 dwError
= RCloseServiceHandle((LPSC_RPC_HANDLE
)&hSCObject
);
578 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
580 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
586 TRACE("RCloseServiceHandle() failed (Error %lu)\n", dwError
);
587 SetLastError(dwError
);
591 TRACE("CloseServiceHandle() done\n");
597 /**********************************************************************
603 ControlService(SC_HANDLE hService
,
605 LPSERVICE_STATUS lpServiceStatus
)
609 TRACE("ControlService(%p %lu %p)\n",
610 hService
, dwControl
, lpServiceStatus
);
614 dwError
= RControlService((SC_RPC_HANDLE
)hService
,
618 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
620 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
624 if (dwError
!= ERROR_SUCCESS
)
626 TRACE("RControlService() failed (Error %lu)\n", dwError
);
627 SetLastError(dwError
);
631 TRACE("ControlService() done\n");
637 /**********************************************************************
643 ControlServiceEx(IN SC_HANDLE hService
,
645 IN DWORD dwInfoLevel
,
646 IN OUT PVOID pControlParams
)
648 FIXME("ControlServiceEx(%p %lu %lu %p)\n",
649 hService
, dwControl
, dwInfoLevel
, pControlParams
);
650 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
655 /**********************************************************************
661 CreateServiceA(SC_HANDLE hSCManager
,
662 LPCSTR lpServiceName
,
663 LPCSTR lpDisplayName
,
664 DWORD dwDesiredAccess
,
667 DWORD dwErrorControl
,
668 LPCSTR lpBinaryPathName
,
669 LPCSTR lpLoadOrderGroup
,
671 LPCSTR lpDependencies
,
672 LPCSTR lpServiceStartName
,
675 SC_HANDLE hService
= NULL
;
676 DWORD dwDependenciesLength
= 0;
680 DWORD dwPasswordSize
= 0;
681 LPWSTR lpPasswordW
= NULL
;
682 LPBYTE lpEncryptedPassword
= NULL
;
684 TRACE("CreateServiceA(%p %s %s %lx %lu %lu %lu %s %s %p %s %s %s)\n",
685 hSCManager
, debugstr_a(lpServiceName
), debugstr_a(lpDisplayName
),
686 dwDesiredAccess
, dwServiceType
, dwStartType
, dwErrorControl
,
687 debugstr_a(lpBinaryPathName
), debugstr_a(lpLoadOrderGroup
), lpdwTagId
,
688 debugstr_a(lpDependencies
), debugstr_a(lpServiceStartName
), debugstr_a(lpPassword
));
692 SetLastError(ERROR_INVALID_HANDLE
);
696 /* Calculate the Dependencies length */
697 if (lpDependencies
!= NULL
)
699 lpStr
= lpDependencies
;
702 cchLength
= strlen(lpStr
) + 1;
703 dwDependenciesLength
+= (DWORD
)cchLength
;
704 lpStr
= lpStr
+ cchLength
;
706 dwDependenciesLength
++;
709 if (lpPassword
!= NULL
)
711 /* Convert the password to unicode */
712 lpPasswordW
= HeapAlloc(GetProcessHeap(),
714 (strlen(lpPassword
) + 1) * sizeof(WCHAR
));
715 if (lpPasswordW
== NULL
)
717 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
721 MultiByteToWideChar(CP_ACP
,
726 (int)(strlen(lpPassword
) + 1));
728 /* Encrypt the password */
729 dwError
= ScmEncryptPassword(lpPasswordW
,
730 &lpEncryptedPassword
,
732 if (dwError
!= ERROR_SUCCESS
)
738 dwError
= RCreateServiceA((SC_RPC_HANDLE
)hSCManager
,
739 (LPSTR
)lpServiceName
,
740 (LPSTR
)lpDisplayName
,
745 (LPSTR
)lpBinaryPathName
,
746 (LPSTR
)lpLoadOrderGroup
,
748 (LPBYTE
)lpDependencies
,
749 dwDependenciesLength
,
750 (LPSTR
)lpServiceStartName
,
753 (SC_RPC_HANDLE
*)&hService
);
755 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
757 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
762 if (lpPasswordW
!= NULL
)
764 /* Wipe and release the password buffers */
765 SecureZeroMemory(lpPasswordW
, (wcslen(lpPasswordW
) + 1) * sizeof(WCHAR
));
766 HeapFree(GetProcessHeap(), 0, lpPasswordW
);
768 if (lpEncryptedPassword
!= NULL
)
770 SecureZeroMemory(lpEncryptedPassword
, dwPasswordSize
);
771 HeapFree(GetProcessHeap(), 0, lpEncryptedPassword
);
775 SetLastError(dwError
);
776 if (dwError
!= ERROR_SUCCESS
)
778 TRACE("RCreateServiceA() failed (Error %lu)\n", dwError
);
786 /**********************************************************************
792 CreateServiceW(SC_HANDLE hSCManager
,
793 LPCWSTR lpServiceName
,
794 LPCWSTR lpDisplayName
,
795 DWORD dwDesiredAccess
,
798 DWORD dwErrorControl
,
799 LPCWSTR lpBinaryPathName
,
800 LPCWSTR lpLoadOrderGroup
,
802 LPCWSTR lpDependencies
,
803 LPCWSTR lpServiceStartName
,
806 SC_HANDLE hService
= NULL
;
807 DWORD dwDependenciesLength
= 0;
811 DWORD dwPasswordSize
= 0;
812 LPBYTE lpEncryptedPassword
= NULL
;
814 TRACE("CreateServiceW(%p %s %s %lx %lu %lu %lu %s %s %p %s %s %s)\n",
815 hSCManager
, debugstr_w(lpServiceName
), debugstr_w(lpDisplayName
),
816 dwDesiredAccess
, dwServiceType
, dwStartType
, dwErrorControl
,
817 debugstr_w(lpBinaryPathName
), debugstr_w(lpLoadOrderGroup
), lpdwTagId
,
818 debugstr_w(lpDependencies
), debugstr_w(lpServiceStartName
), debugstr_w(lpPassword
));
822 SetLastError(ERROR_INVALID_HANDLE
);
826 /* Calculate the Dependencies length */
827 if (lpDependencies
!= NULL
)
829 lpStr
= lpDependencies
;
832 cchLength
= wcslen(lpStr
) + 1;
833 dwDependenciesLength
+= (DWORD
)cchLength
;
834 lpStr
= lpStr
+ cchLength
;
836 dwDependenciesLength
++;
837 dwDependenciesLength
*= sizeof(WCHAR
);
840 if (lpPassword
!= NULL
)
842 /* Encrypt the password */
843 dwError
= ScmEncryptPassword(lpPassword
,
844 &lpEncryptedPassword
,
846 if (dwError
!= ERROR_SUCCESS
)
852 dwError
= RCreateServiceW((SC_RPC_HANDLE
)hSCManager
,
862 (LPBYTE
)lpDependencies
,
863 dwDependenciesLength
,
867 (SC_RPC_HANDLE
*)&hService
);
869 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
871 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
876 if (lpEncryptedPassword
!= NULL
)
878 /* Wipe and release the password buffers */
879 SecureZeroMemory(lpEncryptedPassword
, dwPasswordSize
);
880 HeapFree(GetProcessHeap(), 0, lpEncryptedPassword
);
883 SetLastError(dwError
);
884 if (dwError
!= ERROR_SUCCESS
)
886 TRACE("RCreateServiceW() failed (Error %lu)\n", dwError
);
894 /**********************************************************************
900 DeleteService(SC_HANDLE hService
)
904 TRACE("DeleteService(%p)\n",
909 dwError
= RDeleteService((SC_RPC_HANDLE
)hService
);
911 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
913 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
917 if (dwError
!= ERROR_SUCCESS
)
919 TRACE("RDeleteService() failed (Error %lu)\n", dwError
);
920 SetLastError(dwError
);
928 /**********************************************************************
929 * EnumDependentServicesA
934 EnumDependentServicesA(SC_HANDLE hService
,
935 DWORD dwServiceState
,
936 LPENUM_SERVICE_STATUSA lpServices
,
938 LPDWORD pcbBytesNeeded
,
939 LPDWORD lpServicesReturned
)
941 ENUM_SERVICE_STATUSA ServiceStatus
;
942 LPENUM_SERVICE_STATUSA lpStatusPtr
;
947 TRACE("EnumDependentServicesA(%p %lu %p %lu %p %p)\n",
948 hService
, dwServiceState
, lpServices
, cbBufSize
,
949 pcbBytesNeeded
, lpServicesReturned
);
951 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSA
))
953 lpStatusPtr
= &ServiceStatus
;
954 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSA
);
958 lpStatusPtr
= lpServices
;
959 dwBufferSize
= cbBufSize
;
964 dwError
= REnumDependentServicesA((SC_RPC_HANDLE
)hService
,
971 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
973 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
977 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
979 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
981 if (lpStatusPtr
->lpServiceName
)
982 lpStatusPtr
->lpServiceName
=
983 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
985 if (lpStatusPtr
->lpDisplayName
)
986 lpStatusPtr
->lpDisplayName
=
987 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
993 if (dwError
!= ERROR_SUCCESS
)
995 TRACE("REnumDependentServicesA() failed (Error %lu)\n", dwError
);
996 SetLastError(dwError
);
1000 TRACE("EnumDependentServicesA() done\n");
1006 /**********************************************************************
1007 * EnumDependentServicesW
1012 EnumDependentServicesW(SC_HANDLE hService
,
1013 DWORD dwServiceState
,
1014 LPENUM_SERVICE_STATUSW lpServices
,
1016 LPDWORD pcbBytesNeeded
,
1017 LPDWORD lpServicesReturned
)
1019 ENUM_SERVICE_STATUSW ServiceStatus
;
1020 LPENUM_SERVICE_STATUSW lpStatusPtr
;
1025 TRACE("EnumDependentServicesW(%p %lu %p %lu %p %p)\n",
1026 hService
, dwServiceState
, lpServices
, cbBufSize
,
1027 pcbBytesNeeded
, lpServicesReturned
);
1029 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSW
))
1031 lpStatusPtr
= &ServiceStatus
;
1032 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSW
);
1036 lpStatusPtr
= lpServices
;
1037 dwBufferSize
= cbBufSize
;
1042 dwError
= REnumDependentServicesW((SC_RPC_HANDLE
)hService
,
1044 (LPBYTE
)lpStatusPtr
,
1047 lpServicesReturned
);
1049 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1051 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1055 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1057 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1059 if (lpStatusPtr
->lpServiceName
)
1060 lpStatusPtr
->lpServiceName
=
1061 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1063 if (lpStatusPtr
->lpDisplayName
)
1064 lpStatusPtr
->lpDisplayName
=
1065 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1071 if (dwError
!= ERROR_SUCCESS
)
1073 TRACE("REnumDependentServicesW() failed (Error %lu)\n", dwError
);
1074 SetLastError(dwError
);
1078 TRACE("EnumDependentServicesW() done\n");
1084 /**********************************************************************
1090 EnumServiceGroupW(SC_HANDLE hSCManager
,
1091 DWORD dwServiceType
,
1092 DWORD dwServiceState
,
1093 LPENUM_SERVICE_STATUSW lpServices
,
1095 LPDWORD pcbBytesNeeded
,
1096 LPDWORD lpServicesReturned
,
1097 LPDWORD lpResumeHandle
,
1100 ENUM_SERVICE_STATUSW ServiceStatus
;
1101 LPENUM_SERVICE_STATUSW lpStatusPtr
;
1106 TRACE("EnumServiceGroupW(%p %lu %lu %p %lu %p %p %p %s)\n",
1107 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1108 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
,
1109 lpResumeHandle
, debugstr_w(lpGroup
));
1113 SetLastError(ERROR_INVALID_HANDLE
);
1117 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1119 SetLastError(ERROR_INVALID_ADDRESS
);
1123 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSW
))
1125 lpStatusPtr
= &ServiceStatus
;
1126 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSW
);
1130 lpStatusPtr
= lpServices
;
1131 dwBufferSize
= cbBufSize
;
1136 if (lpGroup
== NULL
)
1138 dwError
= REnumServicesStatusW((SC_RPC_HANDLE
)hSCManager
,
1141 (LPBYTE
)lpStatusPtr
,
1149 dwError
= REnumServiceGroupW((SC_RPC_HANDLE
)hSCManager
,
1152 (LPBYTE
)lpStatusPtr
,
1160 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1162 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1166 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1168 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1170 if (lpStatusPtr
->lpServiceName
)
1171 lpStatusPtr
->lpServiceName
=
1172 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1174 if (lpStatusPtr
->lpDisplayName
)
1175 lpStatusPtr
->lpDisplayName
=
1176 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1182 if (dwError
!= ERROR_SUCCESS
)
1184 TRACE("REnumServiceGroupW() failed (Error %lu)\n", dwError
);
1185 SetLastError(dwError
);
1189 TRACE("EnumServiceGroupW() done\n");
1195 /**********************************************************************
1196 * EnumServicesStatusA
1201 EnumServicesStatusA(SC_HANDLE hSCManager
,
1202 DWORD dwServiceType
,
1203 DWORD dwServiceState
,
1204 LPENUM_SERVICE_STATUSA lpServices
,
1206 LPDWORD pcbBytesNeeded
,
1207 LPDWORD lpServicesReturned
,
1208 LPDWORD lpResumeHandle
)
1210 ENUM_SERVICE_STATUSA ServiceStatus
;
1211 LPENUM_SERVICE_STATUSA lpStatusPtr
;
1216 TRACE("EnumServicesStatusA(%p %lu %lu %p %lu %p %p %p)\n",
1217 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1218 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
, lpResumeHandle
);
1222 SetLastError(ERROR_INVALID_HANDLE
);
1226 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1228 SetLastError(ERROR_INVALID_ADDRESS
);
1232 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSA
))
1234 lpStatusPtr
= &ServiceStatus
;
1235 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSA
);
1239 lpStatusPtr
= lpServices
;
1240 dwBufferSize
= cbBufSize
;
1245 dwError
= REnumServicesStatusA((SC_RPC_HANDLE
)hSCManager
,
1248 (LPBYTE
)lpStatusPtr
,
1254 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1256 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1260 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1262 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1264 if (lpStatusPtr
->lpServiceName
)
1265 lpStatusPtr
->lpServiceName
=
1266 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1268 if (lpStatusPtr
->lpDisplayName
)
1269 lpStatusPtr
->lpDisplayName
=
1270 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1276 if (dwError
!= ERROR_SUCCESS
)
1278 TRACE("REnumServicesStatusA() failed (Error %lu)\n", dwError
);
1279 SetLastError(dwError
);
1283 TRACE("EnumServicesStatusA() done\n");
1289 /**********************************************************************
1290 * EnumServicesStatusW
1295 EnumServicesStatusW(SC_HANDLE hSCManager
,
1296 DWORD dwServiceType
,
1297 DWORD dwServiceState
,
1298 LPENUM_SERVICE_STATUSW lpServices
,
1300 LPDWORD pcbBytesNeeded
,
1301 LPDWORD lpServicesReturned
,
1302 LPDWORD lpResumeHandle
)
1304 ENUM_SERVICE_STATUSW ServiceStatus
;
1305 LPENUM_SERVICE_STATUSW lpStatusPtr
;
1310 TRACE("EnumServicesStatusW(%p %lu %lu %p %lu %p %p %p)\n",
1311 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1312 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
, lpResumeHandle
);
1316 SetLastError(ERROR_INVALID_HANDLE
);
1320 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1322 SetLastError(ERROR_INVALID_ADDRESS
);
1326 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUSW
))
1328 lpStatusPtr
= &ServiceStatus
;
1329 dwBufferSize
= sizeof(ENUM_SERVICE_STATUSW
);
1333 lpStatusPtr
= lpServices
;
1334 dwBufferSize
= cbBufSize
;
1339 dwError
= REnumServicesStatusW((SC_RPC_HANDLE
)hSCManager
,
1342 (LPBYTE
)lpStatusPtr
,
1348 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1350 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1354 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1356 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1358 if (lpStatusPtr
->lpServiceName
)
1359 lpStatusPtr
->lpServiceName
=
1360 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1362 if (lpStatusPtr
->lpDisplayName
)
1363 lpStatusPtr
->lpDisplayName
=
1364 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1370 if (dwError
!= ERROR_SUCCESS
)
1372 TRACE("REnumServicesStatusW() failed (Error %lu)\n", dwError
);
1373 SetLastError(dwError
);
1377 TRACE("EnumServicesStatusW() done\n");
1383 /**********************************************************************
1384 * EnumServicesStatusExA
1389 EnumServicesStatusExA(SC_HANDLE hSCManager
,
1390 SC_ENUM_TYPE InfoLevel
,
1391 DWORD dwServiceType
,
1392 DWORD dwServiceState
,
1395 LPDWORD pcbBytesNeeded
,
1396 LPDWORD lpServicesReturned
,
1397 LPDWORD lpResumeHandle
,
1398 LPCSTR pszGroupName
)
1400 ENUM_SERVICE_STATUS_PROCESSA ServiceStatus
;
1401 LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtr
;
1406 TRACE("EnumServicesStatusExA(%p %lu %lu %p %lu %p %p %p %s)\n",
1407 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1408 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
, lpResumeHandle
,
1409 debugstr_a(pszGroupName
));
1411 if (InfoLevel
!= SC_ENUM_PROCESS_INFO
)
1413 SetLastError(ERROR_INVALID_LEVEL
);
1419 SetLastError(ERROR_INVALID_HANDLE
);
1423 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1425 SetLastError(ERROR_INVALID_ADDRESS
);
1429 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUS_PROCESSA
))
1431 lpStatusPtr
= &ServiceStatus
;
1432 dwBufferSize
= sizeof(ENUM_SERVICE_STATUS_PROCESSA
);
1436 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpServices
;
1437 dwBufferSize
= cbBufSize
;
1442 dwError
= REnumServicesStatusExA((SC_RPC_HANDLE
)hSCManager
,
1446 (LPBYTE
)lpStatusPtr
,
1451 (LPSTR
)pszGroupName
);
1453 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1455 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1459 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1461 if (InfoLevel
== SC_ENUM_PROCESS_INFO
)
1463 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1465 if (lpStatusPtr
->lpServiceName
)
1466 lpStatusPtr
->lpServiceName
=
1467 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1469 if (lpStatusPtr
->lpDisplayName
)
1470 lpStatusPtr
->lpDisplayName
=
1471 (LPSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1478 if (dwError
!= ERROR_SUCCESS
)
1480 TRACE("REnumServicesStatusExA() failed (Error %lu)\n", dwError
);
1481 SetLastError(dwError
);
1485 TRACE("EnumServicesStatusExA() done\n");
1491 /**********************************************************************
1492 * EnumServicesStatusExW
1497 EnumServicesStatusExW(SC_HANDLE hSCManager
,
1498 SC_ENUM_TYPE InfoLevel
,
1499 DWORD dwServiceType
,
1500 DWORD dwServiceState
,
1503 LPDWORD pcbBytesNeeded
,
1504 LPDWORD lpServicesReturned
,
1505 LPDWORD lpResumeHandle
,
1506 LPCWSTR pszGroupName
)
1508 ENUM_SERVICE_STATUS_PROCESSW ServiceStatus
;
1509 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
1514 TRACE("EnumServicesStatusExW(%p %lu %lu %p %lu %p %p %p %s)\n",
1515 hSCManager
, dwServiceType
, dwServiceState
, lpServices
,
1516 cbBufSize
, pcbBytesNeeded
, lpServicesReturned
, lpResumeHandle
,
1517 debugstr_w(pszGroupName
));
1519 if (InfoLevel
!= SC_ENUM_PROCESS_INFO
)
1521 SetLastError(ERROR_INVALID_LEVEL
);
1527 SetLastError(ERROR_INVALID_HANDLE
);
1531 if (pcbBytesNeeded
== NULL
|| lpServicesReturned
== NULL
)
1533 SetLastError(ERROR_INVALID_ADDRESS
);
1537 if (lpServices
== NULL
|| cbBufSize
< sizeof(ENUM_SERVICE_STATUS_PROCESSW
))
1539 lpStatusPtr
= &ServiceStatus
;
1540 dwBufferSize
= sizeof(ENUM_SERVICE_STATUS_PROCESSW
);
1544 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpServices
;
1545 dwBufferSize
= cbBufSize
;
1550 dwError
= REnumServicesStatusExW((SC_RPC_HANDLE
)hSCManager
,
1554 (LPBYTE
)lpStatusPtr
,
1559 (LPWSTR
)pszGroupName
);
1561 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1563 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1567 if (dwError
== ERROR_SUCCESS
|| dwError
== ERROR_MORE_DATA
)
1569 if (InfoLevel
== SC_ENUM_PROCESS_INFO
)
1571 for (dwCount
= 0; dwCount
< *lpServicesReturned
; dwCount
++)
1573 if (lpStatusPtr
->lpServiceName
)
1574 lpStatusPtr
->lpServiceName
=
1575 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpServiceName
);
1577 if (lpStatusPtr
->lpDisplayName
)
1578 lpStatusPtr
->lpDisplayName
=
1579 (LPWSTR
)((ULONG_PTR
)lpServices
+ (ULONG_PTR
)lpStatusPtr
->lpDisplayName
);
1586 if (dwError
!= ERROR_SUCCESS
)
1588 TRACE("REnumServicesStatusExW() failed (Error %lu)\n", dwError
);
1589 SetLastError(dwError
);
1593 TRACE("EnumServicesStatusExW() done\n");
1599 /**********************************************************************
1600 * GetServiceDisplayNameA
1605 GetServiceDisplayNameA(SC_HANDLE hSCManager
,
1606 LPCSTR lpServiceName
,
1607 LPSTR lpDisplayName
,
1608 LPDWORD lpcchBuffer
)
1612 CHAR szEmptyName
[] = "";
1614 TRACE("GetServiceDisplayNameA(%p %s %p %p)\n",
1615 hSCManager
, debugstr_a(lpServiceName
), lpDisplayName
, lpcchBuffer
);
1619 SetLastError(ERROR_INVALID_HANDLE
);
1623 if (!lpDisplayName
|| *lpcchBuffer
< sizeof(CHAR
))
1625 lpNameBuffer
= szEmptyName
;
1626 *lpcchBuffer
= sizeof(CHAR
);
1630 lpNameBuffer
= lpDisplayName
;
1635 dwError
= RGetServiceDisplayNameA((SC_RPC_HANDLE
)hSCManager
,
1640 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1642 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1646 if (dwError
!= ERROR_SUCCESS
)
1648 TRACE("RGetServiceDisplayNameA() failed (Error %lu)\n", dwError
);
1649 SetLastError(dwError
);
1657 /**********************************************************************
1658 * GetServiceDisplayNameW
1663 GetServiceDisplayNameW(SC_HANDLE hSCManager
,
1664 LPCWSTR lpServiceName
,
1665 LPWSTR lpDisplayName
,
1666 LPDWORD lpcchBuffer
)
1669 LPWSTR lpNameBuffer
;
1670 WCHAR szEmptyName
[] = L
"";
1672 TRACE("GetServiceDisplayNameW(%p %s %p %p)\n",
1673 hSCManager
, debugstr_w(lpServiceName
), lpDisplayName
, lpcchBuffer
);
1677 SetLastError(ERROR_INVALID_HANDLE
);
1681 if (!lpDisplayName
|| *lpcchBuffer
< sizeof(WCHAR
))
1683 lpNameBuffer
= szEmptyName
;
1684 *lpcchBuffer
= sizeof(WCHAR
);
1688 lpNameBuffer
= lpDisplayName
;
1693 dwError
= RGetServiceDisplayNameW((SC_RPC_HANDLE
)hSCManager
,
1698 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1700 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1704 if (dwError
!= ERROR_SUCCESS
)
1706 TRACE("RGetServiceDisplayNameW() failed (Error %lu)\n", dwError
);
1707 SetLastError(dwError
);
1715 /**********************************************************************
1716 * GetServiceKeyNameA
1721 GetServiceKeyNameA(SC_HANDLE hSCManager
,
1722 LPCSTR lpDisplayName
,
1723 LPSTR lpServiceName
,
1724 LPDWORD lpcchBuffer
)
1728 CHAR szEmptyName
[] = "";
1730 TRACE("GetServiceKeyNameA(%p %s %p %p)\n",
1731 hSCManager
, debugstr_a(lpDisplayName
), lpServiceName
, lpcchBuffer
);
1735 SetLastError(ERROR_INVALID_HANDLE
);
1739 if (!lpServiceName
|| *lpcchBuffer
< sizeof(CHAR
))
1741 lpNameBuffer
= szEmptyName
;
1742 *lpcchBuffer
= sizeof(CHAR
);
1746 lpNameBuffer
= lpServiceName
;
1751 dwError
= RGetServiceKeyNameA((SC_RPC_HANDLE
)hSCManager
,
1756 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1758 /* HACK: because of a problem with rpcrt4, rpcserver is hacked to return 6 for ERROR_SERVICE_DOES_NOT_EXIST */
1759 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1763 if (dwError
!= ERROR_SUCCESS
)
1765 TRACE("RGetServiceKeyNameA() failed (Error %lu)\n", dwError
);
1766 SetLastError(dwError
);
1774 /**********************************************************************
1775 * GetServiceKeyNameW
1780 GetServiceKeyNameW(SC_HANDLE hSCManager
,
1781 LPCWSTR lpDisplayName
,
1782 LPWSTR lpServiceName
,
1783 LPDWORD lpcchBuffer
)
1786 LPWSTR lpNameBuffer
;
1787 WCHAR szEmptyName
[] = L
"";
1789 TRACE("GetServiceKeyNameW(%p %s %p %p)\n",
1790 hSCManager
, debugstr_w(lpDisplayName
), lpServiceName
, lpcchBuffer
);
1794 SetLastError(ERROR_INVALID_HANDLE
);
1798 if (!lpServiceName
|| *lpcchBuffer
< sizeof(WCHAR
))
1800 lpNameBuffer
= szEmptyName
;
1801 *lpcchBuffer
= sizeof(WCHAR
);
1805 lpNameBuffer
= lpServiceName
;
1810 dwError
= RGetServiceKeyNameW((SC_RPC_HANDLE
)hSCManager
,
1815 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1817 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1821 if (dwError
!= ERROR_SUCCESS
)
1823 TRACE("RGetServiceKeyNameW() failed (Error %lu)\n", dwError
);
1824 SetLastError(dwError
);
1832 /**********************************************************************
1833 * I_ScGetCurrentGroupStateW
1838 I_ScGetCurrentGroupStateW(SC_HANDLE hSCManager
,
1839 LPWSTR pszGroupName
,
1840 LPDWORD pdwGroupState
)
1844 TRACE("I_ScGetCurrentGroupStateW(%p %s %p)\n",
1845 hSCManager
, debugstr_w(pszGroupName
), pdwGroupState
);
1849 dwError
= RI_ScGetCurrentGroupStateW((SC_RPC_HANDLE
)hSCManager
,
1853 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1855 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1859 if (dwError
!= ERROR_SUCCESS
)
1861 TRACE("RI_ScGetCurrentGroupStateW() failed (Error %lu)\n", dwError
);
1862 SetLastError(dwError
);
1869 /**********************************************************************
1870 * LockServiceDatabase
1875 LockServiceDatabase(SC_HANDLE hSCManager
)
1880 TRACE("LockServiceDatabase(%p)\n",
1885 dwError
= RLockServiceDatabase((SC_RPC_HANDLE
)hSCManager
,
1886 (SC_RPC_LOCK
*)&hLock
);
1888 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1890 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1894 if (dwError
!= ERROR_SUCCESS
)
1896 TRACE("RLockServiceDatabase() failed (Error %lu)\n", dwError
);
1897 SetLastError(dwError
);
1901 TRACE("hLock = %p\n", hLock
);
1908 WaitForSCManager(VOID
)
1912 TRACE("WaitForSCManager()\n");
1914 /* Try to open the existing event */
1915 hEvent
= OpenEventW(SYNCHRONIZE
, FALSE
, SCM_START_EVENT
);
1918 if (GetLastError() != ERROR_FILE_NOT_FOUND
)
1921 /* Try to create a new event */
1922 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, SCM_START_EVENT
);
1927 /* Wait for 3 minutes */
1928 WaitForSingleObject(hEvent
, 180000);
1929 CloseHandle(hEvent
);
1931 TRACE("ScmWaitForSCManager() done\n");
1935 /**********************************************************************
1941 OpenSCManagerA(LPCSTR lpMachineName
,
1942 LPCSTR lpDatabaseName
,
1943 DWORD dwDesiredAccess
)
1945 SC_HANDLE hScm
= NULL
;
1948 TRACE("OpenSCManagerA(%s %s %lx)\n",
1949 debugstr_a(lpMachineName
), debugstr_a(lpDatabaseName
), dwDesiredAccess
);
1955 dwError
= ROpenSCManagerA((LPSTR
)lpMachineName
,
1956 (LPSTR
)lpDatabaseName
,
1958 (SC_RPC_HANDLE
*)&hScm
);
1960 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
1962 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
1966 if (dwError
!= ERROR_SUCCESS
)
1968 TRACE("ROpenSCManagerA() failed (Error %lu)\n", dwError
);
1969 SetLastError(dwError
);
1973 TRACE("hScm = %p\n", hScm
);
1979 /**********************************************************************
1985 OpenSCManagerW(LPCWSTR lpMachineName
,
1986 LPCWSTR lpDatabaseName
,
1987 DWORD dwDesiredAccess
)
1989 SC_HANDLE hScm
= NULL
;
1992 TRACE("OpenSCManagerW(%s %s %lx)\n",
1993 debugstr_w(lpMachineName
), debugstr_w(lpDatabaseName
), dwDesiredAccess
);
1999 dwError
= ROpenSCManagerW((LPWSTR
)lpMachineName
,
2000 (LPWSTR
)lpDatabaseName
,
2002 (SC_RPC_HANDLE
*)&hScm
);
2004 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2006 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2010 if (dwError
!= ERROR_SUCCESS
)
2012 TRACE("ROpenSCManagerW() failed (Error %lu)\n", dwError
);
2013 SetLastError(dwError
);
2017 TRACE("hScm = %p\n", hScm
);
2023 /**********************************************************************
2029 OpenServiceA(SC_HANDLE hSCManager
,
2030 LPCSTR lpServiceName
,
2031 DWORD dwDesiredAccess
)
2033 SC_HANDLE hService
= NULL
;
2036 TRACE("OpenServiceA(%p %s %lx)\n",
2037 hSCManager
, debugstr_a(lpServiceName
), dwDesiredAccess
);
2041 SetLastError(ERROR_INVALID_HANDLE
);
2047 dwError
= ROpenServiceA((SC_RPC_HANDLE
)hSCManager
,
2048 (LPSTR
)lpServiceName
,
2050 (SC_RPC_HANDLE
*)&hService
);
2052 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2054 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2058 SetLastError(dwError
);
2059 if (dwError
!= ERROR_SUCCESS
)
2061 TRACE("ROpenServiceA() failed (Error %lu)\n", dwError
);
2065 TRACE("hService = %p\n", hService
);
2071 /**********************************************************************
2077 OpenServiceW(SC_HANDLE hSCManager
,
2078 LPCWSTR lpServiceName
,
2079 DWORD dwDesiredAccess
)
2081 SC_HANDLE hService
= NULL
;
2084 TRACE("OpenServiceW(%p %s %lx)\n",
2085 hSCManager
, debugstr_w(lpServiceName
), dwDesiredAccess
);
2089 SetLastError(ERROR_INVALID_HANDLE
);
2095 dwError
= ROpenServiceW((SC_RPC_HANDLE
)hSCManager
,
2096 (LPWSTR
)lpServiceName
,
2098 (SC_RPC_HANDLE
*)&hService
);
2100 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2102 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2106 SetLastError(dwError
);
2107 if (dwError
!= ERROR_SUCCESS
)
2109 TRACE("ROpenServiceW() failed (Error %lu)\n", dwError
);
2113 TRACE("hService = %p\n", hService
);
2119 /**********************************************************************
2120 * QueryServiceConfigA
2125 QueryServiceConfigA(SC_HANDLE hService
,
2126 LPQUERY_SERVICE_CONFIGA lpServiceConfig
,
2128 LPDWORD pcbBytesNeeded
)
2130 QUERY_SERVICE_CONFIGA ServiceConfig
;
2131 LPQUERY_SERVICE_CONFIGA lpConfigPtr
;
2135 TRACE("QueryServiceConfigA(%p %p %lu %p)\n",
2136 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
2138 if (lpServiceConfig
== NULL
||
2139 cbBufSize
< sizeof(QUERY_SERVICE_CONFIGA
))
2141 lpConfigPtr
= &ServiceConfig
;
2142 dwBufferSize
= sizeof(QUERY_SERVICE_CONFIGA
);
2146 lpConfigPtr
= lpServiceConfig
;
2147 dwBufferSize
= cbBufSize
;
2152 dwError
= RQueryServiceConfigA((SC_RPC_HANDLE
)hService
,
2153 (LPBYTE
)lpConfigPtr
,
2157 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2159 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2163 if (dwError
!= ERROR_SUCCESS
)
2165 TRACE("RQueryServiceConfigA() failed (Error %lu)\n", dwError
);
2166 SetLastError(dwError
);
2170 /* Adjust the pointers */
2171 if (lpConfigPtr
->lpBinaryPathName
)
2172 lpConfigPtr
->lpBinaryPathName
=
2173 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2174 (ULONG_PTR
)lpConfigPtr
->lpBinaryPathName
);
2176 if (lpConfigPtr
->lpLoadOrderGroup
)
2177 lpConfigPtr
->lpLoadOrderGroup
=
2178 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2179 (ULONG_PTR
)lpConfigPtr
->lpLoadOrderGroup
);
2181 if (lpConfigPtr
->lpDependencies
)
2182 lpConfigPtr
->lpDependencies
=
2183 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2184 (ULONG_PTR
)lpConfigPtr
->lpDependencies
);
2186 if (lpConfigPtr
->lpServiceStartName
)
2187 lpConfigPtr
->lpServiceStartName
=
2188 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2189 (ULONG_PTR
)lpConfigPtr
->lpServiceStartName
);
2191 if (lpConfigPtr
->lpDisplayName
)
2192 lpConfigPtr
->lpDisplayName
=
2193 (LPSTR
)((ULONG_PTR
)lpConfigPtr
+
2194 (ULONG_PTR
)lpConfigPtr
->lpDisplayName
);
2196 TRACE("QueryServiceConfigA() done\n");
2202 /**********************************************************************
2203 * QueryServiceConfigW
2208 QueryServiceConfigW(SC_HANDLE hService
,
2209 LPQUERY_SERVICE_CONFIGW lpServiceConfig
,
2211 LPDWORD pcbBytesNeeded
)
2213 QUERY_SERVICE_CONFIGW ServiceConfig
;
2214 LPQUERY_SERVICE_CONFIGW lpConfigPtr
;
2218 TRACE("QueryServiceConfigW(%p %p %lu %p)\n",
2219 hService
, lpServiceConfig
, cbBufSize
, pcbBytesNeeded
);
2221 if (lpServiceConfig
== NULL
||
2222 cbBufSize
< sizeof(QUERY_SERVICE_CONFIGW
))
2224 lpConfigPtr
= &ServiceConfig
;
2225 dwBufferSize
= sizeof(QUERY_SERVICE_CONFIGW
);
2229 lpConfigPtr
= lpServiceConfig
;
2230 dwBufferSize
= cbBufSize
;
2235 dwError
= RQueryServiceConfigW((SC_RPC_HANDLE
)hService
,
2236 (LPBYTE
)lpConfigPtr
,
2240 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2242 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2246 if (dwError
!= ERROR_SUCCESS
)
2248 TRACE("RQueryServiceConfigW() failed (Error %lu)\n", dwError
);
2249 SetLastError(dwError
);
2253 /* Adjust the pointers */
2254 if (lpConfigPtr
->lpBinaryPathName
)
2255 lpConfigPtr
->lpBinaryPathName
=
2256 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2257 (ULONG_PTR
)lpConfigPtr
->lpBinaryPathName
);
2259 if (lpConfigPtr
->lpLoadOrderGroup
)
2260 lpConfigPtr
->lpLoadOrderGroup
=
2261 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2262 (ULONG_PTR
)lpConfigPtr
->lpLoadOrderGroup
);
2264 if (lpConfigPtr
->lpDependencies
)
2265 lpConfigPtr
->lpDependencies
=
2266 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2267 (ULONG_PTR
)lpConfigPtr
->lpDependencies
);
2269 if (lpConfigPtr
->lpServiceStartName
)
2270 lpConfigPtr
->lpServiceStartName
=
2271 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2272 (ULONG_PTR
)lpConfigPtr
->lpServiceStartName
);
2274 if (lpConfigPtr
->lpDisplayName
)
2275 lpConfigPtr
->lpDisplayName
=
2276 (LPWSTR
)((ULONG_PTR
)lpConfigPtr
+
2277 (ULONG_PTR
)lpConfigPtr
->lpDisplayName
);
2279 TRACE("QueryServiceConfigW() done\n");
2285 /**********************************************************************
2286 * QueryServiceConfig2A
2291 QueryServiceConfig2A(SC_HANDLE hService
,
2295 LPDWORD pcbBytesNeeded
)
2297 SERVICE_DESCRIPTIONA ServiceDescription
;
2298 SERVICE_FAILURE_ACTIONSA ServiceFailureActions
;
2299 LPBYTE lpTempBuffer
;
2300 BOOL bUseTempBuffer
= FALSE
;
2304 TRACE("QueryServiceConfig2A(%p %lu %p %lu %p)\n",
2305 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2307 lpTempBuffer
= lpBuffer
;
2308 dwBufferSize
= cbBufSize
;
2310 switch (dwInfoLevel
)
2312 case SERVICE_CONFIG_DESCRIPTION
:
2313 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_DESCRIPTIONA
)))
2315 lpTempBuffer
= (LPBYTE
)&ServiceDescription
;
2316 dwBufferSize
= sizeof(SERVICE_DESCRIPTIONA
);
2317 bUseTempBuffer
= TRUE
;
2321 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2322 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_FAILURE_ACTIONSA
)))
2324 lpTempBuffer
= (LPBYTE
)&ServiceFailureActions
;
2325 dwBufferSize
= sizeof(SERVICE_FAILURE_ACTIONSA
);
2326 bUseTempBuffer
= TRUE
;
2331 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
2332 SetLastError(ERROR_INVALID_LEVEL
);
2338 dwError
= RQueryServiceConfig2A((SC_RPC_HANDLE
)hService
,
2344 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2346 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2350 if (dwError
!= ERROR_SUCCESS
)
2352 TRACE("RQueryServiceConfig2A() failed (Error %lu)\n", dwError
);
2353 SetLastError(dwError
);
2357 if (bUseTempBuffer
!= FALSE
)
2359 TRACE("RQueryServiceConfig2A() returns ERROR_INSUFFICIENT_BUFFER\n");
2360 *pcbBytesNeeded
= dwBufferSize
;
2361 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2365 switch (dwInfoLevel
)
2367 case SERVICE_CONFIG_DESCRIPTION
:
2369 LPSERVICE_DESCRIPTIONA lpPtr
= (LPSERVICE_DESCRIPTIONA
)lpTempBuffer
;
2371 if (lpPtr
->lpDescription
!= NULL
)
2372 lpPtr
->lpDescription
=
2373 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpDescription
);
2377 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2379 LPSERVICE_FAILURE_ACTIONSA lpPtr
= (LPSERVICE_FAILURE_ACTIONSA
)lpTempBuffer
;
2381 if (lpPtr
->lpRebootMsg
!= NULL
)
2382 lpPtr
->lpRebootMsg
=
2383 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpRebootMsg
);
2385 if (lpPtr
->lpCommand
!= NULL
)
2387 (LPSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpCommand
);
2389 if (lpPtr
->lpsaActions
!= NULL
)
2390 lpPtr
->lpsaActions
=
2391 (LPSC_ACTION
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpsaActions
);
2396 TRACE("QueryServiceConfig2A() done\n");
2402 /**********************************************************************
2403 * QueryServiceConfig2W
2408 QueryServiceConfig2W(SC_HANDLE hService
,
2412 LPDWORD pcbBytesNeeded
)
2414 SERVICE_DESCRIPTIONW ServiceDescription
;
2415 SERVICE_FAILURE_ACTIONSW ServiceFailureActions
;
2416 LPBYTE lpTempBuffer
;
2417 BOOL bUseTempBuffer
= FALSE
;
2421 TRACE("QueryServiceConfig2W(%p %lu %p %lu %p)\n",
2422 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2424 lpTempBuffer
= lpBuffer
;
2425 dwBufferSize
= cbBufSize
;
2427 switch (dwInfoLevel
)
2429 case SERVICE_CONFIG_DESCRIPTION
:
2430 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_DESCRIPTIONW
)))
2432 lpTempBuffer
= (LPBYTE
)&ServiceDescription
;
2433 dwBufferSize
= sizeof(SERVICE_DESCRIPTIONW
);
2434 bUseTempBuffer
= TRUE
;
2438 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2439 if ((lpBuffer
== NULL
) || (cbBufSize
< sizeof(SERVICE_FAILURE_ACTIONSW
)))
2441 lpTempBuffer
= (LPBYTE
)&ServiceFailureActions
;
2442 dwBufferSize
= sizeof(SERVICE_FAILURE_ACTIONSW
);
2443 bUseTempBuffer
= TRUE
;
2448 WARN("Unknown info level 0x%lx\n", dwInfoLevel
);
2449 SetLastError(ERROR_INVALID_LEVEL
);
2455 dwError
= RQueryServiceConfig2W((SC_RPC_HANDLE
)hService
,
2461 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2463 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2467 if (dwError
!= ERROR_SUCCESS
)
2469 TRACE("RQueryServiceConfig2W() failed (Error %lu)\n", dwError
);
2470 SetLastError(dwError
);
2474 if (bUseTempBuffer
!= FALSE
)
2476 TRACE("RQueryServiceConfig2W() returns ERROR_INSUFFICIENT_BUFFER\n");
2477 *pcbBytesNeeded
= dwBufferSize
;
2478 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2482 switch (dwInfoLevel
)
2484 case SERVICE_CONFIG_DESCRIPTION
:
2486 LPSERVICE_DESCRIPTIONW lpPtr
= (LPSERVICE_DESCRIPTIONW
)lpTempBuffer
;
2488 if (lpPtr
->lpDescription
!= NULL
)
2489 lpPtr
->lpDescription
=
2490 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpDescription
);
2494 case SERVICE_CONFIG_FAILURE_ACTIONS
:
2496 LPSERVICE_FAILURE_ACTIONSW lpPtr
= (LPSERVICE_FAILURE_ACTIONSW
)lpTempBuffer
;
2498 if (lpPtr
->lpRebootMsg
!= NULL
)
2499 lpPtr
->lpRebootMsg
=
2500 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpRebootMsg
);
2502 if (lpPtr
->lpCommand
!= NULL
)
2504 (LPWSTR
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpCommand
);
2506 if (lpPtr
->lpsaActions
!= NULL
)
2507 lpPtr
->lpsaActions
=
2508 (LPSC_ACTION
)((ULONG_PTR
)lpPtr
+ (ULONG_PTR
)lpPtr
->lpsaActions
);
2513 TRACE("QueryServiceConfig2W() done\n");
2519 /**********************************************************************
2520 * QueryServiceLockStatusA
2525 QueryServiceLockStatusA(SC_HANDLE hSCManager
,
2526 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
2528 LPDWORD pcbBytesNeeded
)
2530 QUERY_SERVICE_LOCK_STATUSA LockStatus
;
2531 LPQUERY_SERVICE_LOCK_STATUSA lpStatusPtr
;
2535 TRACE("QueryServiceLockStatusA(%p %p %lu %p)\n",
2536 hSCManager
, lpLockStatus
, cbBufSize
, pcbBytesNeeded
);
2538 if (lpLockStatus
== NULL
|| cbBufSize
< sizeof(QUERY_SERVICE_LOCK_STATUSA
))
2540 lpStatusPtr
= &LockStatus
;
2541 dwBufferSize
= sizeof(QUERY_SERVICE_LOCK_STATUSA
);
2545 lpStatusPtr
= lpLockStatus
;
2546 dwBufferSize
= cbBufSize
;
2551 dwError
= RQueryServiceLockStatusA((SC_RPC_HANDLE
)hSCManager
,
2552 (LPBYTE
)lpStatusPtr
,
2556 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2558 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2562 if (dwError
!= ERROR_SUCCESS
)
2564 TRACE("RQueryServiceLockStatusA() failed (Error %lu)\n", dwError
);
2565 SetLastError(dwError
);
2569 if (lpStatusPtr
->lpLockOwner
!= NULL
)
2571 lpStatusPtr
->lpLockOwner
=
2572 (LPSTR
)((ULONG_PTR
)lpStatusPtr
+ (ULONG_PTR
)lpStatusPtr
->lpLockOwner
);
2575 TRACE("QueryServiceLockStatusA() done\n");
2581 /**********************************************************************
2582 * QueryServiceLockStatusW
2587 QueryServiceLockStatusW(SC_HANDLE hSCManager
,
2588 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
2590 LPDWORD pcbBytesNeeded
)
2592 QUERY_SERVICE_LOCK_STATUSW LockStatus
;
2593 LPQUERY_SERVICE_LOCK_STATUSW lpStatusPtr
;
2597 TRACE("QueryServiceLockStatusW(%p %p %lu %p)\n",
2598 hSCManager
, lpLockStatus
, cbBufSize
, pcbBytesNeeded
);
2600 if (lpLockStatus
== NULL
|| cbBufSize
< sizeof(QUERY_SERVICE_LOCK_STATUSW
))
2602 lpStatusPtr
= &LockStatus
;
2603 dwBufferSize
= sizeof(QUERY_SERVICE_LOCK_STATUSW
);
2607 lpStatusPtr
= lpLockStatus
;
2608 dwBufferSize
= cbBufSize
;
2613 dwError
= RQueryServiceLockStatusW((SC_RPC_HANDLE
)hSCManager
,
2614 (LPBYTE
)lpStatusPtr
,
2618 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2620 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2624 if (dwError
!= ERROR_SUCCESS
)
2626 TRACE("RQueryServiceLockStatusW() failed (Error %lu)\n", dwError
);
2627 SetLastError(dwError
);
2631 if (lpStatusPtr
->lpLockOwner
!= NULL
)
2633 lpStatusPtr
->lpLockOwner
=
2634 (LPWSTR
)((ULONG_PTR
)lpStatusPtr
+ (ULONG_PTR
)lpStatusPtr
->lpLockOwner
);
2637 TRACE("QueryServiceLockStatusW() done\n");
2643 /**********************************************************************
2644 * QueryServiceObjectSecurity
2649 QueryServiceObjectSecurity(SC_HANDLE hService
,
2650 SECURITY_INFORMATION dwSecurityInformation
,
2651 PSECURITY_DESCRIPTOR lpSecurityDescriptor
,
2653 LPDWORD pcbBytesNeeded
)
2657 TRACE("QueryServiceObjectSecurity(%p %lu %p)\n",
2658 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2662 dwError
= RQueryServiceObjectSecurity((SC_RPC_HANDLE
)hService
,
2663 dwSecurityInformation
,
2664 (LPBYTE
)lpSecurityDescriptor
,
2668 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2670 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2674 if (dwError
!= ERROR_SUCCESS
)
2676 TRACE("QueryServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2677 SetLastError(dwError
);
2685 /**********************************************************************
2686 * SetServiceObjectSecurity
2691 SetServiceObjectSecurity(SC_HANDLE hService
,
2692 SECURITY_INFORMATION dwSecurityInformation
,
2693 PSECURITY_DESCRIPTOR lpSecurityDescriptor
)
2695 PSECURITY_DESCRIPTOR SelfRelativeSD
= NULL
;
2700 TRACE("SetServiceObjectSecurity(%p %lu %p)\n",
2701 hService
, dwSecurityInformation
, lpSecurityDescriptor
);
2704 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2707 if (Status
!= STATUS_BUFFER_TOO_SMALL
)
2709 SetLastError(ERROR_INVALID_PARAMETER
);
2713 SelfRelativeSD
= HeapAlloc(GetProcessHeap(), 0, Length
);
2714 if (SelfRelativeSD
== NULL
)
2716 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
2720 Status
= RtlMakeSelfRelativeSD(lpSecurityDescriptor
,
2723 if (!NT_SUCCESS(Status
))
2725 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2726 SetLastError(RtlNtStatusToDosError(Status
));
2732 dwError
= RSetServiceObjectSecurity((SC_RPC_HANDLE
)hService
,
2733 dwSecurityInformation
,
2734 (LPBYTE
)SelfRelativeSD
,
2737 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2739 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2743 HeapFree(GetProcessHeap(), 0, SelfRelativeSD
);
2745 if (dwError
!= ERROR_SUCCESS
)
2747 TRACE("RServiceObjectSecurity() failed (Error %lu)\n", dwError
);
2748 SetLastError(dwError
);
2756 /**********************************************************************
2757 * QueryServiceStatus
2762 QueryServiceStatus(SC_HANDLE hService
,
2763 LPSERVICE_STATUS lpServiceStatus
)
2767 TRACE("QueryServiceStatus(%p %p)\n",
2768 hService
, lpServiceStatus
);
2772 SetLastError(ERROR_INVALID_HANDLE
);
2778 dwError
= RQueryServiceStatus((SC_RPC_HANDLE
)hService
,
2781 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2783 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2787 if (dwError
!= ERROR_SUCCESS
)
2789 TRACE("RQueryServiceStatus() failed (Error %lu)\n", dwError
);
2790 SetLastError(dwError
);
2798 /**********************************************************************
2799 * QueryServiceStatusEx
2804 QueryServiceStatusEx(SC_HANDLE hService
,
2805 SC_STATUS_TYPE InfoLevel
,
2808 LPDWORD pcbBytesNeeded
)
2812 TRACE("QueryServiceStatusEx(%p %lu %p %lu %p)\n",
2813 hService
, InfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
2815 if (InfoLevel
!= SC_STATUS_PROCESS_INFO
)
2817 SetLastError(ERROR_INVALID_LEVEL
);
2821 if (cbBufSize
< sizeof(SERVICE_STATUS_PROCESS
))
2823 *pcbBytesNeeded
= sizeof(SERVICE_STATUS_PROCESS
);
2824 SetLastError(ERROR_INSUFFICIENT_BUFFER
);
2830 dwError
= RQueryServiceStatusEx((SC_RPC_HANDLE
)hService
,
2836 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2838 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2842 if (dwError
!= ERROR_SUCCESS
)
2844 TRACE("RQueryServiceStatusEx() failed (Error %lu)\n", dwError
);
2845 SetLastError(dwError
);
2853 /**********************************************************************
2859 StartServiceA(SC_HANDLE hService
,
2860 DWORD dwNumServiceArgs
,
2861 LPCSTR
*lpServiceArgVectors
)
2865 TRACE("StartServiceA(%p %lu %p)\n",
2866 hService
, dwNumServiceArgs
, lpServiceArgVectors
);
2870 dwError
= RStartServiceA((SC_RPC_HANDLE
)hService
,
2872 (LPSTRING_PTRSA
)lpServiceArgVectors
);
2874 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2876 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2880 if (dwError
!= ERROR_SUCCESS
)
2882 ERR("RStartServiceA() failed (Error %lu)\n", dwError
);
2883 SetLastError(dwError
);
2891 /**********************************************************************
2897 StartServiceW(SC_HANDLE hService
,
2898 DWORD dwNumServiceArgs
,
2899 LPCWSTR
*lpServiceArgVectors
)
2903 TRACE("StartServiceW(%p %lu %p)\n",
2904 hService
, dwNumServiceArgs
, lpServiceArgVectors
);
2908 dwError
= RStartServiceW((SC_RPC_HANDLE
)hService
,
2910 (LPSTRING_PTRSW
)lpServiceArgVectors
);
2912 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2914 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2918 if (dwError
!= ERROR_SUCCESS
)
2920 ERR("RStartServiceW() failed (Error %lu)\n", dwError
);
2921 SetLastError(dwError
);
2929 /**********************************************************************
2930 * UnlockServiceDatabase
2935 UnlockServiceDatabase(SC_LOCK ScLock
)
2939 TRACE("UnlockServiceDatabase(%x)\n",
2944 dwError
= RUnlockServiceDatabase((LPSC_RPC_LOCK
)&ScLock
);
2946 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2948 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2952 if (dwError
== ERROR_INVALID_HANDLE
)
2953 dwError
= ERROR_INVALID_SERVICE_LOCK
;
2955 if (dwError
!= ERROR_SUCCESS
)
2957 TRACE("RUnlockServiceDatabase() failed (Error %lu)\n", dwError
);
2958 SetLastError(dwError
);
2966 /**********************************************************************
2967 * NotifyBootConfigStatus
2972 NotifyBootConfigStatus(BOOL BootAcceptable
)
2976 TRACE("NotifyBootConfigStatus(%u)\n",
2981 dwError
= RNotifyBootConfigStatus(NULL
,
2984 RpcExcept(EXCEPTION_EXECUTE_HANDLER
)
2986 dwError
= ScmRpcStatusToWinError(RpcExceptionCode());
2990 if (dwError
!= ERROR_SUCCESS
)
2992 TRACE("NotifyBootConfigStatus() failed (Error %lu)\n", dwError
);
2993 SetLastError(dwError
);