Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. FixServiceStartupCircularDependency.cpp
  5. Abstract:
  6. Hooks the call to CreateServiceA and changes the start parameter for
  7. only the service passed in COMMAND_LINE from SERVICE_AUTO_START to
  8. SERVICE_SYSTEM_START. This eliminates a circular dependency during
  9. boot up which results in XP taking 15 to 20 minutes to boot.
  10. Notes:
  11. This is a general purpose shim. Pass the service name in the command
  12. line. It tests if the startup type for that service is SERVICE_AUTO_START
  13. and if so changes it to SERVICE_SYSTEM_START.
  14. History:
  15. 02/19/2001 a-brienw Created
  16. 02/20/2001 a-brienw Changed it to a general purpose shim using the command
  17. line to pass in the service name.
  18. --*/
  19. #include "precomp.h"
  20. IMPLEMENT_SHIM_BEGIN(FixServiceStartupCircularDependency)
  21. #include "ShimHookMacro.h"
  22. APIHOOK_ENUM_BEGIN
  23. APIHOOK_ENUM_ENTRY(CreateServiceA)
  24. APIHOOK_ENUM_END
  25. /*++
  26. Hook CreateServiceA to change the start parameter for the required service.
  27. --*/
  28. SC_HANDLE
  29. APIHook_CreateServiceA(
  30. SC_HANDLE hSCManager, // handle to SCM database
  31. LPCSTR lpServiceName, // name of service to start
  32. LPCSTR lpDisplayName, // display name
  33. DWORD dwDesiredAccess, // type of access to service
  34. DWORD dwServiceType, // type of service
  35. DWORD dwStartType, // when to start service
  36. DWORD dwErrorControl, // severity of service failure
  37. LPCSTR lpBinaryPathName, // name of binary file
  38. LPCSTR lpLoadOrderGroup, // name of load ordering group
  39. LPDWORD lpdwTagId, // tag identifier
  40. LPCSTR lpDependencies, // array of dependency names
  41. LPCSTR lpServiceStartName, // account name
  42. LPCSTR lpPassword // account password
  43. )
  44. {
  45. /*
  46. Only change it if it is currently SERVICE_AUTO_START. Do not change
  47. the IF statement to read != as there are other startup types which do
  48. not result in a circular dependency.
  49. */
  50. if (dwStartType == SERVICE_AUTO_START &&
  51. !_tcsicmp(lpServiceName,COMMAND_LINE))
  52. {
  53. LOGN( eDbgLevelInfo,
  54. "[CreateServiceA] Fixed startup type: %s.", lpServiceName);
  55. dwStartType = SERVICE_SYSTEM_START;
  56. }
  57. return ORIGINAL_API(CreateServiceA)(hSCManager, lpServiceName,
  58. lpDisplayName, dwDesiredAccess, dwServiceType, dwStartType,
  59. dwErrorControl, lpBinaryPathName, lpLoadOrderGroup, lpdwTagId,
  60. lpDependencies, lpServiceStartName, lpPassword);
  61. }
  62. /*++
  63. Register hooked functions
  64. --*/
  65. HOOK_BEGIN
  66. APIHOOK_ENTRY(ADVAPI32.DLL, CreateServiceA)
  67. HOOK_END
  68. IMPLEMENT_SHIM_END