2 * PROJECT: ReactOS Service Control Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/system/services/rpcserver.c
5 * PURPOSE: RPC server interface for the advapi32 calls
6 * COPYRIGHT: Copyright 2005-2006 Eric Kohl
7 * Copyright 2006-2007 Hervé Poussineau <hpoussin@reactos.org>
8 * Copyright 2007 Ged Murphy <gedmurphy@reactos.org>
11 /* INCLUDES ****************************************************************/
18 /* GLOBALS *****************************************************************/
20 #define MANAGER_TAG 0x72674D68 /* 'hMgr' */
21 #define SERVICE_TAG 0x63765368 /* 'hSvc' */
23 typedef struct _SCMGR_HANDLE
30 typedef struct _MANAGER_HANDLE
33 WCHAR DatabaseName
[1];
34 } MANAGER_HANDLE
, *PMANAGER_HANDLE
;
37 typedef struct _SERVICE_HANDLE
40 PSERVICE ServiceEntry
;
41 } SERVICE_HANDLE
, *PSERVICE_HANDLE
;
44 #define SC_MANAGER_READ \
45 (STANDARD_RIGHTS_READ | \
46 SC_MANAGER_QUERY_LOCK_STATUS | \
47 SC_MANAGER_ENUMERATE_SERVICE)
49 #define SC_MANAGER_WRITE \
50 (STANDARD_RIGHTS_WRITE | \
51 SC_MANAGER_MODIFY_BOOT_CONFIG | \
52 SC_MANAGER_CREATE_SERVICE)
54 #define SC_MANAGER_EXECUTE \
55 (STANDARD_RIGHTS_EXECUTE | \
57 SC_MANAGER_ENUMERATE_SERVICE | \
58 SC_MANAGER_CONNECT | \
59 SC_MANAGER_CREATE_SERVICE)
62 #define SERVICE_READ \
63 (STANDARD_RIGHTS_READ | \
64 SERVICE_INTERROGATE | \
65 SERVICE_ENUMERATE_DEPENDENTS | \
66 SERVICE_QUERY_STATUS | \
69 #define SERVICE_WRITE \
70 (STANDARD_RIGHTS_WRITE | \
71 SERVICE_CHANGE_CONFIG)
73 #define SERVICE_EXECUTE \
74 (STANDARD_RIGHTS_EXECUTE | \
75 SERVICE_USER_DEFINED_CONTROL | \
76 SERVICE_PAUSE_CONTINUE | \
80 #define TAG_ARRAY_SIZE 32
82 /* VARIABLES ***************************************************************/
84 static GENERIC_MAPPING
85 ScmManagerMapping
= {SC_MANAGER_READ
,
88 SC_MANAGER_ALL_ACCESS
};
90 static GENERIC_MAPPING
91 ScmServiceMapping
= {SERVICE_READ
,
97 /* FUNCTIONS ***************************************************************/
100 ScmStartRpcServer(VOID
)
104 DPRINT("ScmStartRpcServer() called\n");
106 Status
= RpcServerUseProtseqEpW(L
"ncacn_np",
110 if (Status
!= RPC_S_OK
)
112 DPRINT1("RpcServerUseProtseqEpW() failed (Status %lx)\n", Status
);
116 Status
= RpcServerRegisterIf(svcctl_v2_0_s_ifspec
,
119 if (Status
!= RPC_S_OK
)
121 DPRINT1("RpcServerRegisterIf() failed (Status %lx)\n", Status
);
125 Status
= RpcServerListen(1, 20, TRUE
);
126 if (Status
!= RPC_S_OK
)
128 DPRINT1("RpcServerListen() failed (Status %lx)\n", Status
);
132 DPRINT("ScmStartRpcServer() done\n");
137 ScmCreateManagerHandle(LPWSTR lpDatabaseName
,
142 if (lpDatabaseName
== NULL
)
143 lpDatabaseName
= SERVICES_ACTIVE_DATABASEW
;
145 if (_wcsicmp(lpDatabaseName
, SERVICES_FAILED_DATABASEW
) == 0)
147 DPRINT("Database %S, does not exist\n", lpDatabaseName
);
148 return ERROR_DATABASE_DOES_NOT_EXIST
;
150 else if (_wcsicmp(lpDatabaseName
, SERVICES_ACTIVE_DATABASEW
) != 0)
152 DPRINT("Invalid Database name %S.\n", lpDatabaseName
);
153 return ERROR_INVALID_NAME
;
156 Ptr
= HeapAlloc(GetProcessHeap(),
158 FIELD_OFFSET(MANAGER_HANDLE
, DatabaseName
[wcslen(lpDatabaseName
) + 1]));
160 return ERROR_NOT_ENOUGH_MEMORY
;
162 Ptr
->Handle
.Tag
= MANAGER_TAG
;
164 wcscpy(Ptr
->DatabaseName
, lpDatabaseName
);
166 *Handle
= (SC_HANDLE
)Ptr
;
168 return ERROR_SUCCESS
;
173 ScmCreateServiceHandle(PSERVICE lpServiceEntry
,
178 Ptr
= HeapAlloc(GetProcessHeap(),
180 sizeof(SERVICE_HANDLE
));
182 return ERROR_NOT_ENOUGH_MEMORY
;
184 Ptr
->Handle
.Tag
= SERVICE_TAG
;
186 Ptr
->ServiceEntry
= lpServiceEntry
;
188 *Handle
= (SC_HANDLE
)Ptr
;
190 return ERROR_SUCCESS
;
194 static PMANAGER_HANDLE
195 ScmGetServiceManagerFromHandle(SC_RPC_HANDLE Handle
)
197 PMANAGER_HANDLE pManager
= NULL
;
201 if (((PMANAGER_HANDLE
)Handle
)->Handle
.Tag
== MANAGER_TAG
)
202 pManager
= (PMANAGER_HANDLE
)Handle
;
204 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
206 DPRINT1("Exception: Invalid Service Manager handle!\n");
214 static PSERVICE_HANDLE
215 ScmGetServiceFromHandle(SC_RPC_HANDLE Handle
)
217 PSERVICE_HANDLE pService
= NULL
;
221 if (((PSERVICE_HANDLE
)Handle
)->Handle
.Tag
== SERVICE_TAG
)
222 pService
= (PSERVICE_HANDLE
)Handle
;
224 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
226 DPRINT1("Exception: Invalid Service handle!\n");
235 ScmCheckAccess(SC_HANDLE Handle
,
236 DWORD dwDesiredAccess
)
238 PMANAGER_HANDLE hMgr
;
240 hMgr
= (PMANAGER_HANDLE
)Handle
;
241 if (hMgr
->Handle
.Tag
== MANAGER_TAG
)
243 RtlMapGenericMask(&dwDesiredAccess
,
246 hMgr
->Handle
.DesiredAccess
= dwDesiredAccess
;
248 return ERROR_SUCCESS
;
250 else if (hMgr
->Handle
.Tag
== SERVICE_TAG
)
252 RtlMapGenericMask(&dwDesiredAccess
,
255 hMgr
->Handle
.DesiredAccess
= dwDesiredAccess
;
257 return ERROR_SUCCESS
;
260 return ERROR_INVALID_HANDLE
;
265 ScmAssignNewTag(PSERVICE lpService
)
269 DWORD dwGroupTagCount
= 0;
270 PDWORD pdwGroupTags
= NULL
;
272 DWORD dwTagUsedBase
= 1;
273 BOOLEAN TagUsed
[TAG_ARRAY_SIZE
];
277 PLIST_ENTRY ServiceEntry
;
278 PSERVICE CurrentService
;
280 ASSERT(lpService
!= NULL
);
281 ASSERT(lpService
->lpGroup
!= NULL
);
283 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
284 L
"System\\CurrentControlSet\\Control\\GroupOrderList",
289 if (dwError
!= ERROR_SUCCESS
)
292 /* query value length */
294 dwError
= RegQueryValueExW(hKey
,
295 lpService
->lpGroup
->szGroupName
,
301 if (dwError
!= ERROR_SUCCESS
&& dwError
!= ERROR_MORE_DATA
)
304 pdwGroupTags
= HeapAlloc(GetProcessHeap(), 0, cbDataSize
);
307 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
311 dwError
= RegQueryValueExW(hKey
,
312 lpService
->lpGroup
->szGroupName
,
315 (LPBYTE
)pdwGroupTags
,
318 if (dwError
!= ERROR_SUCCESS
)
321 if (cbDataSize
< sizeof(pdwGroupTags
[0]))
324 dwGroupTagCount
= min(pdwGroupTags
[0], cbDataSize
/ sizeof(pdwGroupTags
[0]) - 1);
329 /* mark all tags as unused */
330 for (i
= 0; i
< TAG_ARRAY_SIZE
; i
++)
333 /* mark tags in GroupOrderList as used */
334 for (i
= 1; i
<= dwGroupTagCount
; i
++)
336 dwTagOffset
= pdwGroupTags
[i
] - dwTagUsedBase
;
337 if (dwTagOffset
>= 0 && dwTagOffset
< TAG_ARRAY_SIZE
)
338 TagUsed
[dwTagOffset
] = TRUE
;
341 /* mark tags in service list as used */
342 ServiceEntry
= lpService
->ServiceListEntry
.Flink
;
343 while (ServiceEntry
!= &lpService
->ServiceListEntry
)
345 ASSERT(ServiceEntry
!= NULL
);
346 CurrentService
= CONTAINING_RECORD(ServiceEntry
, SERVICE
, ServiceListEntry
);
347 if (CurrentService
->lpGroup
== lpService
->lpGroup
)
349 dwTagOffset
= CurrentService
->dwTag
- dwTagUsedBase
;
350 if (dwTagOffset
>= 0 && dwTagOffset
< TAG_ARRAY_SIZE
)
351 TagUsed
[dwTagOffset
] = TRUE
;
354 ServiceEntry
= ServiceEntry
->Flink
;
357 /* find unused tag, if any */
358 for (i
= 0; i
< TAG_ARRAY_SIZE
; i
++)
362 dwFreeTag
= dwTagUsedBase
+ i
;
367 dwTagUsedBase
+= TAG_ARRAY_SIZE
;
373 HeapFree(GetProcessHeap(), 0, pdwGroupTags
);
380 lpService
->dwTag
= dwFreeTag
;
381 DPRINT("Assigning new tag %lu to service %S in group %S\n",
382 lpService
->dwTag
, lpService
->lpServiceName
, lpService
->lpGroup
->szGroupName
);
383 dwError
= ERROR_SUCCESS
;
387 DPRINT1("Failed to assign new tag to service %S, error=%lu\n",
388 lpService
->lpServiceName
, dwError
);
395 /* Create a path suitable for the bootloader out of the full path */
397 ScmConvertToBootPathName(wchar_t *CanonName
, wchar_t **RelativeName
)
399 DWORD ServiceNameLen
, BufferSize
, ExpandedLen
;
402 UNICODE_STRING NtPathName
, SystemRoot
, LinkTarget
;
403 OBJECT_ATTRIBUTES ObjectAttributes
;
405 HANDLE SymbolicLinkHandle
;
407 DPRINT("ScmConvertToBootPathName %S\n", CanonName
);
409 ServiceNameLen
= wcslen(CanonName
);
411 /* First check, if it's already good */
412 if (ServiceNameLen
> 12 &&
413 !_wcsnicmp(L
"\\SystemRoot\\", CanonName
, 12))
415 *RelativeName
= HeapAlloc(GetProcessHeap(),
417 (ServiceNameLen
+ 1) * sizeof(WCHAR
));
418 if (*RelativeName
== NULL
)
420 DPRINT("Error allocating memory for boot driver name!\n");
421 return ERROR_NOT_ENOUGH_MEMORY
;
425 wcscpy(*RelativeName
, CanonName
);
427 DPRINT("Bootdriver name %S\n", *RelativeName
);
428 return ERROR_SUCCESS
;
431 /* If it has %SystemRoot% prefix, substitute it to \System*/
432 if (ServiceNameLen
> 13 &&
433 !_wcsnicmp(L
"%SystemRoot%\\", CanonName
, 13))
435 /* There is no +sizeof(wchar_t) because the name is less by 1 wchar */
436 *RelativeName
= HeapAlloc(GetProcessHeap(),
438 ServiceNameLen
* sizeof(WCHAR
));
440 if (*RelativeName
== NULL
)
442 DPRINT("Error allocating memory for boot driver name!\n");
443 return ERROR_NOT_ENOUGH_MEMORY
;
447 wcscpy(*RelativeName
, L
"\\SystemRoot\\");
448 wcscat(*RelativeName
, CanonName
+ 13);
450 DPRINT("Bootdriver name %S\n", *RelativeName
);
451 return ERROR_SUCCESS
;
454 /* Get buffer size needed for expanding env strings */
455 BufferSize
= ExpandEnvironmentStringsW(L
"%SystemRoot%\\", &Dest
, 1);
459 DPRINT("Error during a call to ExpandEnvironmentStringsW()\n");
460 return ERROR_INVALID_ENVIRONMENT
;
463 /* Allocate memory, since the size is known now */
464 Expanded
= HeapAlloc(GetProcessHeap(),
466 (BufferSize
+ 1) * sizeof(WCHAR
));
469 DPRINT("Error allocating memory for boot driver name!\n");
470 return ERROR_NOT_ENOUGH_MEMORY
;
474 if (ExpandEnvironmentStringsW(L
"%SystemRoot%\\", Expanded
, BufferSize
) >
477 DPRINT("Error during a call to ExpandEnvironmentStringsW()\n");
478 HeapFree(GetProcessHeap(), 0, Expanded
);
479 return ERROR_NOT_ENOUGH_MEMORY
;
482 /* Convert to NY-style path */
483 if (!RtlDosPathNameToNtPathName_U(Expanded
, &NtPathName
, NULL
, NULL
))
485 DPRINT("Error during a call to RtlDosPathNameToNtPathName_U()\n");
486 return ERROR_INVALID_ENVIRONMENT
;
489 DPRINT("Converted to NT-style %wZ\n", &NtPathName
);
491 /* No need to keep the dos-path anymore */
492 HeapFree(GetProcessHeap(), 0, Expanded
);
494 /* Copy it to the allocated place */
495 Expanded
= HeapAlloc(GetProcessHeap(),
497 NtPathName
.Length
+ sizeof(UNICODE_NULL
));
500 DPRINT("Error allocating memory for boot driver name!\n");
501 return ERROR_NOT_ENOUGH_MEMORY
;
504 ExpandedLen
= NtPathName
.Length
/ sizeof(WCHAR
);
505 wcsncpy(Expanded
, NtPathName
.Buffer
, ExpandedLen
);
506 Expanded
[ExpandedLen
] = UNICODE_NULL
;
508 if (ServiceNameLen
> ExpandedLen
&&
509 !_wcsnicmp(Expanded
, CanonName
, ExpandedLen
))
511 /* Only \SystemRoot\ is missing */
512 *RelativeName
= HeapAlloc(GetProcessHeap(),
514 (ServiceNameLen
- ExpandedLen
) * sizeof(WCHAR
) + 13*sizeof(WCHAR
));
515 if (*RelativeName
== NULL
)
517 DPRINT("Error allocating memory for boot driver name!\n");
518 HeapFree(GetProcessHeap(), 0, Expanded
);
519 return ERROR_NOT_ENOUGH_MEMORY
;
522 wcscpy(*RelativeName
, L
"\\SystemRoot\\");
523 wcscat(*RelativeName
, CanonName
+ ExpandedLen
);
525 RtlFreeUnicodeString(&NtPathName
);
526 return ERROR_SUCCESS
;
529 /* The most complex case starts here */
530 RtlInitUnicodeString(&SystemRoot
, L
"\\SystemRoot");
531 InitializeObjectAttributes(&ObjectAttributes
,
533 OBJ_CASE_INSENSITIVE
,
537 /* Open this symlink */
538 Status
= NtOpenSymbolicLinkObject(&SymbolicLinkHandle
, SYMBOLIC_LINK_QUERY
, &ObjectAttributes
);
540 if (NT_SUCCESS(Status
))
542 LinkTarget
.Length
= 0;
543 LinkTarget
.MaximumLength
= 0;
545 DPRINT("Opened symbolic link object\n");
547 Status
= NtQuerySymbolicLinkObject(SymbolicLinkHandle
, &LinkTarget
, &BufferSize
);
548 if (NT_SUCCESS(Status
) || Status
== STATUS_BUFFER_TOO_SMALL
)
550 /* Check if required buffer size is sane */
551 if (BufferSize
> 0xFFFD)
553 DPRINT("Too large buffer required\n");
556 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
557 HeapFree(GetProcessHeap(), 0, Expanded
);
558 return ERROR_NOT_ENOUGH_MEMORY
;
561 /* Alloc the string */
562 LinkTarget
.Length
= (USHORT
)BufferSize
;
563 LinkTarget
.MaximumLength
= LinkTarget
.Length
+ sizeof(UNICODE_NULL
);
564 LinkTarget
.Buffer
= HeapAlloc(GetProcessHeap(),
566 LinkTarget
.MaximumLength
);
567 if (!LinkTarget
.Buffer
)
569 DPRINT("Unable to alloc buffer\n");
570 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
571 HeapFree(GetProcessHeap(), 0, Expanded
);
572 return ERROR_NOT_ENOUGH_MEMORY
;
575 /* Do a real query now */
576 Status
= NtQuerySymbolicLinkObject(SymbolicLinkHandle
, &LinkTarget
, &BufferSize
);
577 if (NT_SUCCESS(Status
))
579 DPRINT("LinkTarget: %wZ\n", &LinkTarget
);
581 ExpandedLen
= LinkTarget
.Length
/ sizeof(WCHAR
);
582 if ((ServiceNameLen
> ExpandedLen
) &&
583 !_wcsnicmp(LinkTarget
.Buffer
, CanonName
, ExpandedLen
))
585 *RelativeName
= HeapAlloc(GetProcessHeap(),
587 (ServiceNameLen
- ExpandedLen
) * sizeof(WCHAR
) + 13*sizeof(WCHAR
));
589 if (*RelativeName
== NULL
)
591 DPRINT("Unable to alloc buffer\n");
592 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
593 HeapFree(GetProcessHeap(), 0, Expanded
);
594 RtlFreeUnicodeString(&NtPathName
);
595 return ERROR_NOT_ENOUGH_MEMORY
;
598 /* Copy it over, substituting the first part
600 wcscpy(*RelativeName
, L
"\\SystemRoot\\");
601 wcscat(*RelativeName
, CanonName
+ExpandedLen
+1);
604 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
605 HeapFree(GetProcessHeap(), 0, Expanded
);
606 RtlFreeUnicodeString(&NtPathName
);
609 return ERROR_SUCCESS
;
613 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
614 HeapFree(GetProcessHeap(), 0, Expanded
);
615 RtlFreeUnicodeString(&NtPathName
);
616 return ERROR_INVALID_PARAMETER
;
621 DPRINT("Error, Status = %08X\n", Status
);
622 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
623 HeapFree(GetProcessHeap(), 0, Expanded
);
624 RtlFreeUnicodeString(&NtPathName
);
625 return ERROR_INVALID_PARAMETER
;
630 DPRINT("Error, Status = %08X\n", Status
);
631 if (SymbolicLinkHandle
) NtClose(SymbolicLinkHandle
);
632 HeapFree(GetProcessHeap(), 0, Expanded
);
633 RtlFreeUnicodeString(&NtPathName
);
634 return ERROR_INVALID_PARAMETER
;
639 DPRINT("Error, Status = %08X\n", Status
);
640 HeapFree(GetProcessHeap(), 0, Expanded
);
641 return ERROR_INVALID_PARAMETER
;
645 *RelativeName
= NULL
;
646 return ERROR_INVALID_PARAMETER
;
651 ScmCanonDriverImagePath(DWORD dwStartType
,
652 const wchar_t *lpServiceName
,
653 wchar_t **lpCanonName
)
655 DWORD ServiceNameLen
, Result
;
656 UNICODE_STRING NtServiceName
;
658 const WCHAR
*SourceName
= lpServiceName
;
660 /* Calculate the length of the service's name */
661 ServiceNameLen
= wcslen(lpServiceName
);
663 /* 12 is wcslen(L"\\SystemRoot\\") */
664 if (ServiceNameLen
> 12 &&
665 !_wcsnicmp(L
"\\SystemRoot\\", lpServiceName
, 12))
667 /* SystemRoot prefix is already included */
668 *lpCanonName
= HeapAlloc(GetProcessHeap(),
670 (ServiceNameLen
+ 1) * sizeof(WCHAR
));
672 if (*lpCanonName
== NULL
)
674 DPRINT("Error allocating memory for canonized service name!\n");
675 return ERROR_NOT_ENOUGH_MEMORY
;
678 /* If it's a boot-time driver, it must be systemroot relative */
679 if (dwStartType
== SERVICE_BOOT_START
)
683 wcscpy(*lpCanonName
, SourceName
);
685 DPRINT("Canonicalized name %S\n", *lpCanonName
);
689 /* Check if it has %SystemRoot% (len=13) */
690 if (ServiceNameLen
> 13 &&
691 !_wcsnicmp(L
"%SystemRoot%\\", lpServiceName
, 13))
693 /* Substitute %SystemRoot% with \\SystemRoot\\ */
694 *lpCanonName
= HeapAlloc(GetProcessHeap(),
696 (ServiceNameLen
+ 1) * sizeof(WCHAR
));
698 if (*lpCanonName
== NULL
)
700 DPRINT("Error allocating memory for canonized service name!\n");
701 return ERROR_NOT_ENOUGH_MEMORY
;
704 /* If it's a boot-time driver, it must be systemroot relative */
705 if (dwStartType
== SERVICE_BOOT_START
)
706 wcscpy(*lpCanonName
, L
"\\SystemRoot\\");
708 wcscat(*lpCanonName
, lpServiceName
+ 13);
710 DPRINT("Canonicalized name %S\n", *lpCanonName
);
714 /* Check if it's a relative path name */
715 if (lpServiceName
[0] != L
'\\' && lpServiceName
[1] != L
':')
717 *lpCanonName
= HeapAlloc(GetProcessHeap(),
719 (ServiceNameLen
+ 1) * sizeof(WCHAR
));
721 if (*lpCanonName
== NULL
)
723 DPRINT("Error allocating memory for canonized service name!\n");
724 return ERROR_NOT_ENOUGH_MEMORY
;
727 /* Just copy it over without changing */
728 wcscpy(*lpCanonName
, lpServiceName
);
733 /* It seems to be a DOS path, convert it */
734 if (!RtlDosPathNameToNtPathName_U(lpServiceName
, &NtServiceName
, NULL
, NULL
))
736 DPRINT("RtlDosPathNameToNtPathName_U() failed!\n");
737 return ERROR_INVALID_PARAMETER
;
740 *lpCanonName
= HeapAlloc(GetProcessHeap(),
742 NtServiceName
.Length
+ sizeof(WCHAR
));
744 if (*lpCanonName
== NULL
)
746 DPRINT("Error allocating memory for canonized service name!\n");
747 RtlFreeUnicodeString(&NtServiceName
);
748 return ERROR_NOT_ENOUGH_MEMORY
;
751 /* Copy the string */
752 wcsncpy(*lpCanonName
, NtServiceName
.Buffer
, NtServiceName
.Length
/ sizeof(WCHAR
));
754 /* The unicode string is not needed anymore */
755 RtlFreeUnicodeString(&NtServiceName
);
757 if (dwStartType
!= SERVICE_BOOT_START
)
759 DPRINT("Canonicalized name %S\n", *lpCanonName
);
763 /* The service is boot-started, so must be relative */
764 Result
= ScmConvertToBootPathName(*lpCanonName
, &RelativeName
);
767 /* There is a problem, free name and return */
768 HeapFree(GetProcessHeap(), 0, *lpCanonName
);
769 DPRINT("Error converting named!\n");
773 ASSERT(RelativeName
);
775 /* Copy that string */
776 wcscpy(*lpCanonName
, RelativeName
+ 12);
778 /* Free the allocated buffer */
779 HeapFree(GetProcessHeap(), 0, RelativeName
);
781 DPRINT("Canonicalized name %S\n", *lpCanonName
);
788 /* Internal recursive function */
789 /* Need to search for every dependency on every service */
791 Int_EnumDependentServicesW(HKEY hServicesKey
,
793 DWORD dwServiceState
,
794 PSERVICE
*lpServices
,
795 LPDWORD pcbBytesNeeded
,
796 LPDWORD lpServicesReturned
)
798 DWORD dwError
= ERROR_SUCCESS
;
799 WCHAR szNameBuf
[MAX_PATH
];
800 WCHAR szValueBuf
[MAX_PATH
];
801 WCHAR
*lpszNameBuf
= szNameBuf
;
802 WCHAR
*lpszValueBuf
= szValueBuf
;
806 PSERVICE lpCurrentService
;
807 HKEY hServiceEnumKey
;
808 DWORD dwCurrentServiceState
= SERVICE_ACTIVE
;
809 DWORD dwDependServiceStrPtr
= 0;
810 DWORD dwRequiredSize
= 0;
812 /* Get the number of service keys */
813 dwError
= RegQueryInfoKeyW(hServicesKey
,
825 if (dwError
!= ERROR_SUCCESS
)
827 DPRINT("ERROR! Unable to get number of services keys.\n");
831 /* Iterate the service keys to see if another service depends on the this service */
832 for (dwIteration
= 0; dwIteration
< dwNumSubKeys
; dwIteration
++)
835 dwError
= RegEnumKeyExW(hServicesKey
,
843 if (dwError
!= ERROR_SUCCESS
)
846 /* Open the Service key */
847 dwError
= RegOpenKeyExW(hServicesKey
,
852 if (dwError
!= ERROR_SUCCESS
)
857 /* Check for the DependOnService Value */
858 dwError
= RegQueryValueExW(hServiceEnumKey
,
862 (LPBYTE
)lpszValueBuf
,
865 /* FIXME: Handle load order. */
867 /* If the service found has a DependOnService value */
868 if (dwError
== ERROR_SUCCESS
)
870 dwDependServiceStrPtr
= 0;
872 /* Can be more than one Dependencies in the DependOnService string */
873 while (wcslen(lpszValueBuf
+ dwDependServiceStrPtr
) > 0)
875 if (_wcsicmp(lpszValueBuf
+ dwDependServiceStrPtr
, lpService
->lpServiceName
) == 0)
877 /* Get the current enumed service pointer */
878 lpCurrentService
= ScmGetServiceEntryByName(lpszNameBuf
);
880 /* Check for valid Service */
881 if (!lpCurrentService
)
883 /* This should never happen! */
884 DPRINT("This should not happen at this point, report to Developer\n");
885 return ERROR_NOT_FOUND
;
888 /* Determine state the service is in */
889 if (lpCurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
890 dwCurrentServiceState
= SERVICE_INACTIVE
;
892 /* If the ServiceState matches that requested or searching for SERVICE_STATE_ALL */
893 if ((dwCurrentServiceState
== dwServiceState
) ||
894 (dwServiceState
== SERVICE_STATE_ALL
))
896 /* Calculate the required size */
897 dwRequiredSize
+= sizeof(SERVICE_STATUS
);
898 dwRequiredSize
+= ((wcslen(lpCurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
));
899 dwRequiredSize
+= ((wcslen(lpCurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
901 /* Add the size for service name and display name pointers */
902 dwRequiredSize
+= (2 * sizeof(PVOID
));
904 /* increase the BytesNeeded size */
905 *pcbBytesNeeded
= *pcbBytesNeeded
+ dwRequiredSize
;
907 /* Don't fill callers buffer yet, as MSDN read that the last service with dependency
910 /* Recursive call to check for its dependencies */
911 Int_EnumDependentServicesW(hServicesKey
,
918 /* If the lpServices is valid set the service pointer */
920 lpServices
[*lpServicesReturned
] = lpCurrentService
;
922 *lpServicesReturned
= *lpServicesReturned
+ 1;
926 dwDependServiceStrPtr
+= (wcslen(lpszValueBuf
+ dwDependServiceStrPtr
) + 1);
929 else if (*pcbBytesNeeded
)
931 dwError
= ERROR_SUCCESS
;
934 RegCloseKey(hServiceEnumKey
);
942 DWORD
RCloseServiceHandle(
943 LPSC_RPC_HANDLE hSCObject
)
945 PMANAGER_HANDLE hManager
;
946 PSERVICE_HANDLE hService
;
950 DWORD pcbBytesNeeded
= 0;
951 DWORD dwServicesReturned
= 0;
953 DPRINT("RCloseServiceHandle() called\n");
955 DPRINT("hSCObject = %p\n", *hSCObject
);
958 return ERROR_INVALID_HANDLE
;
960 hManager
= ScmGetServiceManagerFromHandle(*hSCObject
);
961 hService
= ScmGetServiceFromHandle(*hSCObject
);
963 if (hManager
!= NULL
)
965 DPRINT("Found manager handle\n");
967 /* FIXME: add handle cleanup code */
969 HeapFree(GetProcessHeap(), 0, hManager
);
974 DPRINT("RCloseServiceHandle() done\n");
975 return ERROR_SUCCESS
;
977 else if (hService
!= NULL
)
979 DPRINT("Found service handle\n");
981 /* Lock the service database exlusively */
982 ScmLockDatabaseExclusive();
984 /* Get the pointer to the service record */
985 lpService
= hService
->ServiceEntry
;
987 /* FIXME: add handle cleanup code */
989 /* Free the handle */
990 HeapFree(GetProcessHeap(), 0, hService
);
993 ASSERT(lpService
->dwRefCount
> 0);
995 lpService
->dwRefCount
--;
996 DPRINT("CloseServiceHandle - lpService->dwRefCount %u\n",
997 lpService
->dwRefCount
);
999 if (lpService
->dwRefCount
== 0)
1001 /* If this service has been marked for deletion */
1002 if (lpService
->bDeleted
)
1004 /* Open the Services Reg key */
1005 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1006 L
"System\\CurrentControlSet\\Services",
1008 KEY_SET_VALUE
| KEY_READ
,
1010 if (dwError
!= ERROR_SUCCESS
)
1012 DPRINT("Failed to open services key\n");
1013 ScmUnlockDatabase();
1017 /* Call the internal function with NULL, just to get bytes we need */
1018 Int_EnumDependentServicesW(hServicesKey
,
1023 &dwServicesReturned
);
1025 /* if pcbBytesNeeded returned a value then there are services running that are dependent on this service */
1028 DPRINT("Deletion failed due to running dependencies.\n");
1029 RegCloseKey(hServicesKey
);
1030 ScmUnlockDatabase();
1031 return ERROR_SUCCESS
;
1034 /* There are no references and no runnning dependencies,
1035 it is now safe to delete the service */
1037 /* Delete the Service Key */
1038 dwError
= RegDeleteKeyW(hServicesKey
,
1039 lpService
->lpServiceName
);
1041 RegCloseKey(hServicesKey
);
1043 if (dwError
!= ERROR_SUCCESS
)
1045 DPRINT("Failed to Delete the Service Registry key\n");
1046 ScmUnlockDatabase();
1050 /* Delete the Service */
1051 ScmDeleteServiceRecord(lpService
);
1055 ScmUnlockDatabase();
1059 DPRINT("RCloseServiceHandle() done\n");
1060 return ERROR_SUCCESS
;
1063 DPRINT("Invalid handle tag (Tag %lx)\n", hManager
->Handle
.Tag
);
1065 return ERROR_INVALID_HANDLE
;
1070 DWORD
RControlService(
1071 SC_RPC_HANDLE hService
,
1073 LPSERVICE_STATUS lpServiceStatus
)
1075 PSERVICE_HANDLE hSvc
;
1077 ACCESS_MASK DesiredAccess
;
1078 DWORD dwError
= ERROR_SUCCESS
;
1079 DWORD pcbBytesNeeded
= 0;
1080 DWORD dwServicesReturned
= 0;
1081 DWORD dwControlsAccepted
;
1082 DWORD dwCurrentState
;
1083 HKEY hServicesKey
= NULL
;
1085 DPRINT("RControlService() called\n");
1088 return ERROR_SHUTDOWN_IN_PROGRESS
;
1090 /* Check the service handle */
1091 hSvc
= ScmGetServiceFromHandle(hService
);
1094 DPRINT1("Invalid service handle!\n");
1095 return ERROR_INVALID_HANDLE
;
1098 /* Check the service entry point */
1099 lpService
= hSvc
->ServiceEntry
;
1100 if (lpService
== NULL
)
1102 DPRINT1("lpService == NULL!\n");
1103 return ERROR_INVALID_HANDLE
;
1106 /* Check access rights */
1109 case SERVICE_CONTROL_STOP
:
1110 DesiredAccess
= SERVICE_STOP
;
1113 case SERVICE_CONTROL_PAUSE
:
1114 case SERVICE_CONTROL_CONTINUE
:
1115 DesiredAccess
= SERVICE_PAUSE_CONTINUE
;
1118 case SERVICE_INTERROGATE
:
1119 DesiredAccess
= SERVICE_INTERROGATE
;
1123 if (dwControl
>= 128 && dwControl
<= 255)
1124 DesiredAccess
= SERVICE_USER_DEFINED_CONTROL
;
1126 return ERROR_INVALID_PARAMETER
;
1130 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
1132 return ERROR_ACCESS_DENIED
;
1134 /* Return the current service status information */
1135 RtlCopyMemory(lpServiceStatus
,
1137 sizeof(SERVICE_STATUS
));
1139 if (dwControl
== SERVICE_CONTROL_STOP
)
1141 /* Check if the service has dependencies running as windows
1142 doesn't stop a service that does */
1144 /* Open the Services Reg key */
1145 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
1146 L
"System\\CurrentControlSet\\Services",
1150 if (dwError
!= ERROR_SUCCESS
)
1152 DPRINT("Failed to open services key\n");
1156 /* Call the internal function with NULL, just to get bytes we need */
1157 Int_EnumDependentServicesW(hServicesKey
,
1162 &dwServicesReturned
);
1164 RegCloseKey(hServicesKey
);
1166 /* If pcbBytesNeeded is not zero then there are services running that
1167 are dependent on this service */
1168 if (pcbBytesNeeded
!= 0)
1170 DPRINT("Service has running dependencies. Failed to stop service.\n");
1171 return ERROR_DEPENDENT_SERVICES_RUNNING
;
1175 if (lpService
->Status
.dwServiceType
& SERVICE_DRIVER
)
1177 /* Send control code to the driver */
1178 dwError
= ScmControlDriver(lpService
,
1184 dwControlsAccepted
= lpService
->Status
.dwControlsAccepted
;
1185 dwCurrentState
= lpService
->Status
.dwCurrentState
;
1187 /* Return ERROR_SERVICE_NOT_ACTIVE if the service has not been started */
1188 if (lpService
->lpImage
== NULL
|| dwCurrentState
== SERVICE_STOPPED
)
1189 return ERROR_SERVICE_NOT_ACTIVE
;
1191 /* Check the current state before sending a control request */
1192 switch (dwCurrentState
)
1194 case SERVICE_STOP_PENDING
:
1195 case SERVICE_STOPPED
:
1196 return ERROR_SERVICE_CANNOT_ACCEPT_CTRL
;
1198 case SERVICE_START_PENDING
:
1201 case SERVICE_CONTROL_STOP
:
1204 case SERVICE_CONTROL_INTERROGATE
:
1205 RtlCopyMemory(lpServiceStatus
,
1207 sizeof(SERVICE_STATUS
));
1208 return ERROR_SUCCESS
;
1211 return ERROR_SERVICE_CANNOT_ACCEPT_CTRL
;
1216 /* Check if the control code is acceptable to the service */
1219 case SERVICE_CONTROL_STOP
:
1220 if ((dwControlsAccepted
& SERVICE_ACCEPT_STOP
) == 0)
1221 return ERROR_INVALID_SERVICE_CONTROL
;
1224 case SERVICE_CONTROL_PAUSE
:
1225 case SERVICE_CONTROL_CONTINUE
:
1226 if ((dwControlsAccepted
& SERVICE_ACCEPT_PAUSE_CONTINUE
) == 0)
1227 return ERROR_INVALID_SERVICE_CONTROL
;
1231 /* Send control code to the service */
1232 dwError
= ScmControlService(lpService
,
1235 /* Return service status information */
1236 RtlCopyMemory(lpServiceStatus
,
1238 sizeof(SERVICE_STATUS
));
1241 if ((dwError
== ERROR_SUCCESS
) && (pcbBytesNeeded
))
1242 dwError
= ERROR_DEPENDENT_SERVICES_RUNNING
;
1249 DWORD
RDeleteService(
1250 SC_RPC_HANDLE hService
)
1252 PSERVICE_HANDLE hSvc
;
1256 DPRINT("RDeleteService() called\n");
1259 return ERROR_SHUTDOWN_IN_PROGRESS
;
1261 hSvc
= ScmGetServiceFromHandle(hService
);
1264 DPRINT1("Invalid service handle!\n");
1265 return ERROR_INVALID_HANDLE
;
1268 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
1270 return ERROR_ACCESS_DENIED
;
1272 lpService
= hSvc
->ServiceEntry
;
1273 if (lpService
== NULL
)
1275 DPRINT("lpService == NULL!\n");
1276 return ERROR_INVALID_HANDLE
;
1279 /* Lock the service database exclusively */
1280 ScmLockDatabaseExclusive();
1282 if (lpService
->bDeleted
)
1284 DPRINT("The service has already been marked for delete!\n");
1285 dwError
= ERROR_SERVICE_MARKED_FOR_DELETE
;
1289 /* Mark service for delete */
1290 lpService
->bDeleted
= TRUE
;
1292 dwError
= ScmMarkServiceForDelete(lpService
);
1295 /* Unlock the service database */
1296 ScmUnlockDatabase();
1298 DPRINT("RDeleteService() done\n");
1305 DWORD
RLockServiceDatabase(
1306 SC_RPC_HANDLE hSCManager
,
1307 LPSC_RPC_LOCK lpLock
)
1309 PMANAGER_HANDLE hMgr
;
1311 DPRINT("RLockServiceDatabase() called\n");
1315 hMgr
= ScmGetServiceManagerFromHandle(hSCManager
);
1318 DPRINT1("Invalid service manager handle!\n");
1319 return ERROR_INVALID_HANDLE
;
1322 if (!RtlAreAllAccessesGranted(hMgr
->Handle
.DesiredAccess
,
1324 return ERROR_ACCESS_DENIED
;
1326 // return ScmLockDatabase(0, hMgr->0xC, hLock);
1328 /* FIXME: Lock the database */
1329 *lpLock
= (SC_RPC_LOCK
)0x12345678; /* Dummy! */
1331 return ERROR_SUCCESS
;
1336 DWORD
RQueryServiceObjectSecurity(
1337 SC_RPC_HANDLE hService
,
1338 SECURITY_INFORMATION dwSecurityInformation
,
1339 LPBYTE lpSecurityDescriptor
,
1341 LPBOUNDED_DWORD_256K pcbBytesNeeded
)
1343 PSERVICE_HANDLE hSvc
;
1345 ULONG DesiredAccess
= 0;
1347 DWORD dwBytesNeeded
;
1351 SECURITY_DESCRIPTOR ObjectDescriptor
;
1353 DPRINT("RQueryServiceObjectSecurity() called\n");
1355 hSvc
= ScmGetServiceFromHandle(hService
);
1358 DPRINT1("Invalid service handle!\n");
1359 return ERROR_INVALID_HANDLE
;
1362 if (dwSecurityInformation
& (DACL_SECURITY_INFORMATION
|
1363 GROUP_SECURITY_INFORMATION
|
1364 OWNER_SECURITY_INFORMATION
))
1365 DesiredAccess
|= READ_CONTROL
;
1367 if (dwSecurityInformation
& SACL_SECURITY_INFORMATION
)
1368 DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
1370 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
1373 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
1374 return ERROR_ACCESS_DENIED
;
1377 lpService
= hSvc
->ServiceEntry
;
1378 if (lpService
== NULL
)
1380 DPRINT("lpService == NULL!\n");
1381 return ERROR_INVALID_HANDLE
;
1384 /* Lock the service database */
1385 ScmLockDatabaseShared();
1389 Status
= RtlCreateSecurityDescriptor(&ObjectDescriptor
, SECURITY_DESCRIPTOR_REVISION
);
1391 Status
= RtlQuerySecurityObject(&ObjectDescriptor
/* lpService->lpSecurityDescriptor */,
1392 dwSecurityInformation
,
1393 (PSECURITY_DESCRIPTOR
)lpSecurityDescriptor
,
1397 /* Unlock the service database */
1398 ScmUnlockDatabase();
1400 if (NT_SUCCESS(Status
))
1402 *pcbBytesNeeded
= dwBytesNeeded
;
1403 dwError
= STATUS_SUCCESS
;
1405 else if (Status
== STATUS_BUFFER_TOO_SMALL
)
1407 *pcbBytesNeeded
= dwBytesNeeded
;
1408 dwError
= ERROR_INSUFFICIENT_BUFFER
;
1410 else if (Status
== STATUS_BAD_DESCRIPTOR_FORMAT
)
1412 dwError
= ERROR_GEN_FAILURE
;
1416 dwError
= RtlNtStatusToDosError(Status
);
1424 DWORD
RSetServiceObjectSecurity(
1425 SC_RPC_HANDLE hService
,
1426 DWORD dwSecurityInformation
,
1427 LPBYTE lpSecurityDescriptor
,
1428 DWORD dwSecuityDescriptorSize
)
1430 PSERVICE_HANDLE hSvc
;
1432 ULONG DesiredAccess
= 0;
1433 /* HANDLE hToken = NULL; */
1435 /* NTSTATUS Status; */
1438 DPRINT("RSetServiceObjectSecurity() called\n");
1440 hSvc
= ScmGetServiceFromHandle(hService
);
1443 DPRINT1("Invalid service handle!\n");
1444 return ERROR_INVALID_HANDLE
;
1447 if (dwSecurityInformation
== 0 ||
1448 dwSecurityInformation
& ~(OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
1449 | DACL_SECURITY_INFORMATION
| SACL_SECURITY_INFORMATION
))
1450 return ERROR_INVALID_PARAMETER
;
1452 if (!RtlValidSecurityDescriptor((PSECURITY_DESCRIPTOR
)lpSecurityDescriptor
))
1453 return ERROR_INVALID_PARAMETER
;
1455 if (dwSecurityInformation
& SACL_SECURITY_INFORMATION
)
1456 DesiredAccess
|= ACCESS_SYSTEM_SECURITY
;
1458 if (dwSecurityInformation
& DACL_SECURITY_INFORMATION
)
1459 DesiredAccess
|= WRITE_DAC
;
1461 if (dwSecurityInformation
& (OWNER_SECURITY_INFORMATION
| GROUP_SECURITY_INFORMATION
))
1462 DesiredAccess
|= WRITE_OWNER
;
1464 if ((dwSecurityInformation
& OWNER_SECURITY_INFORMATION
) &&
1465 (((PISECURITY_DESCRIPTOR
)lpSecurityDescriptor
)->Owner
== NULL
))
1466 return ERROR_INVALID_PARAMETER
;
1468 if ((dwSecurityInformation
& GROUP_SECURITY_INFORMATION
) &&
1469 (((PISECURITY_DESCRIPTOR
)lpSecurityDescriptor
)->Group
== NULL
))
1470 return ERROR_INVALID_PARAMETER
;
1472 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
1475 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
1476 return ERROR_ACCESS_DENIED
;
1479 lpService
= hSvc
->ServiceEntry
;
1480 if (lpService
== NULL
)
1482 DPRINT("lpService == NULL!\n");
1483 return ERROR_INVALID_HANDLE
;
1486 if (lpService
->bDeleted
)
1487 return ERROR_SERVICE_MARKED_FOR_DELETE
;
1490 RpcImpersonateClient(NULL
);
1492 Status
= NtOpenThreadToken(NtCurrentThread(),
1496 if (!NT_SUCCESS(Status
))
1497 return RtlNtStatusToDosError(Status
);
1502 /* Lock the service database exclusive */
1503 ScmLockDatabaseExclusive();
1506 Status
= RtlSetSecurityObject(dwSecurityInformation
,
1507 (PSECURITY_DESCRIPTOR
)lpSecurityDescriptor
,
1508 &lpService
->lpSecurityDescriptor
,
1511 if (!NT_SUCCESS(Status
))
1513 dwError
= RtlNtStatusToDosError(Status
);
1518 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
1519 READ_CONTROL
| KEY_CREATE_SUB_KEY
| KEY_SET_VALUE
,
1521 if (dwError
!= ERROR_SUCCESS
)
1525 dwError
= ERROR_SUCCESS
;
1526 // dwError = ScmWriteSecurityDescriptor(hServiceKey,
1527 // lpService->lpSecurityDescriptor);
1529 RegFlushKey(hServiceKey
);
1530 RegCloseKey(hServiceKey
);
1539 /* Unlock service database */
1540 ScmUnlockDatabase();
1542 DPRINT("RSetServiceObjectSecurity() done (Error %lu)\n", dwError
);
1549 DWORD
RQueryServiceStatus(
1550 SC_RPC_HANDLE hService
,
1551 LPSERVICE_STATUS lpServiceStatus
)
1553 PSERVICE_HANDLE hSvc
;
1556 DPRINT("RQueryServiceStatus() called\n");
1559 return ERROR_SHUTDOWN_IN_PROGRESS
;
1561 hSvc
= ScmGetServiceFromHandle(hService
);
1564 DPRINT1("Invalid service handle!\n");
1565 return ERROR_INVALID_HANDLE
;
1568 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
1569 SERVICE_QUERY_STATUS
))
1571 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
1572 return ERROR_ACCESS_DENIED
;
1575 lpService
= hSvc
->ServiceEntry
;
1576 if (lpService
== NULL
)
1578 DPRINT("lpService == NULL!\n");
1579 return ERROR_INVALID_HANDLE
;
1582 /* Lock the service database shared */
1583 ScmLockDatabaseShared();
1585 /* Return service status information */
1586 RtlCopyMemory(lpServiceStatus
,
1588 sizeof(SERVICE_STATUS
));
1590 /* Unlock the service database */
1591 ScmUnlockDatabase();
1593 return ERROR_SUCCESS
;
1598 ScmIsValidServiceState(DWORD dwCurrentState
)
1600 switch (dwCurrentState
)
1602 case SERVICE_STOPPED
:
1603 case SERVICE_START_PENDING
:
1604 case SERVICE_STOP_PENDING
:
1605 case SERVICE_RUNNING
:
1606 case SERVICE_CONTINUE_PENDING
:
1607 case SERVICE_PAUSE_PENDING
:
1608 case SERVICE_PAUSED
:
1618 DWORD
RSetServiceStatus(
1619 RPC_SERVICE_STATUS_HANDLE hServiceStatus
,
1620 LPSERVICE_STATUS lpServiceStatus
)
1624 DPRINT("RSetServiceStatus() called\n");
1625 DPRINT("hServiceStatus = %p\n", hServiceStatus
);
1626 DPRINT("dwServiceType = %lu\n", lpServiceStatus
->dwServiceType
);
1627 DPRINT("dwCurrentState = %lu\n", lpServiceStatus
->dwCurrentState
);
1628 DPRINT("dwControlsAccepted = %lu\n", lpServiceStatus
->dwControlsAccepted
);
1629 DPRINT("dwWin32ExitCode = %lu\n", lpServiceStatus
->dwWin32ExitCode
);
1630 DPRINT("dwServiceSpecificExitCode = %lu\n", lpServiceStatus
->dwServiceSpecificExitCode
);
1631 DPRINT("dwCheckPoint = %lu\n", lpServiceStatus
->dwCheckPoint
);
1632 DPRINT("dwWaitHint = %lu\n", lpServiceStatus
->dwWaitHint
);
1634 if (hServiceStatus
== 0)
1636 DPRINT("hServiceStatus == NULL!\n");
1637 return ERROR_INVALID_HANDLE
;
1640 lpService
= (PSERVICE
)hServiceStatus
;
1641 if (lpService
== NULL
)
1643 DPRINT("lpService == NULL!\n");
1644 return ERROR_INVALID_HANDLE
;
1647 /* Check current state */
1648 if (!ScmIsValidServiceState(lpServiceStatus
->dwCurrentState
))
1650 DPRINT("Invalid service state!\n");
1651 return ERROR_INVALID_DATA
;
1654 /* Check service type */
1655 if (!(lpServiceStatus
->dwServiceType
& SERVICE_WIN32
) &&
1656 (lpServiceStatus
->dwServiceType
& SERVICE_DRIVER
))
1658 DPRINT("Invalid service type!\n");
1659 return ERROR_INVALID_DATA
;
1662 /* Check accepted controls */
1663 if (lpServiceStatus
->dwControlsAccepted
& ~0xFF)
1665 DPRINT("Invalid controls accepted!\n");
1666 return ERROR_INVALID_DATA
;
1669 /* Lock the service database exclusively */
1670 ScmLockDatabaseExclusive();
1672 RtlCopyMemory(&lpService
->Status
,
1674 sizeof(SERVICE_STATUS
));
1676 /* Unlock the service database */
1677 ScmUnlockDatabase();
1679 DPRINT("Set %S to %lu\n", lpService
->lpDisplayName
, lpService
->Status
.dwCurrentState
);
1680 DPRINT("RSetServiceStatus() done\n");
1682 return ERROR_SUCCESS
;
1687 DWORD
RUnlockServiceDatabase(
1691 return ERROR_SUCCESS
;
1696 DWORD
RNotifyBootConfigStatus(
1697 SVCCTL_HANDLEW lpMachineName
,
1698 DWORD BootAcceptable
)
1700 DPRINT1("RNotifyBootConfigStatus(%p %lu) called\n", lpMachineName
, BootAcceptable
);
1701 return ERROR_SUCCESS
;
1704 // return ERROR_CALL_NOT_IMPLEMENTED;
1709 DWORD
RI_ScSetServiceBitsW(
1710 RPC_SERVICE_STATUS_HANDLE hServiceStatus
,
1711 DWORD dwServiceBits
,
1713 int bUpdateImmediately
,
1717 return ERROR_CALL_NOT_IMPLEMENTED
;
1722 DWORD
RChangeServiceConfigW(
1723 SC_RPC_HANDLE hService
,
1724 DWORD dwServiceType
,
1726 DWORD dwErrorControl
,
1727 LPWSTR lpBinaryPathName
,
1728 LPWSTR lpLoadOrderGroup
,
1730 LPBYTE lpDependencies
,
1732 LPWSTR lpServiceStartName
,
1735 LPWSTR lpDisplayName
)
1737 DWORD dwError
= ERROR_SUCCESS
;
1738 PSERVICE_HANDLE hSvc
;
1739 PSERVICE lpService
= NULL
;
1740 HKEY hServiceKey
= NULL
;
1741 LPWSTR lpDisplayNameW
= NULL
;
1742 LPWSTR lpImagePathW
= NULL
;
1744 DPRINT("RChangeServiceConfigW() called\n");
1745 DPRINT("dwServiceType = %lu\n", dwServiceType
);
1746 DPRINT("dwStartType = %lu\n", dwStartType
);
1747 DPRINT("dwErrorControl = %lu\n", dwErrorControl
);
1748 DPRINT("lpBinaryPathName = %S\n", lpBinaryPathName
);
1749 DPRINT("lpLoadOrderGroup = %S\n", lpLoadOrderGroup
);
1750 DPRINT("lpDisplayName = %S\n", lpDisplayName
);
1753 return ERROR_SHUTDOWN_IN_PROGRESS
;
1755 hSvc
= ScmGetServiceFromHandle(hService
);
1758 DPRINT1("Invalid service handle!\n");
1759 return ERROR_INVALID_HANDLE
;
1762 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
1763 SERVICE_CHANGE_CONFIG
))
1765 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
1766 return ERROR_ACCESS_DENIED
;
1769 lpService
= hSvc
->ServiceEntry
;
1770 if (lpService
== NULL
)
1772 DPRINT("lpService == NULL!\n");
1773 return ERROR_INVALID_HANDLE
;
1776 /* Lock the service database exclusively */
1777 ScmLockDatabaseExclusive();
1779 if (lpService
->bDeleted
)
1781 DPRINT("The service has already been marked for delete!\n");
1782 dwError
= ERROR_SERVICE_MARKED_FOR_DELETE
;
1786 /* Open the service key */
1787 dwError
= ScmOpenServiceKey(lpService
->szServiceName
,
1790 if (dwError
!= ERROR_SUCCESS
)
1793 /* Write service data to the registry */
1794 /* Set the display name */
1795 if (lpDisplayName
!= NULL
&& *lpDisplayName
!= 0)
1797 RegSetValueExW(hServiceKey
,
1801 (LPBYTE
)lpDisplayName
,
1802 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
1804 /* Update the display name */
1805 lpDisplayNameW
= HeapAlloc(GetProcessHeap(),
1807 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
1808 if (lpDisplayNameW
== NULL
)
1810 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
1814 if (lpService
->lpDisplayName
!= lpService
->lpServiceName
)
1815 HeapFree(GetProcessHeap(), 0, lpService
->lpDisplayName
);
1817 lpService
->lpDisplayName
= lpDisplayNameW
;
1820 if (dwServiceType
!= SERVICE_NO_CHANGE
)
1822 /* Set the service type */
1823 dwError
= RegSetValueExW(hServiceKey
,
1827 (LPBYTE
)&dwServiceType
,
1829 if (dwError
!= ERROR_SUCCESS
)
1832 lpService
->Status
.dwServiceType
= dwServiceType
;
1835 if (dwStartType
!= SERVICE_NO_CHANGE
)
1837 /* Set the start value */
1838 dwError
= RegSetValueExW(hServiceKey
,
1842 (LPBYTE
)&dwStartType
,
1844 if (dwError
!= ERROR_SUCCESS
)
1847 lpService
->dwStartType
= dwStartType
;
1850 if (dwErrorControl
!= SERVICE_NO_CHANGE
)
1852 /* Set the error control value */
1853 dwError
= RegSetValueExW(hServiceKey
,
1857 (LPBYTE
)&dwErrorControl
,
1859 if (dwError
!= ERROR_SUCCESS
)
1862 lpService
->dwErrorControl
= dwErrorControl
;
1865 if (lpBinaryPathName
!= NULL
&& *lpBinaryPathName
!= 0)
1867 /* Set the image path */
1868 lpImagePathW
= lpBinaryPathName
;
1870 if (lpService
->Status
.dwServiceType
& SERVICE_DRIVER
)
1872 dwError
= ScmCanonDriverImagePath(lpService
->dwStartType
,
1876 if (dwError
!= ERROR_SUCCESS
)
1880 dwError
= RegSetValueExW(hServiceKey
,
1884 (LPBYTE
)lpImagePathW
,
1885 (wcslen(lpImagePathW
) + 1) * sizeof(WCHAR
));
1887 if (lpImagePathW
!= lpBinaryPathName
)
1888 HeapFree(GetProcessHeap(), 0, lpImagePathW
);
1890 if (dwError
!= ERROR_SUCCESS
)
1894 /* Set the group name */
1895 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
1897 dwError
= RegSetValueExW(hServiceKey
,
1901 (LPBYTE
)lpLoadOrderGroup
,
1902 (wcslen(lpLoadOrderGroup
) + 1) * sizeof(WCHAR
));
1903 if (dwError
!= ERROR_SUCCESS
)
1906 dwError
= ScmSetServiceGroup(lpService
,
1908 if (dwError
!= ERROR_SUCCESS
)
1912 if (lpdwTagId
!= NULL
)
1914 dwError
= ScmAssignNewTag(lpService
);
1915 if (dwError
!= ERROR_SUCCESS
)
1918 dwError
= RegSetValueExW(hServiceKey
,
1922 (LPBYTE
)&lpService
->dwTag
,
1924 if (dwError
!= ERROR_SUCCESS
)
1927 *lpdwTagId
= lpService
->dwTag
;
1930 /* Write dependencies */
1931 if (lpDependencies
!= NULL
&& *lpDependencies
!= 0)
1933 dwError
= ScmWriteDependencies(hServiceKey
,
1934 (LPWSTR
)lpDependencies
,
1936 if (dwError
!= ERROR_SUCCESS
)
1940 if (lpPassword
!= NULL
)
1942 /* FIXME: Write password */
1946 if (hServiceKey
!= NULL
)
1947 RegCloseKey(hServiceKey
);
1949 /* Unlock the service database */
1950 ScmUnlockDatabase();
1952 DPRINT("RChangeServiceConfigW() done (Error %lu)\n", dwError
);
1959 DWORD
RCreateServiceW(
1960 SC_RPC_HANDLE hSCManager
,
1961 LPCWSTR lpServiceName
,
1962 LPCWSTR lpDisplayName
,
1963 DWORD dwDesiredAccess
,
1964 DWORD dwServiceType
,
1966 DWORD dwErrorControl
,
1967 LPCWSTR lpBinaryPathName
,
1968 LPCWSTR lpLoadOrderGroup
,
1970 LPBYTE lpDependencies
,
1972 LPCWSTR lpServiceStartName
,
1975 LPSC_RPC_HANDLE lpServiceHandle
)
1977 PMANAGER_HANDLE hManager
;
1978 DWORD dwError
= ERROR_SUCCESS
;
1979 PSERVICE lpService
= NULL
;
1980 SC_HANDLE hServiceHandle
= NULL
;
1981 LPWSTR lpImagePath
= NULL
;
1982 HKEY hServiceKey
= NULL
;
1983 LPWSTR lpObjectName
;
1985 DPRINT("RCreateServiceW() called\n");
1986 DPRINT("lpServiceName = %S\n", lpServiceName
);
1987 DPRINT("lpDisplayName = %S\n", lpDisplayName
);
1988 DPRINT("dwDesiredAccess = %lx\n", dwDesiredAccess
);
1989 DPRINT("dwServiceType = %lu\n", dwServiceType
);
1990 DPRINT("dwStartType = %lu\n", dwStartType
);
1991 DPRINT("dwErrorControl = %lu\n", dwErrorControl
);
1992 DPRINT("lpBinaryPathName = %S\n", lpBinaryPathName
);
1993 DPRINT("lpLoadOrderGroup = %S\n", lpLoadOrderGroup
);
1994 DPRINT("lpdwTagId = %p\n", lpdwTagId
);
1997 return ERROR_SHUTDOWN_IN_PROGRESS
;
1999 hManager
= ScmGetServiceManagerFromHandle(hSCManager
);
2000 if (hManager
== NULL
)
2002 DPRINT1("Invalid service manager handle!\n");
2003 return ERROR_INVALID_HANDLE
;
2006 /* Check access rights */
2007 if (!RtlAreAllAccessesGranted(hManager
->Handle
.DesiredAccess
,
2008 SC_MANAGER_CREATE_SERVICE
))
2010 DPRINT("Insufficient access rights! 0x%lx\n",
2011 hManager
->Handle
.DesiredAccess
);
2012 return ERROR_ACCESS_DENIED
;
2015 if (wcslen(lpServiceName
) == 0)
2017 return ERROR_INVALID_NAME
;
2020 if (wcslen(lpBinaryPathName
) == 0)
2022 return ERROR_INVALID_PARAMETER
;
2025 /* Check for invalid service type value */
2026 if ((dwServiceType
!= SERVICE_KERNEL_DRIVER
) &&
2027 (dwServiceType
!= SERVICE_FILE_SYSTEM_DRIVER
) &&
2028 ((dwServiceType
& ~SERVICE_INTERACTIVE_PROCESS
) != SERVICE_WIN32_OWN_PROCESS
) &&
2029 ((dwServiceType
& ~SERVICE_INTERACTIVE_PROCESS
) != SERVICE_WIN32_SHARE_PROCESS
))
2030 return ERROR_INVALID_PARAMETER
;
2032 /* Check for invalid start type value */
2033 if ((dwStartType
!= SERVICE_BOOT_START
) &&
2034 (dwStartType
!= SERVICE_SYSTEM_START
) &&
2035 (dwStartType
!= SERVICE_AUTO_START
) &&
2036 (dwStartType
!= SERVICE_DEMAND_START
) &&
2037 (dwStartType
!= SERVICE_DISABLED
))
2038 return ERROR_INVALID_PARAMETER
;
2040 /* Only drivers can be boot start or system start services */
2041 if ((dwStartType
== SERVICE_BOOT_START
) ||
2042 (dwStartType
== SERVICE_SYSTEM_START
))
2044 if ((dwServiceType
!= SERVICE_KERNEL_DRIVER
) &&
2045 (dwServiceType
!= SERVICE_FILE_SYSTEM_DRIVER
))
2046 return ERROR_INVALID_PARAMETER
;
2049 /* Check for invalid error control value */
2050 if ((dwErrorControl
!= SERVICE_ERROR_IGNORE
) &&
2051 (dwErrorControl
!= SERVICE_ERROR_NORMAL
) &&
2052 (dwErrorControl
!= SERVICE_ERROR_SEVERE
) &&
2053 (dwErrorControl
!= SERVICE_ERROR_CRITICAL
))
2054 return ERROR_INVALID_PARAMETER
;
2056 if ((dwServiceType
== (SERVICE_WIN32_OWN_PROCESS
| SERVICE_INTERACTIVE_PROCESS
)) &&
2057 (lpServiceStartName
))
2059 return ERROR_INVALID_PARAMETER
;
2062 if (lpdwTagId
&& (!lpLoadOrderGroup
|| !*lpLoadOrderGroup
))
2064 return ERROR_INVALID_PARAMETER
;
2067 /* Lock the service database exclusively */
2068 ScmLockDatabaseExclusive();
2070 lpService
= ScmGetServiceEntryByName(lpServiceName
);
2073 /* Unlock the service database */
2074 ScmUnlockDatabase();
2076 /* Check if it is marked for deletion */
2077 if (lpService
->bDeleted
)
2078 return ERROR_SERVICE_MARKED_FOR_DELETE
;
2080 /* Return Error exist */
2081 return ERROR_SERVICE_EXISTS
;
2084 if (lpDisplayName
!= NULL
&&
2085 ScmGetServiceEntryByDisplayName(lpDisplayName
) != NULL
)
2087 /* Unlock the service database */
2088 ScmUnlockDatabase();
2090 return ERROR_DUPLICATE_SERVICE_NAME
;
2093 if (dwServiceType
& SERVICE_DRIVER
)
2095 dwError
= ScmCanonDriverImagePath(dwStartType
,
2098 if (dwError
!= ERROR_SUCCESS
)
2103 if (dwStartType
== SERVICE_BOOT_START
||
2104 dwStartType
== SERVICE_SYSTEM_START
)
2106 /* Unlock the service database */
2107 ScmUnlockDatabase();
2109 return ERROR_INVALID_PARAMETER
;
2113 /* Allocate a new service entry */
2114 dwError
= ScmCreateNewServiceRecord(lpServiceName
,
2116 if (dwError
!= ERROR_SUCCESS
)
2119 /* Fill the new service entry */
2120 lpService
->Status
.dwServiceType
= dwServiceType
;
2121 lpService
->dwStartType
= dwStartType
;
2122 lpService
->dwErrorControl
= dwErrorControl
;
2124 /* Fill the display name */
2125 if (lpDisplayName
!= NULL
&&
2126 *lpDisplayName
!= 0 &&
2127 _wcsicmp(lpService
->lpDisplayName
, lpDisplayName
) != 0)
2129 lpService
->lpDisplayName
= HeapAlloc(GetProcessHeap(), 0,
2130 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
2131 if (lpService
->lpDisplayName
== NULL
)
2133 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
2136 wcscpy(lpService
->lpDisplayName
, lpDisplayName
);
2139 /* Assign the service to a group */
2140 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
2142 dwError
= ScmSetServiceGroup(lpService
,
2144 if (dwError
!= ERROR_SUCCESS
)
2148 /* Assign a new tag */
2149 if (lpdwTagId
!= NULL
)
2151 dwError
= ScmAssignNewTag(lpService
);
2152 if (dwError
!= ERROR_SUCCESS
)
2156 /* Write service data to the registry */
2157 /* Create the service key */
2158 dwError
= ScmCreateServiceKey(lpServiceName
,
2161 if (dwError
!= ERROR_SUCCESS
)
2164 /* Set the display name */
2165 if (lpDisplayName
!= NULL
&& *lpDisplayName
!= 0)
2167 RegSetValueExW(hServiceKey
,
2171 (LPBYTE
)lpDisplayName
,
2172 (wcslen(lpDisplayName
) + 1) * sizeof(WCHAR
));
2175 /* Set the service type */
2176 dwError
= RegSetValueExW(hServiceKey
,
2180 (LPBYTE
)&dwServiceType
,
2182 if (dwError
!= ERROR_SUCCESS
)
2185 /* Set the start value */
2186 dwError
= RegSetValueExW(hServiceKey
,
2190 (LPBYTE
)&dwStartType
,
2192 if (dwError
!= ERROR_SUCCESS
)
2195 /* Set the error control value */
2196 dwError
= RegSetValueExW(hServiceKey
,
2200 (LPBYTE
)&dwErrorControl
,
2202 if (dwError
!= ERROR_SUCCESS
)
2205 /* Set the image path */
2206 if (dwServiceType
& SERVICE_WIN32
)
2208 dwError
= RegSetValueExW(hServiceKey
,
2212 (LPBYTE
)lpBinaryPathName
,
2213 (wcslen(lpBinaryPathName
) + 1) * sizeof(WCHAR
));
2214 if (dwError
!= ERROR_SUCCESS
)
2217 else if (dwServiceType
& SERVICE_DRIVER
)
2219 dwError
= RegSetValueExW(hServiceKey
,
2223 (LPBYTE
)lpImagePath
,
2224 (wcslen(lpImagePath
) + 1) * sizeof(WCHAR
));
2225 if (dwError
!= ERROR_SUCCESS
)
2229 /* Set the group name */
2230 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
2232 dwError
= RegSetValueExW(hServiceKey
,
2236 (LPBYTE
)lpLoadOrderGroup
,
2237 (wcslen(lpLoadOrderGroup
) + 1) * sizeof(WCHAR
));
2238 if (dwError
!= ERROR_SUCCESS
)
2242 if (lpdwTagId
!= NULL
)
2244 dwError
= RegSetValueExW(hServiceKey
,
2248 (LPBYTE
)&lpService
->dwTag
,
2250 if (dwError
!= ERROR_SUCCESS
)
2254 /* Write dependencies */
2255 if (lpDependencies
!= NULL
&& *lpDependencies
!= 0)
2257 dwError
= ScmWriteDependencies(hServiceKey
,
2258 (LPCWSTR
)lpDependencies
,
2260 if (dwError
!= ERROR_SUCCESS
)
2264 /* Write service start name */
2265 if (dwServiceType
& SERVICE_WIN32
)
2267 lpObjectName
= (lpServiceStartName
!= NULL
) ? (LPWSTR
)lpServiceStartName
: L
"LocalSystem";
2268 dwError
= RegSetValueExW(hServiceKey
,
2272 (LPBYTE
)lpObjectName
,
2273 (wcslen(lpObjectName
) + 1) * sizeof(WCHAR
));
2274 if (dwError
!= ERROR_SUCCESS
)
2278 if (lpPassword
!= NULL
)
2280 /* FIXME: Write password */
2283 dwError
= ScmCreateServiceHandle(lpService
,
2285 if (dwError
!= ERROR_SUCCESS
)
2288 dwError
= ScmCheckAccess(hServiceHandle
,
2290 if (dwError
!= ERROR_SUCCESS
)
2293 lpService
->dwRefCount
= 1;
2294 DPRINT("CreateService - lpService->dwRefCount %u\n", lpService
->dwRefCount
);
2297 /* Unlock the service database */
2298 ScmUnlockDatabase();
2300 if (hServiceKey
!= NULL
)
2301 RegCloseKey(hServiceKey
);
2303 if (dwError
== ERROR_SUCCESS
)
2305 DPRINT("hService %p\n", hServiceHandle
);
2306 *lpServiceHandle
= (SC_RPC_HANDLE
)hServiceHandle
;
2308 if (lpdwTagId
!= NULL
)
2309 *lpdwTagId
= lpService
->dwTag
;
2313 if (lpService
!= NULL
&&
2314 lpService
->lpServiceName
!= NULL
)
2316 /* Release the display name buffer */
2317 HeapFree(GetProcessHeap(), 0, lpService
->lpDisplayName
);
2322 /* Remove the service handle */
2323 HeapFree(GetProcessHeap(), 0, hServiceHandle
);
2326 if (lpService
!= NULL
)
2328 /* FIXME: remove the service entry */
2332 if (lpImagePath
!= NULL
)
2333 HeapFree(GetProcessHeap(), 0, lpImagePath
);
2335 DPRINT("RCreateServiceW() done (Error %lu)\n", dwError
);
2342 DWORD
REnumDependentServicesW(
2343 SC_RPC_HANDLE hService
,
2344 DWORD dwServiceState
,
2347 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
2348 LPBOUNDED_DWORD_256K lpServicesReturned
)
2350 DWORD dwError
= ERROR_SUCCESS
;
2351 DWORD dwServicesReturned
= 0;
2352 DWORD dwServiceCount
;
2353 HKEY hServicesKey
= NULL
;
2354 PSERVICE_HANDLE hSvc
;
2355 PSERVICE lpService
= NULL
;
2356 PSERVICE
*lpServicesArray
= NULL
;
2357 LPENUM_SERVICE_STATUSW lpServicesPtr
= NULL
;
2360 *pcbBytesNeeded
= 0;
2361 *lpServicesReturned
= 0;
2363 DPRINT("REnumDependentServicesW() called\n");
2365 hSvc
= ScmGetServiceFromHandle(hService
);
2368 DPRINT1("Invalid service handle!\n");
2369 return ERROR_INVALID_HANDLE
;
2372 lpService
= hSvc
->ServiceEntry
;
2374 /* Check access rights */
2375 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
2376 SC_MANAGER_ENUMERATE_SERVICE
))
2378 DPRINT("Insufficient access rights! 0x%lx\n",
2379 hSvc
->Handle
.DesiredAccess
);
2380 return ERROR_ACCESS_DENIED
;
2383 /* Open the Services Reg key */
2384 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
2385 L
"System\\CurrentControlSet\\Services",
2389 if (dwError
!= ERROR_SUCCESS
)
2392 /* First determine the bytes needed and get the number of dependent services */
2393 dwError
= Int_EnumDependentServicesW(hServicesKey
,
2398 &dwServicesReturned
);
2399 if (dwError
!= ERROR_SUCCESS
)
2402 /* If buffer size is less than the bytes needed or pointer is null */
2403 if ((!lpServices
) || (cbBufSize
< *pcbBytesNeeded
))
2405 dwError
= ERROR_MORE_DATA
;
2409 /* Allocate memory for array of service pointers */
2410 lpServicesArray
= HeapAlloc(GetProcessHeap(),
2412 (dwServicesReturned
+ 1) * sizeof(PSERVICE
));
2413 if (!lpServicesArray
)
2415 DPRINT1("Could not allocate a buffer!!\n");
2416 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
2420 dwServicesReturned
= 0;
2421 *pcbBytesNeeded
= 0;
2423 dwError
= Int_EnumDependentServicesW(hServicesKey
,
2428 &dwServicesReturned
);
2429 if (dwError
!= ERROR_SUCCESS
)
2434 lpServicesPtr
= (LPENUM_SERVICE_STATUSW
) lpServices
;
2435 lpStr
= (LPWSTR
)(lpServices
+ (dwServicesReturned
* sizeof(ENUM_SERVICE_STATUSW
)));
2437 /* Copy EnumDepenedentService to Buffer */
2438 for (dwServiceCount
= 0; dwServiceCount
< dwServicesReturned
; dwServiceCount
++)
2440 lpService
= lpServicesArray
[dwServiceCount
];
2442 /* Copy status info */
2443 memcpy(&lpServicesPtr
->ServiceStatus
,
2445 sizeof(SERVICE_STATUS
));
2447 /* Copy display name */
2448 wcscpy(lpStr
, lpService
->lpDisplayName
);
2449 lpServicesPtr
->lpDisplayName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServices
);
2450 lpStr
+= (wcslen(lpService
->lpDisplayName
) + 1);
2452 /* Copy service name */
2453 wcscpy(lpStr
, lpService
->lpServiceName
);
2454 lpServicesPtr
->lpServiceName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServices
);
2455 lpStr
+= (wcslen(lpService
->lpServiceName
) + 1);
2460 *lpServicesReturned
= dwServicesReturned
;
2463 if (lpServicesArray
!= NULL
)
2464 HeapFree(GetProcessHeap(), 0, lpServicesArray
);
2466 RegCloseKey(hServicesKey
);
2468 DPRINT("REnumDependentServicesW() done (Error %lu)\n", dwError
);
2475 DWORD
REnumServicesStatusW(
2476 SC_RPC_HANDLE hSCManager
,
2477 DWORD dwServiceType
,
2478 DWORD dwServiceState
,
2481 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
2482 LPBOUNDED_DWORD_256K lpServicesReturned
,
2483 LPBOUNDED_DWORD_256K lpResumeHandle
)
2485 PMANAGER_HANDLE hManager
;
2487 DWORD dwError
= ERROR_SUCCESS
;
2488 PLIST_ENTRY ServiceEntry
;
2489 PSERVICE CurrentService
;
2491 DWORD dwRequiredSize
;
2492 DWORD dwServiceCount
;
2494 DWORD dwLastResumeCount
= 0;
2495 LPENUM_SERVICE_STATUSW lpStatusPtr
;
2498 DPRINT("REnumServicesStatusW() called\n");
2501 return ERROR_SHUTDOWN_IN_PROGRESS
;
2503 hManager
= ScmGetServiceManagerFromHandle(hSCManager
);
2504 if (hManager
== NULL
)
2506 DPRINT1("Invalid service manager handle!\n");
2507 return ERROR_INVALID_HANDLE
;
2511 *pcbBytesNeeded
= 0;
2512 *lpServicesReturned
= 0;
2514 if ((dwServiceType
!=SERVICE_DRIVER
) && (dwServiceType
!=SERVICE_WIN32
))
2516 DPRINT("Not a valid Service Type!\n");
2517 return ERROR_INVALID_PARAMETER
;
2520 if ((dwServiceState
<SERVICE_ACTIVE
) || (dwServiceState
>SERVICE_STATE_ALL
))
2522 DPRINT("Not a valid Service State!\n");
2523 return ERROR_INVALID_PARAMETER
;
2526 /* Check access rights */
2527 if (!RtlAreAllAccessesGranted(hManager
->Handle
.DesiredAccess
,
2528 SC_MANAGER_ENUMERATE_SERVICE
))
2530 DPRINT("Insufficient access rights! 0x%lx\n",
2531 hManager
->Handle
.DesiredAccess
);
2532 return ERROR_ACCESS_DENIED
;
2536 dwLastResumeCount
= *lpResumeHandle
;
2538 /* Lock the service database shared */
2539 ScmLockDatabaseShared();
2541 lpService
= ScmGetServiceEntryByResumeCount(dwLastResumeCount
);
2542 if (lpService
== NULL
)
2544 dwError
= ERROR_SUCCESS
;
2551 for (ServiceEntry
= &lpService
->ServiceListEntry
;
2552 ServiceEntry
!= &ServiceListHead
;
2553 ServiceEntry
= ServiceEntry
->Flink
)
2555 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
2559 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
2562 dwState
= SERVICE_ACTIVE
;
2563 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
2564 dwState
= SERVICE_INACTIVE
;
2566 if ((dwState
& dwServiceState
) == 0)
2569 dwSize
= sizeof(ENUM_SERVICE_STATUSW
) +
2570 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
2571 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
2573 if (dwRequiredSize
+ dwSize
> dwBufSize
)
2575 DPRINT("Service name: %S no fit\n", CurrentService
->lpServiceName
);
2579 DPRINT("Service name: %S fit\n", CurrentService
->lpServiceName
);
2580 dwRequiredSize
+= dwSize
;
2582 dwLastResumeCount
= CurrentService
->dwResumeCount
;
2585 DPRINT("dwRequiredSize: %lu\n", dwRequiredSize
);
2586 DPRINT("dwServiceCount: %lu\n", dwServiceCount
);
2589 ServiceEntry
!= &ServiceListHead
;
2590 ServiceEntry
= ServiceEntry
->Flink
)
2592 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
2596 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
2599 dwState
= SERVICE_ACTIVE
;
2600 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
2601 dwState
= SERVICE_INACTIVE
;
2603 if ((dwState
& dwServiceState
) == 0)
2606 dwRequiredSize
+= (sizeof(ENUM_SERVICE_STATUSW
) +
2607 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
2608 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
)));
2610 dwError
= ERROR_MORE_DATA
;
2613 DPRINT("*pcbBytesNeeded: %lu\n", dwRequiredSize
);
2616 *lpResumeHandle
= dwLastResumeCount
;
2618 *lpServicesReturned
= dwServiceCount
;
2619 *pcbBytesNeeded
= dwRequiredSize
;
2621 lpStatusPtr
= (LPENUM_SERVICE_STATUSW
)lpBuffer
;
2622 lpStringPtr
= (LPWSTR
)((ULONG_PTR
)lpBuffer
+
2623 dwServiceCount
* sizeof(ENUM_SERVICE_STATUSW
));
2626 for (ServiceEntry
= &lpService
->ServiceListEntry
;
2627 ServiceEntry
!= &ServiceListHead
;
2628 ServiceEntry
= ServiceEntry
->Flink
)
2630 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
2634 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
2637 dwState
= SERVICE_ACTIVE
;
2638 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
2639 dwState
= SERVICE_INACTIVE
;
2641 if ((dwState
& dwServiceState
) == 0)
2644 dwSize
= sizeof(ENUM_SERVICE_STATUSW
) +
2645 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
2646 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
2648 if (dwRequiredSize
+ dwSize
> dwBufSize
)
2651 /* Copy the service name */
2652 wcscpy(lpStringPtr
, CurrentService
->lpServiceName
);
2653 lpStatusPtr
->lpServiceName
= (LPWSTR
)((ULONG_PTR
)lpStringPtr
- (ULONG_PTR
)lpBuffer
);
2654 lpStringPtr
+= (wcslen(CurrentService
->lpServiceName
) + 1);
2656 /* Copy the display name */
2657 wcscpy(lpStringPtr
, CurrentService
->lpDisplayName
);
2658 lpStatusPtr
->lpDisplayName
= (LPWSTR
)((ULONG_PTR
)lpStringPtr
- (ULONG_PTR
)lpBuffer
);
2659 lpStringPtr
+= (wcslen(CurrentService
->lpDisplayName
) + 1);
2661 /* Copy the status information */
2662 memcpy(&lpStatusPtr
->ServiceStatus
,
2663 &CurrentService
->Status
,
2664 sizeof(SERVICE_STATUS
));
2667 dwRequiredSize
+= dwSize
;
2672 *pcbBytesNeeded
= 0;
2673 if (lpResumeHandle
) *lpResumeHandle
= 0;
2677 /* Unlock the service database */
2678 ScmUnlockDatabase();
2680 DPRINT("REnumServicesStatusW() done (Error %lu)\n", dwError
);
2687 DWORD
ROpenSCManagerW(
2688 LPWSTR lpMachineName
,
2689 LPWSTR lpDatabaseName
,
2690 DWORD dwDesiredAccess
,
2691 LPSC_RPC_HANDLE lpScHandle
)
2696 DPRINT("ROpenSCManagerW() called\n");
2697 DPRINT("lpMachineName = %p\n", lpMachineName
);
2698 DPRINT("lpMachineName: %S\n", lpMachineName
);
2699 DPRINT("lpDataBaseName = %p\n", lpDatabaseName
);
2700 DPRINT("lpDataBaseName: %S\n", lpDatabaseName
);
2701 DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess
);
2704 return ERROR_SHUTDOWN_IN_PROGRESS
;
2707 return ERROR_INVALID_PARAMETER
;
2709 dwError
= ScmCreateManagerHandle(lpDatabaseName
,
2711 if (dwError
!= ERROR_SUCCESS
)
2713 DPRINT("ScmCreateManagerHandle() failed (Error %lu)\n", dwError
);
2717 /* Check the desired access */
2718 dwError
= ScmCheckAccess(hHandle
,
2719 dwDesiredAccess
| SC_MANAGER_CONNECT
);
2720 if (dwError
!= ERROR_SUCCESS
)
2722 DPRINT("ScmCheckAccess() failed (Error %lu)\n", dwError
);
2723 HeapFree(GetProcessHeap(), 0, hHandle
);
2727 *lpScHandle
= (SC_RPC_HANDLE
)hHandle
;
2728 DPRINT("*hScm = %p\n", *lpScHandle
);
2730 DPRINT("ROpenSCManagerW() done\n");
2732 return ERROR_SUCCESS
;
2737 DWORD
ROpenServiceW(
2738 SC_RPC_HANDLE hSCManager
,
2739 LPWSTR lpServiceName
,
2740 DWORD dwDesiredAccess
,
2741 LPSC_RPC_HANDLE lpServiceHandle
)
2744 PMANAGER_HANDLE hManager
;
2746 DWORD dwError
= ERROR_SUCCESS
;
2748 DPRINT("ROpenServiceW() called\n");
2749 DPRINT("hSCManager = %p\n", hSCManager
);
2750 DPRINT("lpServiceName = %p\n", lpServiceName
);
2751 DPRINT("lpServiceName: %S\n", lpServiceName
);
2752 DPRINT("dwDesiredAccess = %x\n", dwDesiredAccess
);
2755 return ERROR_SHUTDOWN_IN_PROGRESS
;
2757 hManager
= ScmGetServiceManagerFromHandle(hSCManager
);
2758 if (hManager
== NULL
)
2760 DPRINT1("Invalid service manager handle!\n");
2761 return ERROR_INVALID_HANDLE
;
2764 if (!lpServiceHandle
)
2765 return ERROR_INVALID_PARAMETER
;
2768 return ERROR_INVALID_ADDRESS
;
2770 /* Lock the service database exclusive */
2771 ScmLockDatabaseExclusive();
2773 /* Get service database entry */
2774 lpService
= ScmGetServiceEntryByName(lpServiceName
);
2775 if (lpService
== NULL
)
2777 DPRINT("Could not find a service!\n");
2778 dwError
= ERROR_SERVICE_DOES_NOT_EXIST
;
2782 /* Create a service handle */
2783 dwError
= ScmCreateServiceHandle(lpService
,
2785 if (dwError
!= ERROR_SUCCESS
)
2787 DPRINT("ScmCreateServiceHandle() failed (Error %lu)\n", dwError
);
2791 /* Check the desired access */
2792 dwError
= ScmCheckAccess(hHandle
,
2794 if (dwError
!= ERROR_SUCCESS
)
2796 DPRINT("ScmCheckAccess() failed (Error %lu)\n", dwError
);
2797 HeapFree(GetProcessHeap(), 0, hHandle
);
2801 lpService
->dwRefCount
++;
2802 DPRINT("OpenService - lpService->dwRefCount %u\n",lpService
->dwRefCount
);
2804 *lpServiceHandle
= (SC_RPC_HANDLE
)hHandle
;
2805 DPRINT("*hService = %p\n", *lpServiceHandle
);
2808 /* Unlock the service database */
2809 ScmUnlockDatabase();
2811 DPRINT("ROpenServiceW() done\n");
2818 DWORD
RQueryServiceConfigW(
2819 SC_RPC_HANDLE hService
,
2820 LPBYTE lpBuf
, //LPQUERY_SERVICE_CONFIGW lpServiceConfig,
2822 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
2824 LPQUERY_SERVICE_CONFIGW lpServiceConfig
= (LPQUERY_SERVICE_CONFIGW
)lpBuf
;
2825 DWORD dwError
= ERROR_SUCCESS
;
2826 PSERVICE_HANDLE hSvc
;
2827 PSERVICE lpService
= NULL
;
2828 HKEY hServiceKey
= NULL
;
2829 LPWSTR lpImagePath
= NULL
;
2830 LPWSTR lpServiceStartName
= NULL
;
2831 LPWSTR lpDependencies
= NULL
;
2832 DWORD dwDependenciesLength
= 0;
2833 DWORD dwRequiredSize
;
2834 LPQUERY_SERVICE_CONFIGW lpConfig
= NULL
;
2835 WCHAR lpEmptyString
[] = {0,0};
2838 DPRINT("RQueryServiceConfigW() called\n");
2841 return ERROR_SHUTDOWN_IN_PROGRESS
;
2843 hSvc
= ScmGetServiceFromHandle(hService
);
2846 DPRINT1("Invalid service handle!\n");
2847 return ERROR_INVALID_HANDLE
;
2850 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
2851 SERVICE_QUERY_CONFIG
))
2853 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
2854 return ERROR_ACCESS_DENIED
;
2857 lpService
= hSvc
->ServiceEntry
;
2858 if (lpService
== NULL
)
2860 DPRINT("lpService == NULL!\n");
2861 return ERROR_INVALID_HANDLE
;
2864 /* Lock the service database shared */
2865 ScmLockDatabaseShared();
2867 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
2870 if (dwError
!= ERROR_SUCCESS
)
2873 /* Read the image path */
2874 dwError
= ScmReadString(hServiceKey
,
2877 if (dwError
!= ERROR_SUCCESS
)
2880 /* Read the service start name */
2881 ScmReadString(hServiceKey
,
2883 &lpServiceStartName
);
2885 /* Read the dependencies */
2886 ScmReadDependencies(hServiceKey
,
2888 &dwDependenciesLength
);
2890 dwRequiredSize
= sizeof(QUERY_SERVICE_CONFIGW
);
2892 if (lpImagePath
!= NULL
)
2893 dwRequiredSize
+= ((wcslen(lpImagePath
) + 1) * sizeof(WCHAR
));
2895 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2897 if (lpService
->lpGroup
!= NULL
)
2898 dwRequiredSize
+= ((wcslen(lpService
->lpGroup
->lpGroupName
) + 1) * sizeof(WCHAR
));
2900 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2902 if (lpDependencies
!= NULL
)
2903 dwRequiredSize
+= dwDependenciesLength
* sizeof(WCHAR
);
2905 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2907 if (lpServiceStartName
!= NULL
)
2908 dwRequiredSize
+= ((wcslen(lpServiceStartName
) + 1) * sizeof(WCHAR
));
2910 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2912 if (lpService
->lpDisplayName
!= NULL
)
2913 dwRequiredSize
+= ((wcslen(lpService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
2915 dwRequiredSize
+= 2 * sizeof(WCHAR
);
2917 if (lpServiceConfig
== NULL
|| cbBufSize
< dwRequiredSize
)
2919 dwError
= ERROR_INSUFFICIENT_BUFFER
;
2923 lpConfig
= (LPQUERY_SERVICE_CONFIGW
)lpServiceConfig
;
2924 lpConfig
->dwServiceType
= lpService
->Status
.dwServiceType
;
2925 lpConfig
->dwStartType
= lpService
->dwStartType
;
2926 lpConfig
->dwErrorControl
= lpService
->dwErrorControl
;
2927 lpConfig
->dwTagId
= lpService
->dwTag
;
2929 lpStr
= (LPWSTR
)(lpConfig
+ 1);
2931 /* Append the image path */
2932 if (lpImagePath
!= NULL
)
2934 wcscpy(lpStr
, lpImagePath
);
2938 wcscpy(lpStr
, lpEmptyString
);
2941 lpConfig
->lpBinaryPathName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2942 lpStr
+= (wcslen(lpStr
) + 1);
2944 /* Append the group name */
2945 if (lpService
->lpGroup
!= NULL
)
2947 wcscpy(lpStr
, lpService
->lpGroup
->lpGroupName
);
2951 wcscpy(lpStr
, lpEmptyString
);
2954 lpConfig
->lpLoadOrderGroup
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2955 lpStr
+= (wcslen(lpStr
) + 1);
2957 /* Append Dependencies */
2958 if (lpDependencies
!= NULL
)
2962 dwDependenciesLength
* sizeof(WCHAR
));
2966 wcscpy(lpStr
, lpEmptyString
);
2969 lpConfig
->lpDependencies
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2970 if (lpDependencies
!= NULL
)
2971 lpStr
+= dwDependenciesLength
* sizeof(WCHAR
);
2973 lpStr
+= (wcslen(lpStr
) + 1);
2975 /* Append the service start name */
2976 if (lpServiceStartName
!= NULL
)
2978 wcscpy(lpStr
, lpServiceStartName
);
2982 wcscpy(lpStr
, lpEmptyString
);
2985 lpConfig
->lpServiceStartName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
2986 lpStr
+= (wcslen(lpStr
) + 1);
2988 /* Append the display name */
2989 if (lpService
->lpDisplayName
!= NULL
)
2991 wcscpy(lpStr
, lpService
->lpDisplayName
);
2995 wcscpy(lpStr
, lpEmptyString
);
2998 lpConfig
->lpDisplayName
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
3001 if (pcbBytesNeeded
!= NULL
)
3002 *pcbBytesNeeded
= dwRequiredSize
;
3005 /* Unlock the service database */
3006 ScmUnlockDatabase();
3008 if (lpImagePath
!= NULL
)
3009 HeapFree(GetProcessHeap(), 0, lpImagePath
);
3011 if (lpServiceStartName
!= NULL
)
3012 HeapFree(GetProcessHeap(), 0, lpServiceStartName
);
3014 if (lpDependencies
!= NULL
)
3015 HeapFree(GetProcessHeap(), 0, lpDependencies
);
3017 if (hServiceKey
!= NULL
)
3018 RegCloseKey(hServiceKey
);
3020 DPRINT("RQueryServiceConfigW() done\n");
3027 DWORD
RQueryServiceLockStatusW(
3028 SC_RPC_HANDLE hSCManager
,
3029 LPQUERY_SERVICE_LOCK_STATUSW lpLockStatus
,
3031 LPBOUNDED_DWORD_4K pcbBytesNeeded
)
3034 return ERROR_CALL_NOT_IMPLEMENTED
;
3039 DWORD
RStartServiceW(
3040 SC_RPC_HANDLE hService
,
3042 LPSTRING_PTRSW argv
)
3044 DWORD dwError
= ERROR_SUCCESS
;
3045 PSERVICE_HANDLE hSvc
;
3046 PSERVICE lpService
= NULL
;
3049 DPRINT("RStartServiceW(%p %lu %p) called\n", hService
, argc
, argv
);
3050 DPRINT(" argc: %lu\n", argc
);
3053 for (i
= 0; i
< argc
; i
++)
3055 DPRINT(" argv[%lu]: %S\n", i
, argv
[i
]);
3060 return ERROR_SHUTDOWN_IN_PROGRESS
;
3062 hSvc
= ScmGetServiceFromHandle(hService
);
3065 DPRINT1("Invalid service handle!\n");
3066 return ERROR_INVALID_HANDLE
;
3069 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
3072 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
3073 return ERROR_ACCESS_DENIED
;
3076 lpService
= hSvc
->ServiceEntry
;
3077 if (lpService
== NULL
)
3079 DPRINT("lpService == NULL!\n");
3080 return ERROR_INVALID_HANDLE
;
3083 if (lpService
->dwStartType
== SERVICE_DISABLED
)
3084 return ERROR_SERVICE_DISABLED
;
3086 if (lpService
->bDeleted
)
3087 return ERROR_SERVICE_MARKED_FOR_DELETE
;
3089 /* Start the service */
3090 dwError
= ScmStartService(lpService
, argc
, (LPWSTR
*)argv
);
3097 DWORD
RGetServiceDisplayNameW(
3098 SC_RPC_HANDLE hSCManager
,
3099 LPCWSTR lpServiceName
,
3100 LPWSTR lpDisplayName
,
3103 // PMANAGER_HANDLE hManager;
3108 DPRINT("RGetServiceDisplayNameW() called\n");
3109 DPRINT("hSCManager = %p\n", hSCManager
);
3110 DPRINT("lpServiceName: %S\n", lpServiceName
);
3111 DPRINT("lpDisplayName: %p\n", lpDisplayName
);
3112 DPRINT("*lpcchBuffer: %lu\n", *lpcchBuffer
);
3114 // hManager = (PMANAGER_HANDLE)hSCManager;
3115 // if (hManager->Handle.Tag != MANAGER_TAG)
3117 // DPRINT("Invalid manager handle!\n");
3118 // return ERROR_INVALID_HANDLE;
3121 /* Get service database entry */
3122 lpService
= ScmGetServiceEntryByName(lpServiceName
);
3123 if (lpService
== NULL
)
3125 DPRINT("Could not find a service!\n");
3127 /* If the service could not be found and lpcchBuffer is less than 2, windows
3128 puts null in lpDisplayName and puts 2 in lpcchBuffer */
3129 if (*lpcchBuffer
< 2)
3132 if (lpDisplayName
!= NULL
)
3134 *lpDisplayName
= '\0';
3138 return ERROR_SERVICE_DOES_NOT_EXIST
;
3141 if (!lpService
->lpDisplayName
)
3143 dwLength
= wcslen(lpService
->lpServiceName
);
3145 if (lpDisplayName
!= NULL
&&
3146 *lpcchBuffer
> dwLength
)
3148 wcscpy(lpDisplayName
, lpService
->lpServiceName
);
3153 dwLength
= wcslen(lpService
->lpDisplayName
);
3155 if (lpDisplayName
!= NULL
&&
3156 *lpcchBuffer
> dwLength
)
3158 wcscpy(lpDisplayName
, lpService
->lpDisplayName
);
3162 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
3164 *lpcchBuffer
= dwLength
;
3171 DWORD
RGetServiceKeyNameW(
3172 SC_RPC_HANDLE hSCManager
,
3173 LPCWSTR lpDisplayName
,
3174 LPWSTR lpServiceName
,
3177 // PMANAGER_HANDLE hManager;
3182 DPRINT("RGetServiceKeyNameW() called\n");
3183 DPRINT("hSCManager = %p\n", hSCManager
);
3184 DPRINT("lpDisplayName: %S\n", lpDisplayName
);
3185 DPRINT("lpServiceName: %p\n", lpServiceName
);
3186 DPRINT("*lpcchBuffer: %lu\n", *lpcchBuffer
);
3188 // hManager = (PMANAGER_HANDLE)hSCManager;
3189 // if (hManager->Handle.Tag != MANAGER_TAG)
3191 // DPRINT("Invalid manager handle!\n");
3192 // return ERROR_INVALID_HANDLE;
3195 /* Get service database entry */
3196 lpService
= ScmGetServiceEntryByDisplayName(lpDisplayName
);
3197 if (lpService
== NULL
)
3199 DPRINT("Could not find a service!\n");
3201 /* If the service could not be found and lpcchBuffer is less than 2, windows
3202 puts null in lpDisplayName and puts 2 in lpcchBuffer */
3203 if (*lpcchBuffer
< 2)
3206 if (lpServiceName
!= NULL
)
3208 *lpServiceName
= '\0';
3212 return ERROR_SERVICE_DOES_NOT_EXIST
;
3215 dwLength
= wcslen(lpService
->lpServiceName
);
3217 if (lpServiceName
!= NULL
&&
3218 *lpcchBuffer
> dwLength
)
3220 wcscpy(lpServiceName
, lpService
->lpServiceName
);
3221 *lpcchBuffer
= dwLength
;
3222 return ERROR_SUCCESS
;
3225 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
3227 *lpcchBuffer
= dwLength
;
3234 DWORD
RI_ScSetServiceBitsA(
3235 RPC_SERVICE_STATUS_HANDLE hServiceStatus
,
3236 DWORD dwServiceBits
,
3238 int bUpdateImmediately
,
3242 return ERROR_CALL_NOT_IMPLEMENTED
;
3247 DWORD
RChangeServiceConfigA(
3248 SC_RPC_HANDLE hService
,
3249 DWORD dwServiceType
,
3251 DWORD dwErrorControl
,
3252 LPSTR lpBinaryPathName
,
3253 LPSTR lpLoadOrderGroup
,
3255 LPSTR lpDependencies
,
3257 LPSTR lpServiceStartName
,
3260 LPSTR lpDisplayName
)
3262 DWORD dwError
= ERROR_SUCCESS
;
3263 PSERVICE_HANDLE hSvc
;
3264 PSERVICE lpService
= NULL
;
3265 HKEY hServiceKey
= NULL
;
3266 LPWSTR lpDisplayNameW
= NULL
;
3267 LPWSTR lpBinaryPathNameW
= NULL
;
3268 LPWSTR lpCanonicalImagePathW
= NULL
;
3269 LPWSTR lpLoadOrderGroupW
= NULL
;
3270 LPWSTR lpDependenciesW
= NULL
;
3271 // LPWSTR lpPasswordW = NULL;
3273 DPRINT("RChangeServiceConfigA() called\n");
3274 DPRINT("dwServiceType = %lu\n", dwServiceType
);
3275 DPRINT("dwStartType = %lu\n", dwStartType
);
3276 DPRINT("dwErrorControl = %lu\n", dwErrorControl
);
3277 DPRINT("lpBinaryPathName = %s\n", lpBinaryPathName
);
3278 DPRINT("lpLoadOrderGroup = %s\n", lpLoadOrderGroup
);
3279 DPRINT("lpDisplayName = %s\n", lpDisplayName
);
3282 return ERROR_SHUTDOWN_IN_PROGRESS
;
3284 hSvc
= ScmGetServiceFromHandle(hService
);
3287 DPRINT1("Invalid service handle!\n");
3288 return ERROR_INVALID_HANDLE
;
3291 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
3292 SERVICE_CHANGE_CONFIG
))
3294 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
3295 return ERROR_ACCESS_DENIED
;
3298 lpService
= hSvc
->ServiceEntry
;
3299 if (lpService
== NULL
)
3301 DPRINT("lpService == NULL!\n");
3302 return ERROR_INVALID_HANDLE
;
3305 /* Lock the service database exclusively */
3306 ScmLockDatabaseExclusive();
3308 if (lpService
->bDeleted
)
3310 DPRINT("The service has already been marked for delete!\n");
3311 dwError
= ERROR_SERVICE_MARKED_FOR_DELETE
;
3315 /* Open the service key */
3316 dwError
= ScmOpenServiceKey(lpService
->szServiceName
,
3319 if (dwError
!= ERROR_SUCCESS
)
3322 /* Write service data to the registry */
3324 if (lpDisplayName
!= NULL
&& *lpDisplayName
!= 0)
3326 /* Set the display name */
3327 lpDisplayNameW
= HeapAlloc(GetProcessHeap(),
3329 (strlen(lpDisplayName
) + 1) * sizeof(WCHAR
));
3330 if (lpDisplayNameW
== NULL
)
3332 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
3336 MultiByteToWideChar(CP_ACP
,
3341 strlen(lpDisplayName
) + 1);
3343 RegSetValueExW(hServiceKey
,
3347 (LPBYTE
)lpDisplayNameW
,
3348 (wcslen(lpDisplayNameW
) + 1) * sizeof(WCHAR
));
3350 /* Update lpService->lpDisplayName */
3351 if (lpService
->lpDisplayName
)
3352 HeapFree(GetProcessHeap(), 0, lpService
->lpDisplayName
);
3354 lpService
->lpDisplayName
= lpDisplayNameW
;
3357 if (dwServiceType
!= SERVICE_NO_CHANGE
)
3359 /* Set the service type */
3360 dwError
= RegSetValueExW(hServiceKey
,
3364 (LPBYTE
)&dwServiceType
,
3366 if (dwError
!= ERROR_SUCCESS
)
3369 lpService
->Status
.dwServiceType
= dwServiceType
;
3372 if (dwStartType
!= SERVICE_NO_CHANGE
)
3374 /* Set the start value */
3375 dwError
= RegSetValueExW(hServiceKey
,
3379 (LPBYTE
)&dwStartType
,
3381 if (dwError
!= ERROR_SUCCESS
)
3384 lpService
->dwStartType
= dwStartType
;
3387 if (dwErrorControl
!= SERVICE_NO_CHANGE
)
3389 /* Set the error control value */
3390 dwError
= RegSetValueExW(hServiceKey
,
3394 (LPBYTE
)&dwErrorControl
,
3396 if (dwError
!= ERROR_SUCCESS
)
3399 lpService
->dwErrorControl
= dwErrorControl
;
3402 if (lpBinaryPathName
!= NULL
&& *lpBinaryPathName
!= 0)
3404 /* Set the image path */
3405 lpBinaryPathNameW
= HeapAlloc(GetProcessHeap(),
3407 (strlen(lpBinaryPathName
) + 1) * sizeof(WCHAR
));
3408 if (lpBinaryPathNameW
== NULL
)
3410 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
3414 MultiByteToWideChar(CP_ACP
,
3419 strlen(lpBinaryPathName
) + 1);
3421 if (lpService
->Status
.dwServiceType
& SERVICE_DRIVER
)
3423 dwError
= ScmCanonDriverImagePath(lpService
->dwStartType
,
3425 &lpCanonicalImagePathW
);
3427 HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW
);
3429 if (dwError
!= ERROR_SUCCESS
)
3432 lpBinaryPathNameW
= lpCanonicalImagePathW
;
3435 dwError
= RegSetValueExW(hServiceKey
,
3439 (LPBYTE
)lpBinaryPathNameW
,
3440 (wcslen(lpBinaryPathNameW
) + 1) * sizeof(WCHAR
));
3442 HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW
);
3444 if (dwError
!= ERROR_SUCCESS
)
3448 /* Set the group name */
3449 if (lpLoadOrderGroup
!= NULL
&& *lpLoadOrderGroup
!= 0)
3451 lpLoadOrderGroupW
= HeapAlloc(GetProcessHeap(),
3453 (strlen(lpLoadOrderGroup
) + 1) * sizeof(WCHAR
));
3454 if (lpLoadOrderGroupW
== NULL
)
3456 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
3460 MultiByteToWideChar(CP_ACP
,
3465 strlen(lpLoadOrderGroup
) + 1);
3467 dwError
= RegSetValueExW(hServiceKey
,
3471 (LPBYTE
)lpLoadOrderGroupW
,
3472 (wcslen(lpLoadOrderGroupW
) + 1) * sizeof(WCHAR
));
3473 if (dwError
!= ERROR_SUCCESS
)
3475 HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW
);
3479 dwError
= ScmSetServiceGroup(lpService
,
3482 HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW
);
3484 if (dwError
!= ERROR_SUCCESS
)
3488 if (lpdwTagId
!= NULL
)
3490 dwError
= ScmAssignNewTag(lpService
);
3491 if (dwError
!= ERROR_SUCCESS
)
3494 dwError
= RegSetValueExW(hServiceKey
,
3498 (LPBYTE
)&lpService
->dwTag
,
3500 if (dwError
!= ERROR_SUCCESS
)
3503 *lpdwTagId
= lpService
->dwTag
;
3506 /* Write dependencies */
3507 if (lpDependencies
!= NULL
&& *lpDependencies
!= 0)
3509 lpDependenciesW
= HeapAlloc(GetProcessHeap(),
3511 (strlen(lpDependencies
) + 1) * sizeof(WCHAR
));
3512 if (lpDependenciesW
== NULL
)
3514 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
3518 MultiByteToWideChar(CP_ACP
,
3523 strlen(lpDependencies
) + 1);
3525 dwError
= ScmWriteDependencies(hServiceKey
,
3526 (LPWSTR
)lpDependenciesW
,
3529 HeapFree(GetProcessHeap(), 0, lpDependenciesW
);
3532 if (lpPassword
!= NULL
)
3534 /* FIXME: Write password */
3538 /* Unlock the service database */
3539 ScmUnlockDatabase();
3541 if (hServiceKey
!= NULL
)
3542 RegCloseKey(hServiceKey
);
3544 DPRINT("RChangeServiceConfigA() done (Error %lu)\n", dwError
);
3551 DWORD
RCreateServiceA(
3552 SC_RPC_HANDLE hSCManager
,
3553 LPSTR lpServiceName
,
3554 LPSTR lpDisplayName
,
3555 DWORD dwDesiredAccess
,
3556 DWORD dwServiceType
,
3558 DWORD dwErrorControl
,
3559 LPSTR lpBinaryPathName
,
3560 LPSTR lpLoadOrderGroup
,
3562 LPBYTE lpDependencies
,
3564 LPSTR lpServiceStartName
,
3567 LPSC_RPC_HANDLE lpServiceHandle
)
3569 DWORD dwError
= ERROR_SUCCESS
;
3570 LPWSTR lpServiceNameW
= NULL
;
3571 LPWSTR lpDisplayNameW
= NULL
;
3572 LPWSTR lpBinaryPathNameW
= NULL
;
3573 LPWSTR lpLoadOrderGroupW
= NULL
;
3574 LPWSTR lpDependenciesW
= NULL
;
3575 LPWSTR lpServiceStartNameW
= NULL
;
3576 DWORD dwDependenciesLength
= 0;
3583 len
= MultiByteToWideChar(CP_ACP
, 0, lpServiceName
, -1, NULL
, 0);
3584 lpServiceNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3585 if (!lpServiceNameW
)
3587 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3590 MultiByteToWideChar(CP_ACP
, 0, lpServiceName
, -1, lpServiceNameW
, len
);
3595 len
= MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, NULL
, 0);
3596 lpDisplayNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3597 if (!lpDisplayNameW
)
3599 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3602 MultiByteToWideChar(CP_ACP
, 0, lpDisplayName
, -1, lpDisplayNameW
, len
);
3605 if (lpBinaryPathName
)
3607 len
= MultiByteToWideChar(CP_ACP
, 0, lpBinaryPathName
, -1, NULL
, 0);
3608 lpBinaryPathNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3609 if (!lpBinaryPathNameW
)
3611 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3614 MultiByteToWideChar(CP_ACP
, 0, lpBinaryPathName
, -1, lpBinaryPathNameW
, len
);
3617 if (lpLoadOrderGroup
)
3619 len
= MultiByteToWideChar(CP_ACP
, 0, lpLoadOrderGroup
, -1, NULL
, 0);
3620 lpLoadOrderGroupW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3621 if (!lpLoadOrderGroupW
)
3623 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3626 MultiByteToWideChar(CP_ACP
, 0, lpLoadOrderGroup
, -1, lpLoadOrderGroupW
, len
);
3631 lpStr
= (LPCSTR
)lpDependencies
;
3634 dwLength
= strlen(lpStr
) + 1;
3635 dwDependenciesLength
+= dwLength
;
3636 lpStr
= lpStr
+ dwLength
;
3638 dwDependenciesLength
++;
3640 lpDependenciesW
= HeapAlloc(GetProcessHeap(), 0, dwDependenciesLength
* sizeof(WCHAR
));
3641 if (!lpDependenciesW
)
3643 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3646 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)lpDependencies
, dwDependenciesLength
, lpDependenciesW
, dwDependenciesLength
);
3649 if (lpServiceStartName
)
3651 len
= MultiByteToWideChar(CP_ACP
, 0, lpServiceStartName
, -1, NULL
, 0);
3652 lpServiceStartNameW
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
3653 if (!lpServiceStartNameW
)
3655 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3658 MultiByteToWideChar(CP_ACP
, 0, lpServiceStartName
, -1, lpServiceStartNameW
, len
);
3661 dwError
= RCreateServiceW(hSCManager
,
3671 (LPBYTE
)lpDependenciesW
,
3672 dwDependenciesLength
,
3673 lpServiceStartNameW
,
3679 if (lpServiceNameW
!=NULL
)
3680 HeapFree(GetProcessHeap(), 0, lpServiceNameW
);
3682 if (lpDisplayNameW
!= NULL
)
3683 HeapFree(GetProcessHeap(), 0, lpDisplayNameW
);
3685 if (lpBinaryPathNameW
!= NULL
)
3686 HeapFree(GetProcessHeap(), 0, lpBinaryPathNameW
);
3688 if (lpLoadOrderGroupW
!= NULL
)
3689 HeapFree(GetProcessHeap(), 0, lpLoadOrderGroupW
);
3691 if (lpDependenciesW
!= NULL
)
3692 HeapFree(GetProcessHeap(), 0, lpDependenciesW
);
3694 if (lpServiceStartNameW
!= NULL
)
3695 HeapFree(GetProcessHeap(), 0, lpServiceStartNameW
);
3702 DWORD
REnumDependentServicesA(
3703 SC_RPC_HANDLE hService
,
3704 DWORD dwServiceState
,
3707 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
3708 LPBOUNDED_DWORD_256K lpServicesReturned
)
3710 DWORD dwError
= ERROR_SUCCESS
;
3711 DWORD dwServicesReturned
= 0;
3712 DWORD dwServiceCount
;
3713 HKEY hServicesKey
= NULL
;
3714 PSERVICE_HANDLE hSvc
;
3715 PSERVICE lpService
= NULL
;
3716 PSERVICE
*lpServicesArray
= NULL
;
3717 LPENUM_SERVICE_STATUSA lpServicesPtr
= NULL
;
3720 *pcbBytesNeeded
= 0;
3721 *lpServicesReturned
= 0;
3723 DPRINT("REnumDependentServicesA() called\n");
3725 hSvc
= ScmGetServiceFromHandle(hService
);
3728 DPRINT1("Invalid service handle!\n");
3729 return ERROR_INVALID_HANDLE
;
3732 lpService
= hSvc
->ServiceEntry
;
3734 /* Check access rights */
3735 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
3736 SC_MANAGER_ENUMERATE_SERVICE
))
3738 DPRINT("Insufficient access rights! 0x%lx\n",
3739 hSvc
->Handle
.DesiredAccess
);
3740 return ERROR_ACCESS_DENIED
;
3743 /* Open the Services Reg key */
3744 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
3745 L
"System\\CurrentControlSet\\Services",
3750 if (dwError
!= ERROR_SUCCESS
)
3753 /* NOTE: Windows calculates the pcbBytesNeeded based on WCHAR strings for
3754 both EnumDependentServicesA and EnumDependentServicesW. So returned pcbBytesNeeded
3755 are the same for both. Verified in WINXP. */
3757 /* First determine the bytes needed and get the number of dependent services*/
3758 dwError
= Int_EnumDependentServicesW(hServicesKey
,
3763 &dwServicesReturned
);
3764 if (dwError
!= ERROR_SUCCESS
)
3767 /* If buffer size is less than the bytes needed or pointer is null*/
3768 if ((!lpServices
) || (cbBufSize
< *pcbBytesNeeded
))
3770 dwError
= ERROR_MORE_DATA
;
3774 /* Allocate memory for array of service pointers */
3775 lpServicesArray
= HeapAlloc(GetProcessHeap(),
3777 (dwServicesReturned
+ 1) * sizeof(PSERVICE
));
3778 if (!lpServicesArray
)
3780 DPRINT("Could not allocate a buffer!!\n");
3781 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
3785 dwServicesReturned
= 0;
3786 *pcbBytesNeeded
= 0;
3788 dwError
= Int_EnumDependentServicesW(hServicesKey
,
3793 &dwServicesReturned
);
3794 if (dwError
!= ERROR_SUCCESS
)
3799 lpServicesPtr
= (LPENUM_SERVICE_STATUSA
)lpServices
;
3800 lpStr
= (LPSTR
)(lpServices
+ (dwServicesReturned
* sizeof(ENUM_SERVICE_STATUSA
)));
3802 /* Copy EnumDepenedentService to Buffer */
3803 for (dwServiceCount
= 0; dwServiceCount
< dwServicesReturned
; dwServiceCount
++)
3805 lpService
= lpServicesArray
[dwServiceCount
];
3807 /* Copy the status info */
3808 memcpy(&lpServicesPtr
->ServiceStatus
,
3810 sizeof(SERVICE_STATUS
));
3812 /* Copy display name */
3813 WideCharToMultiByte(CP_ACP
,
3815 lpService
->lpDisplayName
,
3818 wcslen(lpService
->lpDisplayName
),
3821 lpServicesPtr
->lpDisplayName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServices
);
3822 lpStr
+= strlen(lpStr
) + 1;
3824 /* Copy service name */
3825 WideCharToMultiByte(CP_ACP
,
3827 lpService
->lpServiceName
,
3830 wcslen(lpService
->lpServiceName
),
3833 lpServicesPtr
->lpServiceName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServices
);
3834 lpStr
+= strlen(lpStr
) + 1;
3839 *lpServicesReturned
= dwServicesReturned
;
3842 if (lpServicesArray
)
3843 HeapFree(GetProcessHeap(), 0, lpServicesArray
);
3845 RegCloseKey(hServicesKey
);
3847 DPRINT("REnumDependentServicesA() done (Error %lu)\n", dwError
);
3854 DWORD
REnumServicesStatusA(
3855 SC_RPC_HANDLE hSCManager
,
3856 DWORD dwServiceType
,
3857 DWORD dwServiceState
,
3860 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
3861 LPBOUNDED_DWORD_256K lpServicesReturned
,
3862 LPBOUNDED_DWORD_256K lpResumeHandle
)
3864 LPENUM_SERVICE_STATUSW lpStatusPtrW
= NULL
;
3865 LPENUM_SERVICE_STATUSA lpStatusPtrA
= NULL
;
3866 LPWSTR lpStringPtrW
;
3869 DWORD dwServiceCount
;
3871 DPRINT("REnumServicesStatusA() called\n");
3873 if ((dwBufSize
> 0) && (lpBuffer
))
3875 lpStatusPtrW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, dwBufSize
);
3878 DPRINT("Failed to allocate buffer!\n");
3879 return ERROR_NOT_ENOUGH_MEMORY
;
3883 dwError
= REnumServicesStatusW(hSCManager
,
3886 (LPBYTE
)lpStatusPtrW
,
3892 /* if no services were returned then we are Done */
3893 if (*lpServicesReturned
== 0)
3896 lpStatusPtrA
= (LPENUM_SERVICE_STATUSA
)lpBuffer
;
3897 lpStringPtrA
= (LPSTR
)((ULONG_PTR
)lpBuffer
+
3898 *lpServicesReturned
* sizeof(ENUM_SERVICE_STATUSA
));
3899 lpStringPtrW
= (LPWSTR
)((ULONG_PTR
)lpStatusPtrW
+
3900 *lpServicesReturned
* sizeof(ENUM_SERVICE_STATUSW
));
3902 for (dwServiceCount
= 0; dwServiceCount
< *lpServicesReturned
; dwServiceCount
++)
3904 /* Copy the service name */
3905 WideCharToMultiByte(CP_ACP
,
3910 wcslen(lpStringPtrW
),
3914 lpStatusPtrA
->lpServiceName
= (LPSTR
)((ULONG_PTR
)lpStringPtrA
- (ULONG_PTR
)lpBuffer
);
3915 lpStringPtrA
+= wcslen(lpStringPtrW
) + 1;
3916 lpStringPtrW
+= wcslen(lpStringPtrW
) + 1;
3918 /* Copy the display name */
3919 WideCharToMultiByte(CP_ACP
,
3924 wcslen(lpStringPtrW
),
3928 lpStatusPtrA
->lpDisplayName
= (LPSTR
)((ULONG_PTR
)lpStringPtrA
- (ULONG_PTR
)lpBuffer
);
3929 lpStringPtrA
+= wcslen(lpStringPtrW
) + 1;
3930 lpStringPtrW
+= wcslen(lpStringPtrW
) + 1;
3932 /* Copy the status information */
3933 memcpy(&lpStatusPtrA
->ServiceStatus
,
3934 &lpStatusPtrW
->ServiceStatus
,
3935 sizeof(SERVICE_STATUS
));
3942 HeapFree(GetProcessHeap(), 0, lpStatusPtrW
);
3944 DPRINT("REnumServicesStatusA() done (Error %lu)\n", dwError
);
3951 DWORD
ROpenSCManagerA(
3952 LPSTR lpMachineName
,
3953 LPSTR lpDatabaseName
,
3954 DWORD dwDesiredAccess
,
3955 LPSC_RPC_HANDLE lpScHandle
)
3957 UNICODE_STRING MachineName
;
3958 UNICODE_STRING DatabaseName
;
3961 DPRINT("ROpenSCManagerA() called\n");
3964 RtlCreateUnicodeStringFromAsciiz(&MachineName
,
3968 RtlCreateUnicodeStringFromAsciiz(&DatabaseName
,
3971 dwError
= ROpenSCManagerW(lpMachineName
? MachineName
.Buffer
: NULL
,
3972 lpDatabaseName
? DatabaseName
.Buffer
: NULL
,
3977 RtlFreeUnicodeString(&MachineName
);
3980 RtlFreeUnicodeString(&DatabaseName
);
3987 DWORD
ROpenServiceA(
3988 SC_RPC_HANDLE hSCManager
,
3989 LPSTR lpServiceName
,
3990 DWORD dwDesiredAccess
,
3991 LPSC_RPC_HANDLE lpServiceHandle
)
3993 UNICODE_STRING ServiceName
;
3996 DPRINT("ROpenServiceA() called\n");
3999 RtlCreateUnicodeStringFromAsciiz(&ServiceName
,
4002 dwError
= ROpenServiceW(hSCManager
,
4003 lpServiceName
? ServiceName
.Buffer
: NULL
,
4008 RtlFreeUnicodeString(&ServiceName
);
4015 DWORD
RQueryServiceConfigA(
4016 SC_RPC_HANDLE hService
,
4017 LPBYTE lpBuf
, //LPQUERY_SERVICE_CONFIGA lpServiceConfig,
4019 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
4021 LPQUERY_SERVICE_CONFIGA lpServiceConfig
= (LPQUERY_SERVICE_CONFIGA
)lpBuf
;
4022 DWORD dwError
= ERROR_SUCCESS
;
4023 PSERVICE_HANDLE hSvc
;
4024 PSERVICE lpService
= NULL
;
4025 HKEY hServiceKey
= NULL
;
4026 LPWSTR lpImagePath
= NULL
;
4027 LPWSTR lpServiceStartName
= NULL
;
4028 LPWSTR lpDependencies
= NULL
;
4029 DWORD dwDependenciesLength
= 0;
4030 DWORD dwRequiredSize
;
4031 LPQUERY_SERVICE_CONFIGA lpConfig
= NULL
;
4032 CHAR lpEmptyString
[]={0,0};
4035 DPRINT("RQueryServiceConfigA() called\n");
4038 return ERROR_SHUTDOWN_IN_PROGRESS
;
4040 hSvc
= ScmGetServiceFromHandle(hService
);
4043 DPRINT1("Invalid service handle!\n");
4044 return ERROR_INVALID_HANDLE
;
4047 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4048 SERVICE_QUERY_CONFIG
))
4050 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4051 return ERROR_ACCESS_DENIED
;
4054 lpService
= hSvc
->ServiceEntry
;
4055 if (lpService
== NULL
)
4057 DPRINT("lpService == NULL!\n");
4058 return ERROR_INVALID_HANDLE
;
4061 /* Lock the service database shared */
4062 ScmLockDatabaseShared();
4064 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
4067 if (dwError
!= ERROR_SUCCESS
)
4070 /* Read the image path */
4071 dwError
= ScmReadString(hServiceKey
,
4074 if (dwError
!= ERROR_SUCCESS
)
4077 /* Read the service start name */
4078 ScmReadString(hServiceKey
,
4080 &lpServiceStartName
);
4082 /* Read the dependencies */
4083 ScmReadDependencies(hServiceKey
,
4085 &dwDependenciesLength
);
4087 dwRequiredSize
= sizeof(QUERY_SERVICE_CONFIGW
);
4089 if (lpImagePath
!= NULL
)
4090 dwRequiredSize
+= wcslen(lpImagePath
) + 1;
4092 dwRequiredSize
+= 2;
4094 if ((lpService
->lpGroup
!= NULL
) && (lpService
->lpGroup
->lpGroupName
!= NULL
))
4095 dwRequiredSize
+= wcslen(lpService
->lpGroup
->lpGroupName
) + 1;
4097 dwRequiredSize
+= 2;
4099 /* Add Dependencies length */
4100 if (lpDependencies
!= NULL
)
4101 dwRequiredSize
+= dwDependenciesLength
;
4103 dwRequiredSize
+= 2;
4105 if (lpServiceStartName
!= NULL
)
4106 dwRequiredSize
+= wcslen(lpServiceStartName
) + 1;
4108 dwRequiredSize
+= 2;
4110 if (lpService
->lpDisplayName
!= NULL
)
4111 dwRequiredSize
+= wcslen(lpService
->lpDisplayName
) + 1;
4113 dwRequiredSize
+= 2;
4115 if (lpServiceConfig
== NULL
|| cbBufSize
< dwRequiredSize
)
4117 dwError
= ERROR_INSUFFICIENT_BUFFER
;
4121 lpConfig
= (LPQUERY_SERVICE_CONFIGA
)lpServiceConfig
;
4122 lpConfig
->dwServiceType
= lpService
->Status
.dwServiceType
;
4123 lpConfig
->dwStartType
= lpService
->dwStartType
;
4124 lpConfig
->dwErrorControl
= lpService
->dwErrorControl
;
4125 lpConfig
->dwTagId
= lpService
->dwTag
;
4127 lpStr
= (LPSTR
)(lpServiceConfig
+ 1);
4129 /* NOTE: Strings that are NULL for QUERY_SERVICE_CONFIG are pointers to empty strings.
4134 WideCharToMultiByte(CP_ACP
,
4139 wcslen(lpImagePath
) + 1,
4145 strcpy(lpStr
, lpEmptyString
);
4148 lpConfig
->lpBinaryPathName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
4149 lpStr
+= (strlen((LPSTR
)lpStr
) + 1);
4151 if (lpService
->lpGroup
&& lpService
->lpGroup
->lpGroupName
)
4153 WideCharToMultiByte(CP_ACP
,
4155 lpService
->lpGroup
->lpGroupName
,
4158 wcslen(lpService
->lpGroup
->lpGroupName
) + 1,
4164 strcpy(lpStr
, lpEmptyString
);
4167 lpConfig
->lpLoadOrderGroup
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
4168 lpStr
+= (strlen(lpStr
) + 1);
4170 /* Append Dependencies */
4173 WideCharToMultiByte(CP_ACP
,
4176 dwDependenciesLength
,
4178 dwDependenciesLength
,
4184 strcpy(lpStr
, lpEmptyString
);
4187 lpConfig
->lpDependencies
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
4189 lpStr
+= dwDependenciesLength
;
4191 lpStr
+= (strlen(lpStr
) + 1);
4193 if (lpServiceStartName
)
4195 WideCharToMultiByte(CP_ACP
,
4200 wcslen(lpServiceStartName
) + 1,
4206 strcpy(lpStr
, lpEmptyString
);
4209 lpConfig
->lpServiceStartName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
4210 lpStr
+= (strlen(lpStr
) + 1);
4212 if (lpService
->lpDisplayName
)
4214 WideCharToMultiByte(CP_ACP
,
4216 lpService
->lpDisplayName
,
4219 wcslen(lpService
->lpDisplayName
) + 1,
4225 strcpy(lpStr
, lpEmptyString
);
4228 lpConfig
->lpDisplayName
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpConfig
);
4231 if (pcbBytesNeeded
!= NULL
)
4232 *pcbBytesNeeded
= dwRequiredSize
;
4235 /* Unlock the service database */
4236 ScmUnlockDatabase();
4238 if (lpImagePath
!= NULL
)
4239 HeapFree(GetProcessHeap(), 0, lpImagePath
);
4241 if (lpServiceStartName
!= NULL
)
4242 HeapFree(GetProcessHeap(), 0, lpServiceStartName
);
4244 if (lpDependencies
!= NULL
)
4245 HeapFree(GetProcessHeap(), 0, lpDependencies
);
4247 if (hServiceKey
!= NULL
)
4248 RegCloseKey(hServiceKey
);
4250 DPRINT("RQueryServiceConfigA() done\n");
4257 DWORD
RQueryServiceLockStatusA(
4258 SC_RPC_HANDLE hSCManager
,
4259 LPQUERY_SERVICE_LOCK_STATUSA lpLockStatus
,
4261 LPBOUNDED_DWORD_4K pcbBytesNeeded
)
4264 return ERROR_CALL_NOT_IMPLEMENTED
;
4269 DWORD
RStartServiceA(
4270 SC_RPC_HANDLE hService
,
4272 LPSTRING_PTRSA argv
)
4274 DWORD dwError
= ERROR_SUCCESS
;
4275 PSERVICE_HANDLE hSvc
;
4276 PSERVICE lpService
= NULL
;
4277 LPWSTR
*lpVector
= NULL
;
4281 DPRINT("RStartServiceA() called\n");
4284 return ERROR_SHUTDOWN_IN_PROGRESS
;
4286 hSvc
= ScmGetServiceFromHandle(hService
);
4289 DPRINT1("Invalid service handle!\n");
4290 return ERROR_INVALID_HANDLE
;
4293 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4296 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4297 return ERROR_ACCESS_DENIED
;
4300 lpService
= hSvc
->ServiceEntry
;
4301 if (lpService
== NULL
)
4303 DPRINT("lpService == NULL!\n");
4304 return ERROR_INVALID_HANDLE
;
4307 if (lpService
->dwStartType
== SERVICE_DISABLED
)
4308 return ERROR_SERVICE_DISABLED
;
4310 if (lpService
->bDeleted
)
4311 return ERROR_SERVICE_MARKED_FOR_DELETE
;
4313 /* Build a Unicode argument vector */
4316 lpVector
= HeapAlloc(GetProcessHeap(),
4318 argc
* sizeof(LPWSTR
));
4319 if (lpVector
== NULL
)
4320 return ERROR_NOT_ENOUGH_MEMORY
;
4322 for (i
= 0; i
< argc
; i
++)
4324 dwLength
= MultiByteToWideChar(CP_ACP
,
4331 lpVector
[i
] = HeapAlloc(GetProcessHeap(),
4333 dwLength
* sizeof(WCHAR
));
4334 if (lpVector
[i
] == NULL
)
4336 dwError
= ERROR_NOT_ENOUGH_MEMORY
;
4340 MultiByteToWideChar(CP_ACP
,
4349 /* Start the service */
4350 dwError
= ScmStartService(lpService
, argc
, lpVector
);
4353 /* Free the Unicode argument vector */
4354 if (lpVector
!= NULL
)
4356 for (i
= 0; i
< argc
; i
++)
4358 if (lpVector
[i
] != NULL
)
4359 HeapFree(GetProcessHeap(), 0, lpVector
[i
]);
4361 HeapFree(GetProcessHeap(), 0, lpVector
);
4369 DWORD
RGetServiceDisplayNameA(
4370 SC_RPC_HANDLE hSCManager
,
4371 LPCSTR lpServiceName
,
4372 LPSTR lpDisplayName
,
4373 LPBOUNDED_DWORD_4K lpcchBuffer
)
4375 // PMANAGER_HANDLE hManager;
4376 PSERVICE lpService
= NULL
;
4379 LPWSTR lpServiceNameW
;
4381 DPRINT("RGetServiceDisplayNameA() called\n");
4382 DPRINT("hSCManager = %p\n", hSCManager
);
4383 DPRINT("lpServiceName: %s\n", lpServiceName
);
4384 DPRINT("lpDisplayName: %p\n", lpDisplayName
);
4385 DPRINT("*lpcchBuffer: %lu\n", *lpcchBuffer
);
4387 // hManager = (PMANAGER_HANDLE)hSCManager;
4388 // if (hManager->Handle.Tag != MANAGER_TAG)
4390 // DPRINT("Invalid manager handle!\n");
4391 // return ERROR_INVALID_HANDLE;
4394 if (lpServiceName
!= NULL
)
4396 dwLength
= strlen(lpServiceName
) + 1;
4397 lpServiceNameW
= HeapAlloc(GetProcessHeap(),
4399 dwLength
* sizeof(WCHAR
));
4400 if (!lpServiceNameW
)
4401 return ERROR_NOT_ENOUGH_MEMORY
;
4403 MultiByteToWideChar(CP_ACP
,
4410 lpService
= ScmGetServiceEntryByName(lpServiceNameW
);
4412 HeapFree(GetProcessHeap(), 0, lpServiceNameW
);
4415 if (lpService
== NULL
)
4417 DPRINT("Could not find a service!\n");
4419 /* If the service could not be found and lpcchBuffer is 0, windows
4420 puts null in lpDisplayName and puts 1 in lpcchBuffer */
4421 if (*lpcchBuffer
== 0)
4424 if (lpDisplayName
!= NULL
)
4426 *lpDisplayName
= '\0';
4429 return ERROR_SERVICE_DOES_NOT_EXIST
;
4432 if (!lpService
->lpDisplayName
)
4434 dwLength
= wcslen(lpService
->lpServiceName
);
4435 if (lpDisplayName
!= NULL
&&
4436 *lpcchBuffer
> dwLength
)
4438 WideCharToMultiByte(CP_ACP
,
4440 lpService
->lpServiceName
,
4441 wcslen(lpService
->lpServiceName
),
4446 return ERROR_SUCCESS
;
4451 dwLength
= wcslen(lpService
->lpDisplayName
);
4452 if (lpDisplayName
!= NULL
&&
4453 *lpcchBuffer
> dwLength
)
4455 WideCharToMultiByte(CP_ACP
,
4457 lpService
->lpDisplayName
,
4458 wcslen(lpService
->lpDisplayName
),
4463 return ERROR_SUCCESS
;
4467 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
4469 *lpcchBuffer
= dwLength
* 2;
4476 DWORD
RGetServiceKeyNameA(
4477 SC_RPC_HANDLE hSCManager
,
4478 LPCSTR lpDisplayName
,
4479 LPSTR lpServiceName
,
4480 LPBOUNDED_DWORD_4K lpcchBuffer
)
4485 LPWSTR lpDisplayNameW
;
4487 DPRINT("RGetServiceKeyNameA() called\n");
4488 DPRINT("hSCManager = %p\n", hSCManager
);
4489 DPRINT("lpDisplayName: %s\n", lpDisplayName
);
4490 DPRINT("lpServiceName: %p\n", lpServiceName
);
4491 DPRINT("*lpcchBuffer: %lu\n", *lpcchBuffer
);
4493 dwLength
= strlen(lpDisplayName
) + 1;
4494 lpDisplayNameW
= HeapAlloc(GetProcessHeap(),
4496 dwLength
* sizeof(WCHAR
));
4497 if (!lpDisplayNameW
)
4498 return ERROR_NOT_ENOUGH_MEMORY
;
4500 MultiByteToWideChar(CP_ACP
,
4507 lpService
= ScmGetServiceEntryByDisplayName(lpDisplayNameW
);
4509 HeapFree(GetProcessHeap(), 0, lpDisplayNameW
);
4511 if (lpService
== NULL
)
4513 DPRINT("Could not find the service!\n");
4515 /* If the service could not be found and lpcchBuffer is 0,
4516 put null in lpDisplayName and puts 1 in lpcchBuffer, verified WINXP. */
4517 if (*lpcchBuffer
== 0)
4520 if (lpServiceName
!= NULL
)
4522 *lpServiceName
= '\0';
4526 return ERROR_SERVICE_DOES_NOT_EXIST
;
4529 dwLength
= wcslen(lpService
->lpServiceName
);
4530 if (lpServiceName
!= NULL
&&
4531 *lpcchBuffer
> dwLength
)
4533 WideCharToMultiByte(CP_ACP
,
4535 lpService
->lpServiceName
,
4536 wcslen(lpService
->lpServiceName
),
4541 return ERROR_SUCCESS
;
4544 dwError
= (*lpcchBuffer
> dwLength
) ? ERROR_SUCCESS
: ERROR_INSUFFICIENT_BUFFER
;
4546 *lpcchBuffer
= dwLength
* 2;
4553 DWORD
RI_ScGetCurrentGroupStateW(
4554 SC_RPC_HANDLE hSCManager
,
4555 LPWSTR lpLoadOrderGroup
,
4559 return ERROR_CALL_NOT_IMPLEMENTED
;
4564 DWORD
REnumServiceGroupW(
4565 SC_RPC_HANDLE hSCManager
,
4566 DWORD dwServiceType
,
4567 DWORD dwServiceState
,
4570 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
4571 LPBOUNDED_DWORD_256K lpServicesReturned
,
4572 LPBOUNDED_DWORD_256K lpResumeIndex
,
4573 LPCWSTR pszGroupName
)
4576 return ERROR_CALL_NOT_IMPLEMENTED
;
4581 // WARNING: This function is untested
4584 DWORD
RChangeServiceConfig2A(
4585 SC_RPC_HANDLE hService
,
4586 SC_RPC_CONFIG_INFOA Info
)
4588 SC_RPC_CONFIG_INFOW InfoW
;
4589 DWORD dwRet
, dwLength
;
4592 DPRINT("RChangeServiceConfig2A() called\n");
4593 DPRINT("dwInfoLevel = %lu\n", Info
.dwInfoLevel
);
4595 InfoW
.dwInfoLevel
= Info
.dwInfoLevel
;
4597 if (InfoW
.dwInfoLevel
== SERVICE_CONFIG_DESCRIPTION
)
4599 LPSERVICE_DESCRIPTIONW lpServiceDescriptonW
;
4600 //LPSERVICE_DESCRIPTIONA lpServiceDescriptonA;
4602 //lpServiceDescriptonA = Info.psd;
4604 ///if (lpServiceDescriptonA &&
4605 ///lpServiceDescriptonA->lpDescription)
4607 dwLength
= (strlen(Info
.lpDescription
) + 1) * sizeof(WCHAR
);
4609 lpServiceDescriptonW
= HeapAlloc(GetProcessHeap(),
4611 dwLength
+ sizeof(SERVICE_DESCRIPTIONW
));
4612 if (!lpServiceDescriptonW
)
4614 return ERROR_NOT_ENOUGH_MEMORY
;
4617 lpServiceDescriptonW
->lpDescription
= (LPWSTR
)(lpServiceDescriptonW
+ 1);
4619 MultiByteToWideChar(CP_ACP
,
4623 lpServiceDescriptonW
->lpDescription
,
4626 ptr
= lpServiceDescriptonW
;
4627 InfoW
.psd
= lpServiceDescriptonW
;
4630 else if (Info
.dwInfoLevel
== SERVICE_CONFIG_FAILURE_ACTIONS
)
4632 LPSERVICE_FAILURE_ACTIONSW lpServiceFailureActionsW
;
4633 LPSERVICE_FAILURE_ACTIONSA lpServiceFailureActionsA
;
4634 DWORD dwRebootLen
= 0;
4635 DWORD dwCommandLen
= 0;
4637 lpServiceFailureActionsA
= Info
.psfa
;
4639 if (lpServiceFailureActionsA
)
4641 if (lpServiceFailureActionsA
->lpRebootMsg
)
4643 dwRebootLen
= (strlen(lpServiceFailureActionsA
->lpRebootMsg
) + 1) * sizeof(WCHAR
);
4645 if (lpServiceFailureActionsA
->lpCommand
)
4647 dwCommandLen
= (strlen(lpServiceFailureActionsA
->lpCommand
) + 1) * sizeof(WCHAR
);
4649 dwLength
= dwRebootLen
+ dwCommandLen
+ sizeof(SERVICE_FAILURE_ACTIONSW
);
4651 lpServiceFailureActionsW
= HeapAlloc(GetProcessHeap(),
4654 if (!lpServiceFailureActionsW
)
4656 return ERROR_NOT_ENOUGH_MEMORY
;
4659 lpServiceFailureActionsW
->cActions
= lpServiceFailureActionsA
->cActions
;
4660 lpServiceFailureActionsW
->dwResetPeriod
= lpServiceFailureActionsA
->dwResetPeriod
;
4661 CopyMemory(lpServiceFailureActionsW
->lpsaActions
, lpServiceFailureActionsA
->lpsaActions
, sizeof(SC_ACTION
));
4663 if (lpServiceFailureActionsA
->lpRebootMsg
)
4665 MultiByteToWideChar(CP_ACP
,
4667 lpServiceFailureActionsA
->lpRebootMsg
,
4669 lpServiceFailureActionsW
->lpRebootMsg
,
4673 if (lpServiceFailureActionsA
->lpCommand
)
4675 MultiByteToWideChar(CP_ACP
,
4677 lpServiceFailureActionsA
->lpCommand
,
4679 lpServiceFailureActionsW
->lpCommand
,
4683 ptr
= lpServiceFailureActionsW
;
4687 dwRet
= RChangeServiceConfig2W(hService
, InfoW
);
4689 HeapFree(GetProcessHeap(), 0, ptr
);
4696 DWORD
RChangeServiceConfig2W(
4697 SC_RPC_HANDLE hService
,
4698 SC_RPC_CONFIG_INFOW Info
)
4700 DWORD dwError
= ERROR_SUCCESS
;
4701 PSERVICE_HANDLE hSvc
;
4702 PSERVICE lpService
= NULL
;
4703 HKEY hServiceKey
= NULL
;
4705 DPRINT("RChangeServiceConfig2W() called\n");
4706 DPRINT("dwInfoLevel = %lu\n", Info
.dwInfoLevel
);
4709 return ERROR_SHUTDOWN_IN_PROGRESS
;
4711 hSvc
= ScmGetServiceFromHandle(hService
);
4714 DPRINT1("Invalid service handle!\n");
4715 return ERROR_INVALID_HANDLE
;
4718 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4719 SERVICE_CHANGE_CONFIG
))
4721 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4722 return ERROR_ACCESS_DENIED
;
4725 lpService
= hSvc
->ServiceEntry
;
4726 if (lpService
== NULL
)
4728 DPRINT("lpService == NULL!\n");
4729 return ERROR_INVALID_HANDLE
;
4732 /* Lock the service database exclusively */
4733 ScmLockDatabaseExclusive();
4735 if (lpService
->bDeleted
)
4737 DPRINT("The service has already been marked for delete!\n");
4738 dwError
= ERROR_SERVICE_MARKED_FOR_DELETE
;
4742 /* Open the service key */
4743 dwError
= ScmOpenServiceKey(lpService
->szServiceName
,
4746 if (dwError
!= ERROR_SUCCESS
)
4749 if (Info
.dwInfoLevel
== SERVICE_CONFIG_DESCRIPTION
)
4751 LPSERVICE_DESCRIPTIONW lpServiceDescription
;
4753 lpServiceDescription
= (LPSERVICE_DESCRIPTIONW
)Info
.psd
;
4754 lpServiceDescription
->lpDescription
= (LPWSTR
)((ULONG_PTR
)lpServiceDescription
+ sizeof(LPSERVICE_DESCRIPTIONW
));
4756 if (lpServiceDescription
!= NULL
&&
4757 lpServiceDescription
->lpDescription
!= NULL
)
4759 DPRINT("Setting value %S\n", lpServiceDescription
->lpDescription
);
4760 dwError
= RegSetValueExW(hServiceKey
,
4764 (LPBYTE
)lpServiceDescription
->lpDescription
,
4765 (wcslen(lpServiceDescription
->lpDescription
) + 1) * sizeof(WCHAR
));
4766 if (dwError
!= ERROR_SUCCESS
)
4770 else if (Info
.dwInfoLevel
== SERVICE_CONFIG_FAILURE_ACTIONS
)
4773 dwError
= ERROR_CALL_NOT_IMPLEMENTED
;
4778 /* Unlock the service database */
4779 ScmUnlockDatabase();
4781 if (hServiceKey
!= NULL
)
4782 RegCloseKey(hServiceKey
);
4784 DPRINT("RChangeServiceConfig2W() done (Error %lu)\n", dwError
);
4791 DWORD
RQueryServiceConfig2A(
4792 SC_RPC_HANDLE hService
,
4796 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
4798 DWORD dwError
= ERROR_SUCCESS
;
4799 PSERVICE_HANDLE hSvc
;
4800 PSERVICE lpService
= NULL
;
4801 HKEY hServiceKey
= NULL
;
4802 LPWSTR lpDescriptionW
= NULL
;
4803 LPSTR lpDescription
= NULL
;
4805 DPRINT("RQueryServiceConfig2A() called hService %p dwInfoLevel %u, lpBuffer %p cbBufSize %u pcbBytesNeeded %p\n",
4806 hService
, dwInfoLevel
, lpBuffer
, cbBufSize
, pcbBytesNeeded
);
4809 return ERROR_INVALID_ADDRESS
;
4812 return ERROR_SHUTDOWN_IN_PROGRESS
;
4814 hSvc
= ScmGetServiceFromHandle(hService
);
4817 DPRINT1("Invalid service handle!\n");
4818 return ERROR_INVALID_HANDLE
;
4821 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4822 SERVICE_QUERY_CONFIG
))
4824 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4825 return ERROR_ACCESS_DENIED
;
4828 lpService
= hSvc
->ServiceEntry
;
4829 if (lpService
== NULL
)
4831 DPRINT("lpService == NULL!\n");
4832 return ERROR_INVALID_HANDLE
;
4835 /* Lock the service database shared */
4836 ScmLockDatabaseShared();
4838 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
4841 if (dwError
!= ERROR_SUCCESS
)
4844 if (dwInfoLevel
== SERVICE_CONFIG_DESCRIPTION
)
4846 LPSERVICE_DESCRIPTIONA lpServiceDescription
= (LPSERVICE_DESCRIPTIONA
)lpBuffer
;
4849 dwError
= ScmReadString(hServiceKey
,
4852 if (dwError
!= ERROR_SUCCESS
&& dwError
!= ERROR_FILE_NOT_FOUND
)
4855 *pcbBytesNeeded
= sizeof(SERVICE_DESCRIPTIONA
);
4856 if (dwError
== ERROR_SUCCESS
)
4857 *pcbBytesNeeded
+= ((wcslen(lpDescriptionW
) + 1) * sizeof(WCHAR
));
4859 if (cbBufSize
< *pcbBytesNeeded
)
4861 dwError
= ERROR_INSUFFICIENT_BUFFER
;
4865 if (dwError
== ERROR_SUCCESS
)
4867 lpStr
= (LPSTR
)(lpServiceDescription
+ 1);
4869 WideCharToMultiByte(CP_ACP
,
4874 wcslen(lpDescriptionW
),
4877 lpServiceDescription
->lpDescription
= (LPSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServiceDescription
);
4881 lpServiceDescription
->lpDescription
= NULL
;
4882 dwError
= ERROR_SUCCESS
;
4886 else if (dwInfoLevel
& SERVICE_CONFIG_FAILURE_ACTIONS
)
4889 dwError
= ERROR_CALL_NOT_IMPLEMENTED
;
4894 /* Unlock the service database */
4895 ScmUnlockDatabase();
4897 if (lpDescription
!= NULL
)
4898 HeapFree(GetProcessHeap(), 0, lpDescription
);
4900 if (hServiceKey
!= NULL
)
4901 RegCloseKey(hServiceKey
);
4903 DPRINT("RQueryServiceConfig2W() done (Error %lu)\n", dwError
);
4910 DWORD
RQueryServiceConfig2W(
4911 SC_RPC_HANDLE hService
,
4915 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
4917 DWORD dwError
= ERROR_SUCCESS
;
4918 PSERVICE_HANDLE hSvc
;
4919 PSERVICE lpService
= NULL
;
4920 HKEY hServiceKey
= NULL
;
4921 DWORD dwRequiredSize
;
4922 LPWSTR lpDescription
= NULL
;
4923 LPWSTR lpFailureCommand
= NULL
;
4924 LPWSTR lpRebootMessage
= NULL
;
4926 DPRINT("RQueryServiceConfig2W() called\n");
4929 return ERROR_INVALID_ADDRESS
;
4932 return ERROR_SHUTDOWN_IN_PROGRESS
;
4934 hSvc
= ScmGetServiceFromHandle(hService
);
4937 DPRINT1("Invalid service handle!\n");
4938 return ERROR_INVALID_HANDLE
;
4941 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
4942 SERVICE_QUERY_CONFIG
))
4944 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
4945 return ERROR_ACCESS_DENIED
;
4948 lpService
= hSvc
->ServiceEntry
;
4949 if (lpService
== NULL
)
4951 DPRINT("lpService == NULL!\n");
4952 return ERROR_INVALID_HANDLE
;
4955 /* Lock the service database shared */
4956 ScmLockDatabaseShared();
4958 dwError
= ScmOpenServiceKey(lpService
->lpServiceName
,
4961 if (dwError
!= ERROR_SUCCESS
)
4964 if (dwInfoLevel
== SERVICE_CONFIG_DESCRIPTION
)
4966 LPSERVICE_DESCRIPTIONW lpServiceDescription
= (LPSERVICE_DESCRIPTIONW
)lpBuffer
;
4969 dwError
= ScmReadString(hServiceKey
,
4972 if (dwError
!= ERROR_SUCCESS
&& dwError
!= ERROR_FILE_NOT_FOUND
)
4975 *pcbBytesNeeded
= sizeof(SERVICE_DESCRIPTIONW
);
4976 if (dwError
== ERROR_SUCCESS
)
4977 *pcbBytesNeeded
+= ((wcslen(lpDescription
) + 1) * sizeof(WCHAR
));
4979 if (cbBufSize
< *pcbBytesNeeded
)
4981 dwError
= ERROR_INSUFFICIENT_BUFFER
;
4985 if (dwError
== ERROR_SUCCESS
)
4987 lpStr
= (LPWSTR
)(lpServiceDescription
+ 1);
4988 wcscpy(lpStr
, lpDescription
);
4989 lpServiceDescription
->lpDescription
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpServiceDescription
);
4993 lpServiceDescription
->lpDescription
= NULL
;
4994 dwError
= ERROR_SUCCESS
;
4997 else if (dwInfoLevel
== SERVICE_CONFIG_FAILURE_ACTIONS
)
5000 LPSERVICE_FAILURE_ACTIONSW lpFailureActions
= (LPSERVICE_FAILURE_ACTIONSW
)lpBuffer
;
5004 dwError
= ScmReadString(hServiceKey
,
5008 dwError
= ScmReadString(hServiceKey
,
5012 dwRequiredSize
= sizeof(SERVICE_FAILURE_ACTIONSW
);
5014 if (lpFailureCommand
)
5015 dwRequiredSize
+= (wcslen(lpFailureCommand
) + 1) * sizeof(WCHAR
);
5017 if (lpRebootMessage
)
5018 dwRequiredSize
+= (wcslen(lpRebootMessage
) + 1) * sizeof(WCHAR
);
5020 if (cbBufSize
< dwRequiredSize
)
5022 *pcbBytesNeeded
= dwRequiredSize
;
5023 dwError
= ERROR_INSUFFICIENT_BUFFER
;
5027 lpFailureActions
->cActions
= 0;
5028 lpFailureActions
->dwResetPeriod
= 0;
5029 lpFailureActions
->lpCommand
= NULL
;
5030 lpFailureActions
->lpRebootMsg
= NULL
;
5031 lpFailureActions
->lpsaActions
= NULL
;
5033 lpStr
= (LPWSTR
)(lpFailureActions
+ 1);
5034 if (lpRebootMessage
)
5036 wcscpy(lpStr
, lpRebootMessage
);
5037 lpFailureActions
->lpRebootMsg
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpRebootMessage
);
5038 lpStr
+= wcslen(lpRebootMessage
) + 1;
5041 if (lpFailureCommand
)
5043 wcscpy(lpStr
, lpFailureCommand
);
5044 lpFailureActions
->lpCommand
= (LPWSTR
)((ULONG_PTR
)lpStr
- (ULONG_PTR
)lpFailureCommand
);
5045 lpStr
+= wcslen(lpRebootMessage
) + 1;
5047 dwError
= STATUS_SUCCESS
;
5052 /* Unlock the service database */
5053 ScmUnlockDatabase();
5055 if (lpDescription
!= NULL
)
5056 HeapFree(GetProcessHeap(), 0, lpDescription
);
5058 if (lpRebootMessage
!= NULL
)
5059 HeapFree(GetProcessHeap(), 0, lpRebootMessage
);
5061 if (lpFailureCommand
!= NULL
)
5062 HeapFree(GetProcessHeap(), 0, lpFailureCommand
);
5064 if (hServiceKey
!= NULL
)
5065 RegCloseKey(hServiceKey
);
5067 DPRINT("RQueryServiceConfig2W() done (Error %lu)\n", dwError
);
5074 DWORD
RQueryServiceStatusEx(
5075 SC_RPC_HANDLE hService
,
5076 SC_STATUS_TYPE InfoLevel
,
5079 LPBOUNDED_DWORD_8K pcbBytesNeeded
)
5081 LPSERVICE_STATUS_PROCESS lpStatus
;
5082 PSERVICE_HANDLE hSvc
;
5085 DPRINT("RQueryServiceStatusEx() called\n");
5088 return ERROR_SHUTDOWN_IN_PROGRESS
;
5090 if (InfoLevel
!= SC_STATUS_PROCESS_INFO
)
5091 return ERROR_INVALID_LEVEL
;
5093 *pcbBytesNeeded
= sizeof(SERVICE_STATUS_PROCESS
);
5095 if (cbBufSize
< sizeof(SERVICE_STATUS_PROCESS
))
5096 return ERROR_INSUFFICIENT_BUFFER
;
5098 hSvc
= ScmGetServiceFromHandle(hService
);
5101 DPRINT1("Invalid service handle!\n");
5102 return ERROR_INVALID_HANDLE
;
5105 if (!RtlAreAllAccessesGranted(hSvc
->Handle
.DesiredAccess
,
5106 SERVICE_QUERY_STATUS
))
5108 DPRINT("Insufficient access rights! 0x%lx\n", hSvc
->Handle
.DesiredAccess
);
5109 return ERROR_ACCESS_DENIED
;
5112 lpService
= hSvc
->ServiceEntry
;
5113 if (lpService
== NULL
)
5115 DPRINT("lpService == NULL!\n");
5116 return ERROR_INVALID_HANDLE
;
5119 /* Lock the service database shared */
5120 ScmLockDatabaseShared();
5122 lpStatus
= (LPSERVICE_STATUS_PROCESS
)lpBuffer
;
5124 /* Return service status information */
5125 RtlCopyMemory(lpStatus
,
5127 sizeof(SERVICE_STATUS
));
5129 lpStatus
->dwProcessId
= (lpService
->lpImage
!= NULL
) ? lpService
->lpImage
->dwProcessId
: 0; /* FIXME */
5130 lpStatus
->dwServiceFlags
= 0; /* FIXME */
5132 /* Unlock the service database */
5133 ScmUnlockDatabase();
5135 return ERROR_SUCCESS
;
5140 DWORD
REnumServicesStatusExA(
5141 SC_RPC_HANDLE hSCManager
,
5142 SC_ENUM_TYPE InfoLevel
,
5143 DWORD dwServiceType
,
5144 DWORD dwServiceState
,
5147 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
5148 LPBOUNDED_DWORD_256K lpServicesReturned
,
5149 LPBOUNDED_DWORD_256K lpResumeIndex
,
5150 LPCSTR pszGroupName
)
5152 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtrW
= NULL
;
5153 LPENUM_SERVICE_STATUS_PROCESSA lpStatusPtrA
= NULL
;
5154 LPWSTR lpStringPtrW
;
5156 LPWSTR pszGroupNameW
= NULL
;
5158 DWORD dwServiceCount
;
5160 DPRINT("REnumServicesStatusExA() called\n");
5164 pszGroupNameW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (strlen(pszGroupName
) + 1) * sizeof(WCHAR
));
5167 DPRINT("Failed to allocate buffer!\n");
5168 return ERROR_NOT_ENOUGH_MEMORY
;
5171 MultiByteToWideChar(CP_ACP
,
5176 strlen(pszGroupName
) + 1);
5179 if ((cbBufSize
> 0) && (lpBuffer
))
5181 lpStatusPtrW
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, cbBufSize
);
5184 DPRINT("Failed to allocate buffer!\n");
5185 return ERROR_NOT_ENOUGH_MEMORY
;
5189 dwError
= REnumServicesStatusExW(hSCManager
,
5193 (LPBYTE
)lpStatusPtrW
,
5200 /* if no services were returned then we are Done */
5201 if (*lpServicesReturned
== 0)
5204 lpStatusPtrA
= (LPENUM_SERVICE_STATUS_PROCESSA
)lpBuffer
;
5205 lpStringPtrA
= (LPSTR
)((ULONG_PTR
)lpBuffer
+
5206 *lpServicesReturned
* sizeof(ENUM_SERVICE_STATUS_PROCESSA
));
5207 lpStringPtrW
= (LPWSTR
)((ULONG_PTR
)lpStatusPtrW
+
5208 *lpServicesReturned
* sizeof(ENUM_SERVICE_STATUS_PROCESSW
));
5210 for (dwServiceCount
= 0; dwServiceCount
< *lpServicesReturned
; dwServiceCount
++)
5212 /* Copy the service name */
5213 WideCharToMultiByte(CP_ACP
,
5218 wcslen(lpStringPtrW
),
5222 lpStatusPtrA
->lpServiceName
= (LPSTR
)((ULONG_PTR
)lpStringPtrA
- (ULONG_PTR
)lpBuffer
);
5223 lpStringPtrA
+= wcslen(lpStringPtrW
) + 1;
5224 lpStringPtrW
+= wcslen(lpStringPtrW
) + 1;
5226 /* Copy the display name */
5227 WideCharToMultiByte(CP_ACP
,
5232 wcslen(lpStringPtrW
),
5236 lpStatusPtrA
->lpDisplayName
= (LPSTR
)((ULONG_PTR
)lpStringPtrA
- (ULONG_PTR
)lpBuffer
);
5237 lpStringPtrA
+= wcslen(lpStringPtrW
) + 1;
5238 lpStringPtrW
+= wcslen(lpStringPtrW
) + 1;
5240 /* Copy the status information */
5241 memcpy(&lpStatusPtrA
->ServiceStatusProcess
,
5242 &lpStatusPtrW
->ServiceStatusProcess
,
5243 sizeof(SERVICE_STATUS
));
5245 lpStatusPtrA
->ServiceStatusProcess
.dwProcessId
= lpStatusPtrW
->ServiceStatusProcess
.dwProcessId
; /* FIXME */
5246 lpStatusPtrA
->ServiceStatusProcess
.dwServiceFlags
= 0; /* FIXME */
5252 HeapFree(GetProcessHeap(), 0, pszGroupNameW
);
5255 HeapFree(GetProcessHeap(), 0, lpStatusPtrW
);
5257 DPRINT("REnumServicesStatusExA() done (Error %lu)\n", dwError
);
5264 DWORD
REnumServicesStatusExW(
5265 SC_RPC_HANDLE hSCManager
,
5266 SC_ENUM_TYPE InfoLevel
,
5267 DWORD dwServiceType
,
5268 DWORD dwServiceState
,
5271 LPBOUNDED_DWORD_256K pcbBytesNeeded
,
5272 LPBOUNDED_DWORD_256K lpServicesReturned
,
5273 LPBOUNDED_DWORD_256K lpResumeIndex
,
5274 LPCWSTR pszGroupName
)
5276 PMANAGER_HANDLE hManager
;
5278 DWORD dwError
= ERROR_SUCCESS
;
5279 PLIST_ENTRY ServiceEntry
;
5280 PSERVICE CurrentService
;
5282 DWORD dwRequiredSize
;
5283 DWORD dwServiceCount
;
5285 DWORD dwLastResumeCount
= 0;
5286 LPENUM_SERVICE_STATUS_PROCESSW lpStatusPtr
;
5289 DPRINT("REnumServicesStatusExW() called\n");
5292 return ERROR_SHUTDOWN_IN_PROGRESS
;
5294 if (InfoLevel
!= SC_ENUM_PROCESS_INFO
)
5295 return ERROR_INVALID_LEVEL
;
5297 hManager
= ScmGetServiceManagerFromHandle(hSCManager
);
5298 if (hManager
== NULL
)
5300 DPRINT1("Invalid service manager handle!\n");
5301 return ERROR_INVALID_HANDLE
;
5304 *pcbBytesNeeded
= 0;
5305 *lpServicesReturned
= 0;
5307 if ((dwServiceType
== 0) ||
5308 ((dwServiceType
& ~(SERVICE_DRIVER
| SERVICE_WIN32
)) != 0))
5310 DPRINT("Not a valid Service Type!\n");
5311 return ERROR_INVALID_PARAMETER
;
5314 if ((dwServiceState
!= SERVICE_ACTIVE
) &&
5315 (dwServiceState
!= SERVICE_INACTIVE
) &&
5316 (dwServiceState
!= SERVICE_STATE_ALL
))
5318 DPRINT("Not a valid Service State!\n");
5319 return ERROR_INVALID_PARAMETER
;
5322 /* Check access rights */
5323 if (!RtlAreAllAccessesGranted(hManager
->Handle
.DesiredAccess
,
5324 SC_MANAGER_ENUMERATE_SERVICE
))
5326 DPRINT("Insufficient access rights! 0x%lx\n",
5327 hManager
->Handle
.DesiredAccess
);
5328 return ERROR_ACCESS_DENIED
;
5332 dwLastResumeCount
= *lpResumeIndex
;
5334 /* Lock the service database shared */
5335 ScmLockDatabaseShared();
5337 lpService
= ScmGetServiceEntryByResumeCount(dwLastResumeCount
);
5338 if (lpService
== NULL
)
5340 dwError
= ERROR_SUCCESS
;
5347 for (ServiceEntry
= &lpService
->ServiceListEntry
;
5348 ServiceEntry
!= &ServiceListHead
;
5349 ServiceEntry
= ServiceEntry
->Flink
)
5351 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
5355 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
5358 dwState
= SERVICE_ACTIVE
;
5359 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
5360 dwState
= SERVICE_INACTIVE
;
5362 if ((dwState
& dwServiceState
) == 0)
5367 if (*pszGroupName
== 0)
5369 if (CurrentService
->lpGroup
!= NULL
)
5374 if ((CurrentService
->lpGroup
== NULL
) ||
5375 _wcsicmp(pszGroupName
, CurrentService
->lpGroup
->lpGroupName
))
5380 dwSize
= sizeof(ENUM_SERVICE_STATUS_PROCESSW
) +
5381 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
5382 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
5384 if (dwRequiredSize
+ dwSize
<= cbBufSize
)
5386 DPRINT("Service name: %S fit\n", CurrentService
->lpServiceName
);
5387 dwRequiredSize
+= dwSize
;
5389 dwLastResumeCount
= CurrentService
->dwResumeCount
;
5393 DPRINT("Service name: %S no fit\n", CurrentService
->lpServiceName
);
5399 DPRINT("dwRequiredSize: %lu\n", dwRequiredSize
);
5400 DPRINT("dwServiceCount: %lu\n", dwServiceCount
);
5403 ServiceEntry
!= &ServiceListHead
;
5404 ServiceEntry
= ServiceEntry
->Flink
)
5406 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
5410 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
5413 dwState
= SERVICE_ACTIVE
;
5414 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
5415 dwState
= SERVICE_INACTIVE
;
5417 if ((dwState
& dwServiceState
) == 0)
5422 if (*pszGroupName
== 0)
5424 if (CurrentService
->lpGroup
!= NULL
)
5429 if ((CurrentService
->lpGroup
== NULL
) ||
5430 _wcsicmp(pszGroupName
, CurrentService
->lpGroup
->lpGroupName
))
5435 dwRequiredSize
+= (sizeof(ENUM_SERVICE_STATUS_PROCESSW
) +
5436 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
5437 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
)));
5439 dwError
= ERROR_MORE_DATA
;
5442 DPRINT("*pcbBytesNeeded: %lu\n", dwRequiredSize
);
5445 *lpResumeIndex
= dwLastResumeCount
;
5447 *lpServicesReturned
= dwServiceCount
;
5448 *pcbBytesNeeded
= dwRequiredSize
;
5450 /* If there was no services that matched */
5451 if ((!dwServiceCount
) && (dwError
!= ERROR_MORE_DATA
))
5453 dwError
= ERROR_SERVICE_DOES_NOT_EXIST
;
5457 lpStatusPtr
= (LPENUM_SERVICE_STATUS_PROCESSW
)lpBuffer
;
5458 lpStringPtr
= (LPWSTR
)((ULONG_PTR
)lpBuffer
+
5459 dwServiceCount
* sizeof(ENUM_SERVICE_STATUS_PROCESSW
));
5462 for (ServiceEntry
= &lpService
->ServiceListEntry
;
5463 ServiceEntry
!= &ServiceListHead
;
5464 ServiceEntry
= ServiceEntry
->Flink
)
5466 CurrentService
= CONTAINING_RECORD(ServiceEntry
,
5470 if ((CurrentService
->Status
.dwServiceType
& dwServiceType
) == 0)
5473 dwState
= SERVICE_ACTIVE
;
5474 if (CurrentService
->Status
.dwCurrentState
== SERVICE_STOPPED
)
5475 dwState
= SERVICE_INACTIVE
;
5477 if ((dwState
& dwServiceState
) == 0)
5482 if (*pszGroupName
== 0)
5484 if (CurrentService
->lpGroup
!= NULL
)
5489 if ((CurrentService
->lpGroup
== NULL
) ||
5490 _wcsicmp(pszGroupName
, CurrentService
->lpGroup
->lpGroupName
))
5495 dwSize
= sizeof(ENUM_SERVICE_STATUS_PROCESSW
) +
5496 ((wcslen(CurrentService
->lpServiceName
) + 1) * sizeof(WCHAR
)) +
5497 ((wcslen(CurrentService
->lpDisplayName
) + 1) * sizeof(WCHAR
));
5499 if (dwRequiredSize
+ dwSize
<= cbBufSize
)
5501 /* Copy the service name */
5503 CurrentService
->lpServiceName
);
5504 lpStatusPtr
->lpServiceName
= (LPWSTR
)((ULONG_PTR
)lpStringPtr
- (ULONG_PTR
)lpBuffer
);
5505 lpStringPtr
+= (wcslen(CurrentService
->lpServiceName
) + 1);
5507 /* Copy the display name */
5509 CurrentService
->lpDisplayName
);
5510 lpStatusPtr
->lpDisplayName
= (LPWSTR
)((ULONG_PTR
)lpStringPtr
- (ULONG_PTR
)lpBuffer
);
5511 lpStringPtr
+= (wcslen(CurrentService
->lpDisplayName
) + 1);
5513 /* Copy the status information */
5514 memcpy(&lpStatusPtr
->ServiceStatusProcess
,
5515 &CurrentService
->Status
,
5516 sizeof(SERVICE_STATUS
));
5517 lpStatusPtr
->ServiceStatusProcess
.dwProcessId
=
5518 (CurrentService
->lpImage
!= NULL
) ? CurrentService
->lpImage
->dwProcessId
: 0; /* FIXME */
5519 lpStatusPtr
->ServiceStatusProcess
.dwServiceFlags
= 0; /* FIXME */
5522 dwRequiredSize
+= dwSize
;
5532 *pcbBytesNeeded
= 0;
5538 /* Unlock the service database */
5539 ScmUnlockDatabase();
5541 DPRINT("REnumServicesStatusExW() done (Error %lu)\n", dwError
);
5548 DWORD
RSendTSMessage(
5549 handle_t BindingHandle
) /* FIXME */
5552 return ERROR_CALL_NOT_IMPLEMENTED
;
5557 DWORD
RCreateServiceWOW64A(
5558 handle_t BindingHandle
,
5559 LPSTR lpServiceName
,
5560 LPSTR lpDisplayName
,
5561 DWORD dwDesiredAccess
,
5562 DWORD dwServiceType
,
5564 DWORD dwErrorControl
,
5565 LPSTR lpBinaryPathName
,
5566 LPSTR lpLoadOrderGroup
,
5568 LPBYTE lpDependencies
,
5570 LPSTR lpServiceStartName
,
5573 LPSC_RPC_HANDLE lpServiceHandle
)
5576 return ERROR_CALL_NOT_IMPLEMENTED
;
5581 DWORD
RCreateServiceWOW64W(
5582 handle_t BindingHandle
,
5583 LPWSTR lpServiceName
,
5584 LPWSTR lpDisplayName
,
5585 DWORD dwDesiredAccess
,
5586 DWORD dwServiceType
,
5588 DWORD dwErrorControl
,
5589 LPWSTR lpBinaryPathName
,
5590 LPWSTR lpLoadOrderGroup
,
5592 LPBYTE lpDependencies
,
5594 LPWSTR lpServiceStartName
,
5597 LPSC_RPC_HANDLE lpServiceHandle
)
5600 return ERROR_CALL_NOT_IMPLEMENTED
;
5605 DWORD
RQueryServiceTagInfo(
5606 handle_t BindingHandle
) /* FIXME */
5609 return ERROR_CALL_NOT_IMPLEMENTED
;
5614 DWORD
RNotifyServiceStatusChange(
5615 SC_RPC_HANDLE hService
,
5616 SC_RPC_NOTIFY_PARAMS NotifyParams
,
5617 GUID
*pClientProcessGuid
,
5618 GUID
*pSCMProcessGuid
,
5619 PBOOL pfCreateRemoteQueue
,
5620 LPSC_NOTIFY_RPC_HANDLE phNotify
)
5623 return ERROR_CALL_NOT_IMPLEMENTED
;
5628 DWORD
RGetNotifyResults(
5629 SC_NOTIFY_RPC_HANDLE hNotify
,
5630 PSC_RPC_NOTIFY_PARAMS_LIST
*ppNotifyParams
)
5633 return ERROR_CALL_NOT_IMPLEMENTED
;
5638 DWORD
RCloseNotifyHandle(
5639 LPSC_NOTIFY_RPC_HANDLE phNotify
,
5643 return ERROR_CALL_NOT_IMPLEMENTED
;
5648 DWORD
RControlServiceExA(
5649 SC_RPC_HANDLE hService
,
5654 return ERROR_CALL_NOT_IMPLEMENTED
;
5659 DWORD
RControlServiceExW(
5660 SC_RPC_HANDLE hService
,
5665 return ERROR_CALL_NOT_IMPLEMENTED
;
5670 DWORD
RSendPnPMessage(
5671 handle_t BindingHandle
) /* FIXME */
5674 return ERROR_CALL_NOT_IMPLEMENTED
;
5679 DWORD
RValidatePnPService(
5680 handle_t BindingHandle
) /* FIXME */
5683 return ERROR_CALL_NOT_IMPLEMENTED
;
5688 DWORD
ROpenServiceStatusHandle(
5689 handle_t BindingHandle
) /* FIXME */
5692 return ERROR_CALL_NOT_IMPLEMENTED
;
5698 handle_t BindingHandle
) /* FIXME */
5701 return ERROR_CALL_NOT_IMPLEMENTED
;
5705 void __RPC_FAR
* __RPC_USER
midl_user_allocate(SIZE_T len
)
5707 return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, len
);
5711 void __RPC_USER
midl_user_free(void __RPC_FAR
* ptr
)
5713 HeapFree(GetProcessHeap(), 0, ptr
);
5717 void __RPC_USER
SC_RPC_HANDLE_rundown(SC_RPC_HANDLE hSCObject
)
5722 void __RPC_USER
SC_RPC_LOCK_rundown(SC_RPC_LOCK Lock
)
5727 void __RPC_USER
SC_NOTIFY_RPC_HANDLE_rundown(SC_NOTIFY_RPC_HANDLE hNotify
)