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.

225 lines
7.0 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: ThemeService.cpp
  3. //
  4. // Copyright (c) 2001, Microsoft Corporation
  5. //
  6. // This file contains functions that are called from the shell services DLL
  7. // to interact with the theme service.
  8. //
  9. // History: 2001-01-02 vtan created
  10. // --------------------------------------------------------------------------
  11. #include "StandardHeader.h"
  12. #include "ThemeService.h"
  13. #include <shlwapi.h>
  14. #include <shlwapip.h>
  15. #include "Resource.h"
  16. #include "ThemeManagerAPIRequest.h"
  17. #include "ThemeManagerService.h"
  18. #include "ThemeServerClient.h"
  19. extern HINSTANCE g_hInstance;
  20. // --------------------------------------------------------------------------
  21. // CThemeService::Main
  22. //
  23. // Arguments: See the platform SDK under DllMain.
  24. //
  25. // Returns: See the platform SDK under DllMain.
  26. //
  27. // Purpose: Performs initialization and clean up on process attach and
  28. // detach. Not interested in anything else.
  29. //
  30. // History: 2000-10-12 vtan created
  31. // 2001-01-02 vtan scoped to a C++ class
  32. // --------------------------------------------------------------------------
  33. NTSTATUS CThemeService::Main (DWORD dwReason)
  34. {
  35. NTSTATUS status;
  36. switch (dwReason)
  37. {
  38. case DLL_PROCESS_ATTACH:
  39. status = CThemeManagerAPIRequest::StaticInitialize();
  40. if (NT_SUCCESS(status))
  41. {
  42. status = CThemeServerClient::StaticInitialize();
  43. }
  44. break;
  45. case DLL_PROCESS_DETACH:
  46. TSTATUS(CThemeServerClient::StaticTerminate());
  47. TSTATUS(CThemeManagerAPIRequest::StaticTerminate());
  48. status = STATUS_SUCCESS;
  49. break;
  50. default:
  51. status = STATUS_SUCCESS;
  52. break;
  53. }
  54. return(status);
  55. }
  56. // --------------------------------------------------------------------------
  57. // CThemeService::DllRegisterServer
  58. //
  59. // Arguments: <none>
  60. //
  61. // Returns: NTSTATUS
  62. //
  63. // Purpose: Register entry point to allow the theme server to install
  64. // itself into the registry.
  65. //
  66. // History: 2000-11-28 vtan created
  67. // 2001-01-02 vtan scoped to a C++ class
  68. // --------------------------------------------------------------------------
  69. NTSTATUS CThemeService::RegisterServer (void)
  70. {
  71. NTSTATUS status;
  72. status = STATUS_SUCCESS;
  73. // In upgrade cases, remove our old name service from both 32 & 64 bit systems
  74. (NTSTATUS)CService::Remove(TEXT("ThemeService"));
  75. #ifdef _WIN64
  76. // In upgrade cases for 64-bit, remove our current name service
  77. (NTSTATUS)CService::Remove(CThemeManagerService::GetName());
  78. #else
  79. // This is 32-bit only. Check if this is REALLY 32-bit and not 32-bit on 64-bit.
  80. if (!IsOS(OS_WOW6432))
  81. {
  82. // Prepare the failure actions, in order to get the service to restart automatically
  83. SC_ACTION ac[3];
  84. ac[0].Type = SC_ACTION_RESTART;
  85. ac[0].Delay = 60000;
  86. ac[1].Type = SC_ACTION_RESTART;
  87. ac[1].Delay = 60000;
  88. ac[2].Type = SC_ACTION_NONE;
  89. ac[2].Delay = 0;
  90. SERVICE_FAILURE_ACTIONS sf;
  91. sf.dwResetPeriod = 86400;
  92. sf.lpRebootMsg = NULL;
  93. sf.lpCommand = NULL;
  94. sf.cActions = 3;
  95. sf.lpsaActions = ac;
  96. // Now install the new service by name.
  97. status = CService::Install(CThemeManagerService::GetName(),
  98. TEXT("%SystemRoot%\\System32\\svchost.exe -k netsvcs"),
  99. TEXT("UIGroup"),
  100. NULL,
  101. TEXT("shsvcs.dll"),
  102. NULL,
  103. TEXT("netsvcs"),
  104. TEXT("ThemeServiceMain"),
  105. SERVICE_AUTO_START,
  106. g_hInstance,
  107. IDS_THEMESERVER_DISPLAYNAME,
  108. IDS_THEMESERVER_DESCRIPTION,
  109. &sf);
  110. }
  111. #endif
  112. return(status);
  113. }
  114. // --------------------------------------------------------------------------
  115. // CThemeService::DllUnregisterServer
  116. //
  117. // Arguments: <none>
  118. //
  119. // Returns: NTSTATUS
  120. //
  121. // Purpose: Unregister entry point to allow the theme server to uninstall
  122. // itself from the registry.
  123. //
  124. // History: 2000-11-28 vtan created
  125. // 2001-01-02 vtan scoped to a C++ class
  126. // --------------------------------------------------------------------------
  127. NTSTATUS CThemeService::UnregisterServer (void)
  128. {
  129. // Ignore any "not found", etc errors.
  130. (NTSTATUS)CService::Remove(CThemeManagerService::GetName());
  131. return(STATUS_SUCCESS);
  132. }
  133. // --------------------------------------------------------------------------
  134. // ::ThemeServiceMain
  135. //
  136. // Arguments: dwArgc = Number of arguments.
  137. // lpszArgv = Argument array.
  138. //
  139. // Returns: <none>
  140. //
  141. // Purpose: ServiceMain entry point for theme server.
  142. //
  143. // History: 2000-11-28 vtan created
  144. // 2001-01-02 vtan scoped to the theme service
  145. // --------------------------------------------------------------------------
  146. void WINAPI ThemeServiceMain (DWORD dwArgc, LPWSTR *lpszArgv)
  147. {
  148. UNREFERENCED_PARAMETER(dwArgc);
  149. UNREFERENCED_PARAMETER(lpszArgv);
  150. NTSTATUS status;
  151. status = CThemeManagerAPIRequest::InitializeServerChangeNumber();
  152. if (NT_SUCCESS(status))
  153. {
  154. CThemeManagerAPIServer *pThemeManagerAPIServer;
  155. // Bring in shell32.dll NOW so that when CheckThemeSignature is called
  156. // and it tries to use SHGetFolderPath it won't cause shell32.dll to be
  157. // brought in while impersonating a user. This will cause advapi32.dll
  158. // to leak a key to the user's hive that won't get cleaned up at logoff.
  159. CModule hModule(TEXT("shell32.dll"));
  160. pThemeManagerAPIServer = new CThemeManagerAPIServer;
  161. if (pThemeManagerAPIServer != NULL)
  162. {
  163. CAPIConnection *pAPIConnection;
  164. pAPIConnection = new CAPIConnection(pThemeManagerAPIServer);
  165. if (pAPIConnection != NULL)
  166. {
  167. CThemeManagerService *pThemeManagerService;
  168. pThemeManagerService = new CThemeManagerService(pAPIConnection, pThemeManagerAPIServer);
  169. if (pThemeManagerService != NULL)
  170. {
  171. CThemeManagerSessionData::SetAPIConnection(pAPIConnection);
  172. TSTATUS(CThemeManagerAPIRequest::ArrayInitialize());
  173. pThemeManagerService->Start();
  174. pThemeManagerService->Release();
  175. TSTATUS(CThemeManagerAPIRequest::ArrayTerminate());
  176. CThemeManagerSessionData::ReleaseAPIConnection();
  177. }
  178. pAPIConnection->Release();
  179. }
  180. pThemeManagerAPIServer->Release();
  181. }
  182. }
  183. }