25#define MANAGER_TAG 0x72674D68
26#define SERVICE_TAG 0x63765368
27#define INVALID_TAG 0xAABBCCDD
50#define SC_MANAGER_READ \
51 (STANDARD_RIGHTS_READ | \
52 SC_MANAGER_QUERY_LOCK_STATUS | \
53 SC_MANAGER_ENUMERATE_SERVICE)
55#define SC_MANAGER_WRITE \
56 (STANDARD_RIGHTS_WRITE | \
57 SC_MANAGER_MODIFY_BOOT_CONFIG | \
58 SC_MANAGER_CREATE_SERVICE)
60#define SC_MANAGER_EXECUTE \
61 (STANDARD_RIGHTS_EXECUTE | \
63 SC_MANAGER_ENUMERATE_SERVICE | \
64 SC_MANAGER_CONNECT | \
65 SC_MANAGER_CREATE_SERVICE)
69 (STANDARD_RIGHTS_READ | \
70 SERVICE_INTERROGATE | \
71 SERVICE_ENUMERATE_DEPENDENTS | \
72 SERVICE_QUERY_STATUS | \
75#define SERVICE_WRITE \
76 (STANDARD_RIGHTS_WRITE | \
77 SERVICE_CHANGE_CONFIG)
79#define SERVICE_EXECUTE \
80 (STANDARD_RIGHTS_EXECUTE | \
81 SERVICE_USER_DEFINED_CONTROL | \
82 SERVICE_PAUSE_CONTINUE | \
86#define TAG_ARRAY_SIZE 32
111 DPRINT(
"ScmStartRpcServer() called\n");
119 DPRINT1(
"RpcServerUseProtseqEpW() failed (Status %lx)\n",
Status);
128 DPRINT1(
"RpcServerRegisterIf() failed (Status %lx)\n",
Status);
139 DPRINT(
"ScmStartRpcServer() done\n");
149 if (lpDatabaseName ==
NULL)
154 DPRINT(
"Database %S, does not exist\n", lpDatabaseName);
159 DPRINT(
"Invalid Database name %S\n", lpDatabaseName);
171 wcscpy(
Ptr->DatabaseName, lpDatabaseName);
193 Ptr->ServiceEntry = lpServiceEntry;
213 DPRINT1(
"Exception: Invalid Service Manager handle\n");
233 DPRINT1(
"Exception: Invalid Service handle\n");
243 DWORD dwDesiredAccess)
276 DWORD dwGroupTagCount = 0;
279 DWORD dwTagUsedBase = 1;
291 L"System\\CurrentControlSet\\Control\\GroupOrderList",
328 if (cbDataSize <
sizeof(pdwGroupTags[0]))
331 dwGroupTagCount =
min(pdwGroupTags[0], cbDataSize /
sizeof(pdwGroupTags[0]) - 1);
341 for (
i = 1;
i <= dwGroupTagCount;
i++)
343 nTagOffset = pdwGroupTags[
i] - dwTagUsedBase;
345 TagUsed[nTagOffset] =
TRUE;
356 nTagOffset = CurrentService->
dwTag - dwTagUsedBase;
358 TagUsed[nTagOffset] =
TRUE;
361 ServiceEntry = ServiceEntry->
Flink;
369 dwFreeTag = dwTagUsedBase +
i;
375 }
while (!dwFreeTag);
386 lpService->
dwTag = dwFreeTag;
387 DPRINT(
"Assigning new tag %lu to service %S in group %S\n",
393 DPRINT1(
"Failed to assign new tag to service %S, error=%lu\n",
405 SIZE_T ServiceNameLen, ExpandedLen;
412 HANDLE SymbolicLinkHandle;
419 *RelativeName =
NULL;
424 if (ServiceNameLen > 12 &&
429 (ServiceNameLen + 1) *
sizeof(
WCHAR));
430 if (*RelativeName ==
NULL)
432 DPRINT(
"Error allocating memory for boot driver name\n");
439 DPRINT(
"Bootdriver name %S\n", *RelativeName);
444 if (ServiceNameLen > 13 &&
450 ServiceNameLen *
sizeof(
WCHAR));
452 if (*RelativeName ==
NULL)
454 DPRINT(
"Error allocating memory for boot driver name\n");
459 wcscpy(*RelativeName,
L"\\SystemRoot\\");
462 DPRINT(
"Bootdriver name %S\n", *RelativeName);
470 DPRINT(
"Error during a call to ExpandEnvironmentStringsW()\n");
480 DPRINT(
"Error allocating memory for boot driver name\n");
488 DPRINT(
"Error during a call to ExpandEnvironmentStringsW()\n");
496 DPRINT(
"Error during a call to RtlDosPathNameToNtPathName_U()\n");
500 DPRINT(
"Converted to NT-style %wZ\n", &NtPathName);
511 DPRINT(
"Error allocating memory for boot driver name\n");
521 if (ServiceNameLen > ExpandedLen &&
529 (ServiceNameLen - ExpandedLen) *
sizeof(
WCHAR) + 13*
sizeof(
WCHAR));
530 if (*RelativeName ==
NULL)
532 DPRINT(
"Error allocating memory for boot driver name\n");
536 wcscpy(*RelativeName,
L"\\SystemRoot\\");
557 DPRINT(
"Opened symbolic link object\n");
566 DPRINT(
"Too large buffer required\n");
580 DPRINT(
"Unable to alloc buffer\n");
593 if ((ServiceNameLen > ExpandedLen) &&
598 (ServiceNameLen - ExpandedLen) *
sizeof(
WCHAR) + 13*
sizeof(
WCHAR));
600 if (*RelativeName ==
NULL)
602 DPRINT(
"Unable to alloc buffer\n");
608 wcscpy(*RelativeName,
L"\\SystemRoot\\");
643 const wchar_t *lpServiceName,
644 wchar_t **lpCanonName)
653 ServiceNameLen =
wcslen(lpServiceName);
656 if (ServiceNameLen > 12 &&
657 !
_wcsnicmp(
L"\\SystemRoot\\", lpServiceName, 12))
662 (ServiceNameLen + 1) *
sizeof(
WCHAR));
664 if (*lpCanonName ==
NULL)
666 DPRINT(
"Error allocating memory for canonized service name\n");
677 DPRINT(
"Canonicalized name %S\n", *lpCanonName);
682 if (ServiceNameLen > 13 &&
683 !
_wcsnicmp(
L"%SystemRoot%\\", lpServiceName, 13))
688 (ServiceNameLen + 1) *
sizeof(
WCHAR));
690 if (*lpCanonName ==
NULL)
692 DPRINT(
"Error allocating memory for canonized service name\n");
698 wcscpy(*lpCanonName,
L"\\SystemRoot\\");
700 wcscat(*lpCanonName, lpServiceName + 13);
702 DPRINT(
"Canonicalized name %S\n", *lpCanonName);
707 if (lpServiceName[0] !=
L'\\' && lpServiceName[1] !=
L':')
711 (ServiceNameLen + 1) *
sizeof(
WCHAR));
713 if (*lpCanonName ==
NULL)
715 DPRINT(
"Error allocating memory for canonized service name\n");
720 wcscpy(*lpCanonName, lpServiceName);
728 DPRINT(
"RtlDosPathNameToNtPathName_U() failed\n");
736 if (*lpCanonName ==
NULL)
738 DPRINT(
"Error allocating memory for canonized service name\n");
751 DPRINT(
"Canonicalized name %S\n", *lpCanonName);
761 DPRINT(
"Error converting named\n");
768 wcscpy(*lpCanonName, RelativeName + 12);
773 DPRINT(
"Canonicalized name %S\n", *lpCanonName);
785 DWORD dwServiceState,
793 WCHAR *lpszNameBuf = szNameBuf;
794 WCHAR *lpszValueBuf = szValueBuf;
799 HKEY hServiceEnumKey;
801 DWORD dwDependServiceStrPtr = 0;
802 DWORD dwRequiredSize = 0;
819 DPRINT(
"ERROR! Unable to get number of services keys\n");
824 for (dwIteration = 0; dwIteration < dwNumSubKeys; dwIteration++)
862 dwDependServiceStrPtr = 0;
865 while (
wcslen(lpszValueBuf + dwDependServiceStrPtr) > 0)
873 if (!lpCurrentService)
876 DPRINT(
"This should not happen at this point, report to Developer\n");
885 if ((dwCurrentServiceState == dwServiceState) ||
894 dwRequiredSize += (2 *
sizeof(
PVOID));
912 lpServices[*lpServicesReturned] = lpCurrentService;
914 *lpServicesReturned = *lpServicesReturned + 1;
918 dwDependServiceStrPtr += (
DWORD)(
wcslen(lpszValueBuf + dwDependServiceStrPtr) + 1);
945 DWORD dwServicesReturned = 0;
947 DPRINT(
"RCloseServiceHandle() called\n");
949 DPRINT(
"hSCObject = %p\n", *hSCObject);
957 if (hManager !=
NULL)
959 DPRINT(
"Found manager handle\n");
969 DPRINT(
"RCloseServiceHandle() done\n");
972 else if (hService !=
NULL)
974 DPRINT(
"Found service handle\n");
992 DPRINT(
"CloseServiceHandle - lpService->dwRefCount %u\n",
1003 L"System\\CurrentControlSet\\Services",
1009 DPRINT(
"Failed to open services key\n");
1020 &dwServicesReturned);
1025 DPRINT(
"Deletion failed due to running dependencies\n");
1042 DPRINT(
"Failed to Delete the Service Registry key\n");
1056 DPRINT(
"RCloseServiceHandle() done\n");
1079 DWORD dwServicesReturned = 0;
1080 DWORD dwControlsAccepted;
1081 DWORD dwCurrentState;
1084 WCHAR szLogBuffer[80];
1087 DPRINT(
"RControlService() called\n");
1096 DPRINT1(
"Invalid service handle\n");
1102 if (lpService ==
NULL)
1104 DPRINT1(
"lpService == NULL\n");
1130 if (dwControl >= 128 && dwControl <= 255)
1153 L"System\\CurrentControlSet\\Services",
1159 DPRINT(
"Failed to open services key\n");
1169 &dwServicesReturned);
1177 DPRINT(
"Service has running dependencies. Failed to stop service\n");
1199 switch (dwCurrentState)
1288 lpLogStrings[1] = szLogBuffer;
1311 DPRINT(
"RDeleteService() called\n");
1319 DPRINT1(
"Invalid service handle\n");
1328 if (lpService ==
NULL)
1330 DPRINT(
"lpService == NULL\n");
1339 DPRINT(
"Service has already been marked for delete\n");
1353 DPRINT(
"RDeleteService() done\n");
1368 DPRINT(
"RLockServiceDatabase() called\n");
1375 DPRINT1(
"Invalid service manager handle\n");
1393 LPBYTE lpSecurityDescriptor,
1401 DWORD dwBytesNeeded;
1404 DPRINT(
"RQueryServiceObjectSecurity() called\n");
1409 DPRINT1(
"Invalid service handle\n");
1429 if (lpService ==
NULL)
1431 DPRINT(
"lpService == NULL\n");
1440 dwSecurityInformation,
1476 DWORD dwSecurityInformation,
1477 LPBYTE lpSecurityDescriptor,
1478 DWORD dwSecurityDescriptorSize)
1489 DPRINT(
"RSetServiceObjectSecurity() called\n");
1494 DPRINT1(
"Invalid service handle\n");
1498 if (dwSecurityInformation == 0 ||
1537 if (lpService ==
NULL)
1539 DPRINT1(
"lpService == NULL\n");
1573 bDatabaseLocked =
TRUE;
1589 if (hServiceKey !=
NULL)
1593 if (bDatabaseLocked ==
TRUE)
1599 DPRINT(
"RSetServiceObjectSecurity() done (Error %lu)\n", dwError);
1615 DPRINT(
"RQueryServiceStatus() called\n");
1623 DPRINT1(
"Invalid service handle\n");
1635 if (lpService ==
NULL)
1637 DPRINT(
"lpService == NULL\n");
1659 switch (dwCurrentState)
1684 DWORD dwPreviousState;
1685 DWORD dwPreviousType;
1687 WCHAR szLogBuffer[80];
1690 DPRINT(
"RSetServiceStatus() called\n");
1702 DPRINT(
"hServiceStatus == NULL\n");
1711 DPRINT(
"Invalid service state\n");
1719 DPRINT(
"Invalid service type\n");
1726 DPRINT(
"Invalid controls accepted\n");
1775 lpService->lpImage =
NULL;
1790 lpLogStrings[1] = szLogBuffer;
1820 lpLogStrings[1] = szLogBuffer;
1829 DPRINT(
"RSetServiceStatus() done\n");
1841 DPRINT(
"RUnlockServiceDatabase(%p)\n",
Lock);
1851 DWORD BootAcceptable)
1853 DPRINT(
"RNotifyBootConfigStatus(%p %lu)\n",
1854 lpMachineName, BootAcceptable);
1870 int bUpdateImmediately,
1875 DPRINT(
"RI_ScSetServiceBitsW(%p %lx %d %d %S)\n",
1877 bUpdateImmediately, lpString);
1882 if (lpString !=
NULL)
1887 DPRINT(
"hServiceStatus == NULL\n");
1922 DWORD dwServiceType,
1924 DWORD dwErrorControl,
1930 LPWSTR lpServiceStartName,
1943 DPRINT(
"RChangeServiceConfigW() called\n");
1944 DPRINT(
"dwServiceType = 0x%lx\n", dwServiceType);
1945 DPRINT(
"dwStartType = %lu\n", dwStartType);
1946 DPRINT(
"dwErrorControl = %lu\n", dwErrorControl);
1947 DPRINT(
"lpBinaryPathName = %S\n", lpBinaryPathName);
1948 DPRINT(
"lpLoadOrderGroup = %S\n", lpLoadOrderGroup);
1949 DPRINT(
"lpServiceStartName = %S\n", lpServiceStartName);
1950 DPRINT(
"lpPassword = %p\n", lpPassword);
1951 DPRINT(
"dwPwSite = %lu\n", dwPwSize);
1960 DPRINT1(
"Invalid service handle\n");
2011 if (lpdwTagId && (!lpLoadOrderGroup || !*lpLoadOrderGroup))
2017 if (lpService ==
NULL)
2019 DPRINT(
"lpService == NULL\n");
2028 DPRINT(
"Service has already been marked for delete\n");
2056 if (lpDisplayNameW ==
NULL)
2114 if (lpBinaryPathName !=
NULL && *lpBinaryPathName != 0)
2117 lpImagePathW = lpBinaryPathName;
2136 if (lpImagePathW != lpBinaryPathName)
2144 if (lpLoadOrderGroup !=
NULL && *lpLoadOrderGroup != 0)
2150 (
LPBYTE)lpLoadOrderGroup,
2162 if (lpdwTagId !=
NULL)
2177 *lpdwTagId = lpService->
dwTag;
2181 if (lpDependencies !=
NULL && *lpDependencies != 0)
2194 if (lpServiceStartName !=
NULL && *lpServiceStartName != 0)
2200 (
LPBYTE)lpServiceStartName,
2206 if (lpPassword !=
NULL)
2208 if (*(
LPWSTR)lpPassword != 0)
2214 &lpClearTextPassword);
2217 DPRINT1(
"ScmDecryptPassword failed (Error %lu)\n", dwError);
2220 DPRINT1(
"Clear text password: %S\n", lpClearTextPassword);
2224 lpClearTextPassword);
2227 DPRINT1(
"ScmSetServicePassword failed (Error %lu)\n", dwError);
2241 DPRINT1(
"ScmSetServicePassword failed (Error %lu)\n", dwError);
2249 if (lpClearTextPassword !=
NULL)
2253 (
wcslen(lpClearTextPassword) + 1) *
sizeof(
WCHAR));
2257 if (hServiceKey !=
NULL)
2263 DPRINT(
"RChangeServiceConfigW() done (Error %lu)\n", dwError);
2276 DWORD dwDesiredAccess,
2277 DWORD dwServiceType,
2279 DWORD dwErrorControl,
2293 SC_HANDLE hServiceHandle =
NULL;
2299 DPRINT(
"RCreateServiceW() called\n");
2300 DPRINT(
"lpServiceName = %S\n", lpServiceName);
2302 DPRINT(
"dwDesiredAccess = %lx\n", dwDesiredAccess);
2303 DPRINT(
"dwServiceType = 0x%lx\n", dwServiceType);
2304 DPRINT(
"dwStartType = %lu\n", dwStartType);
2305 DPRINT(
"dwErrorControl = %lu\n", dwErrorControl);
2306 DPRINT(
"lpBinaryPathName = %S\n", lpBinaryPathName);
2307 DPRINT(
"lpLoadOrderGroup = %S\n", lpLoadOrderGroup);
2308 DPRINT(
"lpdwTagId = %p\n", lpdwTagId);
2314 if (hManager ==
NULL)
2316 DPRINT1(
"Invalid service manager handle\n");
2324 DPRINT(
"Insufficient access rights! 0x%lx\n",
2329 if (*lpServiceName == 0)
2332 if (*lpBinaryPathName == 0)
2375 (lpServiceStartName))
2378 if (
wcsicmp(lpServiceStartName,
L"LocalSystem"))
2384 if (lpdwTagId && (!lpLoadOrderGroup || !*lpLoadOrderGroup))
2463 if (lpLoadOrderGroup !=
NULL && *lpLoadOrderGroup != 0)
2472 if (lpdwTagId !=
NULL)
2543 (
LPBYTE)lpBinaryPathName,
2561 if (lpLoadOrderGroup !=
NULL && *lpLoadOrderGroup != 0)
2567 (
LPBYTE)lpLoadOrderGroup,
2574 if (lpdwTagId !=
NULL)
2587 if (lpDependencies !=
NULL && *lpDependencies != 0)
2600 lpObjectName = (lpServiceStartName !=
NULL) ? (
LPWSTR)lpServiceStartName :
L"LocalSystem";
2610 if (lpPassword !=
NULL && *(
LPWSTR)lpPassword != 0)
2616 &lpClearTextPassword);
2622 lpClearTextPassword);
2649 DPRINT(
"CreateService - lpService->dwRefCount %u\n", lpService->
dwRefCount);
2655 if (hServiceKey !=
NULL)
2658 if (lpClearTextPassword !=
NULL)
2662 (
wcslen(lpClearTextPassword) + 1) *
sizeof(
WCHAR));
2668 DPRINT(
"hService %p\n", hServiceHandle);
2671 if (lpdwTagId !=
NULL)
2672 *lpdwTagId = lpService->
dwTag;
2676 if (lpService !=
NULL &&
2689 if (lpService !=
NULL)
2695 if (lpImagePath !=
NULL)
2698 DPRINT(
"RCreateServiceW() done (Error %lu)\n", dwError);
2709 DWORD dwServiceState,
2716 DWORD dwServicesReturned = 0;
2717 DWORD dwServiceCount;
2726 *lpServicesReturned = 0;
2728 DPRINT(
"REnumDependentServicesW() called\n");
2733 DPRINT1(
"Invalid service handle\n");
2743 DPRINT(
"Insufficient access rights! 0x%lx\n",
2750 L"System\\CurrentControlSet\\Services",
2763 &dwServicesReturned);
2777 (dwServicesReturned + 1) *
sizeof(
PSERVICE));
2778 if (!lpServicesArray)
2780 DPRINT1(
"Could not allocate buffer\n");
2785 dwServicesReturned = 0;
2793 &dwServicesReturned);
2803 for (dwServiceCount = 0; dwServiceCount < dwServicesReturned; dwServiceCount++)
2805 lpService = lpServicesArray[dwServiceCount];
2825 *lpServicesReturned = dwServicesReturned;
2828 if (lpServicesArray !=
NULL)
2833 DPRINT(
"REnumDependentServicesW() done (Error %lu)\n", dwError);
2844 DWORD dwServiceType,
2845 DWORD dwServiceState,
2871 DWORD dwDesiredAccess,
2877 DPRINT(
"ROpenSCManagerW() called\n");
2878 DPRINT(
"lpMachineName = %p\n", lpMachineName);
2879 DPRINT(
"lpMachineName: %S\n", lpMachineName);
2880 DPRINT(
"lpDataBaseName = %p\n", lpDatabaseName);
2881 DPRINT(
"lpDataBaseName: %S\n", lpDatabaseName);
2882 DPRINT(
"dwDesiredAccess = %x\n", dwDesiredAccess);
2894 DPRINT(
"ScmCreateManagerHandle() failed (Error %lu)\n", dwError);
2903 DPRINT(
"ScmCheckAccess() failed (Error %lu)\n", dwError);
2909 DPRINT(
"*hScm = %p\n", *lpScHandle);
2911 DPRINT(
"ROpenSCManagerW() done\n");
2923 DWORD dwDesiredAccess,
2931 DPRINT(
"ROpenServiceW() called\n");
2933 DPRINT(
"lpServiceName = %p\n", lpServiceName);
2934 DPRINT(
"lpServiceName: %S\n", lpServiceName);
2935 DPRINT(
"dwDesiredAccess = %x\n", dwDesiredAccess);
2941 if (hManager ==
NULL)
2943 DPRINT1(
"Invalid service manager handle\n");
2947 if (!lpServiceHandle)
2958 if (lpService ==
NULL)
2960 DPRINT(
"Could not find service\n");
2970 DPRINT(
"ScmCreateServiceHandle() failed (Error %lu)\n", dwError);
2979 DPRINT(
"ScmCheckAccess() failed (Error %lu)\n", dwError);
2988 DPRINT(
"*hService = %p\n", *lpServiceHandle);
2994 DPRINT(
"ROpenServiceW() done\n");
3017 DWORD dwDependenciesLength = 0;
3018 DWORD dwRequiredSize;
3021 DPRINT(
"RQueryServiceConfigW() called\n");
3029 DPRINT1(
"Invalid service handle\n");
3041 if (lpService ==
NULL)
3043 DPRINT(
"lpService == NULL\n");
3066 &lpServiceStartName);
3071 &dwDependenciesLength);
3075 if (lpImagePath !=
NULL)
3078 dwRequiredSize += 2 *
sizeof(
WCHAR);
3083 dwRequiredSize += 2 *
sizeof(
WCHAR);
3085 if (lpDependencies !=
NULL)
3086 dwRequiredSize += dwDependenciesLength *
sizeof(
WCHAR);
3088 dwRequiredSize += 2 *
sizeof(
WCHAR);
3090 if (lpServiceStartName !=
NULL)
3091 dwRequiredSize += (
DWORD)((
wcslen(lpServiceStartName) + 1) *
sizeof(
WCHAR));
3093 dwRequiredSize += 2 *
sizeof(
WCHAR);
3098 dwRequiredSize += 2 *
sizeof(
WCHAR);
3111 lpStr = (
LPWSTR)(lpServiceConfig + 1);
3114 if (lpImagePath !=
NULL)
3116 wcscpy(lpStr, lpImagePath);
3124 lpStr += (
wcslen(lpStr) + 1);
3137 lpStr += (
wcslen(lpStr) + 1);
3140 if (lpDependencies !=
NULL)
3144 dwDependenciesLength *
sizeof(
WCHAR));
3152 if (lpDependencies !=
NULL)
3153 lpStr += dwDependenciesLength;
3155 lpStr += (
wcslen(lpStr) + 1);
3158 if (lpServiceStartName !=
NULL)
3160 wcscpy(lpStr, lpServiceStartName);
3168 lpStr += (
wcslen(lpStr) + 1);
3190 if (lpImagePath !=
NULL)
3193 if (lpServiceStartName !=
NULL)
3196 if (lpDependencies !=
NULL)
3199 if (hServiceKey !=
NULL)
3202 DPRINT(
"RQueryServiceConfigW() done\n");
3219 DWORD dwRequiredSize;
3227 DPRINT1(
"Invalid service manager handle\n");
3266 DPRINT(
"RStartServiceW(%p %lu %p) called\n", hService,
argc,
argv);
3283 DPRINT1(
"Invalid service handle\n");
3295 if (lpService ==
NULL)
3297 DPRINT(
"lpService == NULL\n");
3329 DPRINT(
"RGetServiceDisplayNameW() called\n");
3331 DPRINT(
"lpServiceName: %S\n", lpServiceName);
3333 DPRINT(
"*lpcchBuffer: %lu\n", *lpcchBuffer);
3339 DPRINT(
"Invalid manager handle\n");
3346 if (lpService ==
NULL)
3348 DPRINT(
"Could not find service\n");
3391 DPRINT(
"RGetServiceKeyNameW() called\n");
3394 DPRINT(
"lpServiceName: %p\n", lpServiceName);
3395 DPRINT(
"*lpcchBuffer: %lu\n", *lpcchBuffer);
3401 DPRINT(
"Invalid manager handle\n");
3408 if (lpService ==
NULL)
3410 DPRINT(
"Could not find service\n");
3418 if (lpServiceName !=
NULL)
3441 int bUpdateImmediately,
3447 if (lpString !=
NULL)
3463 DWORD dwServiceType,
3465 DWORD dwErrorControl,
3466 LPSTR lpBinaryPathName,
3467 LPSTR lpLoadOrderGroup,
3471 LPSTR lpServiceStartName,
3482 DWORD dwDependenciesLength = 0;
3487 if (lpBinaryPathName)
3491 if (!lpBinaryPathNameW)
3499 if (lpLoadOrderGroup)
3503 if (!lpLoadOrderGroupW)
3513 lpStr = (
LPCSTR)lpDependencies;
3516 cchLength =
strlen(lpStr) + 1;
3517 dwDependenciesLength += (
DWORD)cchLength;
3518 lpStr = lpStr + cchLength;
3520 dwDependenciesLength++;
3523 if (!lpDependenciesW)
3531 if (lpServiceStartName)
3535 if (!lpServiceStartNameW)
3547 if (!lpDisplayNameW)
3563 dwDependenciesLength,
3564 lpServiceStartNameW,
3570 if (lpBinaryPathNameW !=
NULL)
3573 if (lpLoadOrderGroupW !=
NULL)
3576 if (lpDependenciesW !=
NULL)
3579 if (lpServiceStartNameW !=
NULL)
3582 if (lpDisplayNameW !=
NULL)
3594 LPSTR lpServiceName,
3596 DWORD dwDesiredAccess,
3597 DWORD dwServiceType,
3599 DWORD dwErrorControl,
3600 LPSTR lpBinaryPathName,
3601 LPSTR lpLoadOrderGroup,
3605 LPSTR lpServiceStartName,
3617 DWORD dwDependenciesLength = 0;
3626 if (!lpServiceNameW)
3638 if (!lpDisplayNameW)
3646 if (lpBinaryPathName)
3650 if (!lpBinaryPathNameW)
3658 if (lpLoadOrderGroup)
3662 if (!lpLoadOrderGroupW)
3672 lpStr = (
LPCSTR)lpDependencies;
3675 cchLength =
strlen(lpStr) + 1;
3676 dwDependenciesLength += (
DWORD)cchLength;
3677 lpStr = lpStr + cchLength;
3679 dwDependenciesLength++;
3682 if (!lpDependenciesW)
3690 if (lpServiceStartName)
3694 if (!lpServiceStartNameW)
3713 dwDependenciesLength,
3714 lpServiceStartNameW,
3720 if (lpServiceNameW !=
NULL)
3723 if (lpDisplayNameW !=
NULL)
3726 if (lpBinaryPathNameW !=
NULL)
3729 if (lpLoadOrderGroupW !=
NULL)
3732 if (lpDependenciesW !=
NULL)
3735 if (lpServiceStartNameW !=
NULL)
3747 DWORD dwServiceState,
3754 DWORD dwServicesReturned = 0;
3755 DWORD dwServiceCount;
3764 *lpServicesReturned = 0;
3766 DPRINT(
"REnumDependentServicesA() called\n");
3771 DPRINT1(
"Invalid service handle\n");
3781 DPRINT(
"Insufficient access rights! 0x%lx\n",
3788 L"System\\CurrentControlSet\\Services",
3806 &dwServicesReturned);
3820 (dwServicesReturned + 1) *
sizeof(
PSERVICE));
3821 if (!lpServicesArray)
3823 DPRINT(
"Could not allocate buffer\n");
3828 dwServicesReturned = 0;
3836 &dwServicesReturned);
3846 for (dwServiceCount = 0; dwServiceCount < dwServicesReturned; dwServiceCount++)
3848 lpService = lpServicesArray[dwServiceCount];
3865 lpStr +=
strlen(lpStr) + 1;
3877 lpStr +=
strlen(lpStr) + 1;
3882 *lpServicesReturned = dwServicesReturned;
3885 if (lpServicesArray)
3890 DPRINT(
"REnumDependentServicesA() done (Error %lu)\n", dwError);
3901 DWORD dwServiceType,
3902 DWORD dwServiceState,
3915 DWORD dwServiceCount;
3917 DPRINT(
"REnumServicesStatusA() called\n");
3929 DPRINT(
"Failed to allocate buffer\n");
3944 if (*lpServicesReturned == 0)
3947 lpStatusPtrIncrW = lpStatusPtrW;
3954 for (dwServiceCount = 0; dwServiceCount < *lpServicesReturned; dwServiceCount++)
3962 (
int)
wcslen(lpStringPtrW),
3967 lpStringPtrA +=
wcslen(lpStringPtrW) + 1;
3968 lpStringPtrW +=
wcslen(lpStringPtrW) + 1;
3976 (
int)
wcslen(lpStringPtrW),
3981 lpStringPtrA +=
wcslen(lpStringPtrW) + 1;
3982 lpStringPtrW +=
wcslen(lpStringPtrW) + 1;
3997 DPRINT(
"REnumServicesStatusA() done (Error %lu)\n", dwError);
4007 LPSTR lpMachineName,
4008 LPSTR lpDatabaseName,
4009 DWORD dwDesiredAccess,
4016 DPRINT(
"ROpenSCManagerA() called\n");
4046 LPSTR lpServiceName,
4047 DWORD dwDesiredAccess,
4053 DPRINT(
"ROpenServiceA() called\n");
4088 DWORD dwDependenciesLength = 0;
4089 DWORD dwRequiredSize;
4092 DPRINT(
"RQueryServiceConfigA() called\n");
4100 DPRINT1(
"Invalid service handle\n");
4112 if (lpService ==
NULL)
4114 DPRINT(
"lpService == NULL\n");
4137 &lpServiceStartName);
4142 &dwDependenciesLength);
4146 if (lpImagePath !=
NULL)
4147 dwRequiredSize += (
DWORD)(
wcslen(lpImagePath) + 1);
4149 dwRequiredSize += 2 *
sizeof(
CHAR);
4154 dwRequiredSize += 2 *
sizeof(
CHAR);
4157 if (lpDependencies !=
NULL)
4158 dwRequiredSize += dwDependenciesLength;
4160 dwRequiredSize += 2 *
sizeof(
CHAR);
4162 if (lpServiceStartName !=
NULL)
4163 dwRequiredSize += (
DWORD)(
wcslen(lpServiceStartName) + 1);
4165 dwRequiredSize += 2 *
sizeof(
CHAR);
4170 dwRequiredSize += 2 *
sizeof(
CHAR);
4183 lpStr = (
LPSTR)(lpServiceConfig + 1);
4195 (
int)(
wcslen(lpImagePath) + 1),
4224 lpStr += (
strlen(lpStr) + 1);
4232 dwDependenciesLength,
4234 dwDependenciesLength,
4245 lpStr += dwDependenciesLength;
4247 lpStr += (
strlen(lpStr) + 1);
4249 if (lpServiceStartName)
4256 (
int)(
wcslen(lpServiceStartName) + 1),
4266 lpStr += (
strlen(lpStr) + 1);
4294 if (lpImagePath !=
NULL)
4297 if (lpServiceStartName !=
NULL)
4300 if (lpDependencies !=
NULL)
4303 if (hServiceKey !=
NULL)
4306 DPRINT(
"RQueryServiceConfigA() done\n");
4323 DWORD dwRequiredSize;
4331 DPRINT1(
"Invalid service manager handle\n");
4370 DPRINT(
"RStartServiceA() called\n");
4378 DPRINT1(
"Invalid service handle\n");
4390 if (lpService ==
NULL)
4392 DPRINT(
"lpService == NULL\n");
4408 if (lpVector ==
NULL)
4423 if (lpVector[
i] ==
NULL)
4443 if (lpVector !=
NULL)
4447 if (lpVector[
i] !=
NULL)
4472 DPRINT(
"RGetServiceDisplayNameA() called\n");
4474 DPRINT(
"lpServiceName: %s\n", lpServiceName);
4476 DPRINT(
"*lpcchBuffer: %lu\n", *lpcchBuffer);
4482 DPRINT(
"Invalid manager handle\n");
4488 if (lpServiceName !=
NULL)
4494 if (!lpServiceNameW)
4509 if (lpService ==
NULL)
4511 DPRINT(
"Could not find service\n");
4585 LPSTR lpServiceName,
4593 DPRINT(
"RGetServiceKeyNameA() called\n");
4596 DPRINT(
"lpServiceName: %p\n", lpServiceName);
4597 DPRINT(
"*lpcchBuffer: %lu\n", *lpcchBuffer);
4603 DPRINT(
"Invalid manager handle\n");
4614 if (!lpDisplayNameW)
4628 if (lpService ==
NULL)
4630 DPRINT(
"Could not find service\n");
4643 if (lpServiceName !=
NULL &&
4705 DPRINT(
"RI_ScGetCurrentGroupStateW() called\n");
4711 if (hManager ==
NULL)
4713 DPRINT1(
"Invalid service manager handle\n");
4721 DPRINT(
"Insufficient access rights! 0x%lx\n",
4731 if (pServiceGroup ==
NULL)
4744 DPRINT(
"RI_ScGetCurrentGroupStateW() done (Error %lu)\n", dwError);
4755 DWORD dwServiceType,
4756 DWORD dwServiceState,
4770 DWORD dwRequiredSize;
4771 DWORD dwServiceCount;
4773 DWORD dwLastResumeCount = 0;
4777 DPRINT(
"REnumServiceGroupW() called\n");
4783 if (hManager ==
NULL)
4785 DPRINT1(
"Invalid service manager handle\n");
4795 *lpServicesReturned = 0;
4797 if ((dwServiceType == 0) ||
4800 DPRINT(
"Invalid Service Type\n");
4804 if ((dwServiceState == 0) ||
4807 DPRINT(
"Invalid Service State\n");
4815 DPRINT(
"Insufficient access rights! 0x%lx\n",
4821 dwLastResumeCount = *lpResumeIndex;
4827 if (lpService ==
NULL)
4838 ServiceEntry = ServiceEntry->
Flink)
4851 if ((dwState & dwServiceState) == 0)
4856 if (*pszGroupName == 0)
4880 dwRequiredSize +=
dwSize;
4885 DPRINT(
"dwRequiredSize: %lu\n", dwRequiredSize);
4886 DPRINT(
"dwServiceCount: %lu\n", dwServiceCount);
4890 ServiceEntry = ServiceEntry->
Flink)
4903 if ((dwState & dwServiceState) == 0)
4908 if (*pszGroupName == 0)
4910 if (CurrentService->