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.

238 lines
6.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: M S C A P P L Y . C P P
  7. //
  8. // Contents: Functions called when MSClient is applied.
  9. //
  10. // Notes:
  11. //
  12. // Author: danielwe 25 Feb 1997
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include <ncxbase.h>
  18. #include "ncnetcfg.h"
  19. #include "mscliobj.h"
  20. #include "ncmisc.h"
  21. #include "ncsvc.h"
  22. //+---------------------------------------------------------------------------
  23. //
  24. // Member: CMSClient::HrApplyChanges
  25. //
  26. // Purpose: Writes out changes that occurred during the lifetime of our
  27. // object.
  28. //
  29. // Arguments:
  30. // (none)
  31. //
  32. // Returns: HRESULT, Error code.
  33. //
  34. // Author: danielwe 25 Feb 1997
  35. //
  36. // Notes: This will do several things.
  37. // 1) Set info for the RPC nameservice and security service that
  38. // was indicated by the UI for the RPC config dialog.
  39. // 2) Set the parameters for the browser configuration to the
  40. // registry.
  41. //
  42. // If no changes were detected, this will do nothing.
  43. //
  44. HRESULT CMSClient::HrApplyChanges()
  45. {
  46. HRESULT hr;
  47. // Write out any changes to RPC info
  48. hr = HrSetRPCRegistryInfo();
  49. if (SUCCEEDED(hr))
  50. {
  51. // Write out any changes to Browser info
  52. hr = HrSetBrowserRegistryInfo();
  53. }
  54. if (SUCCEEDED(hr) && (m_fOneTimeInstall || m_fUpgradeFromWks))
  55. {
  56. // Note: This function will do the workstation/server detection,
  57. // and won't install if we're running the workstation build.
  58. //
  59. hr = HrInstallDfs();
  60. }
  61. TraceError("CMSClient::HrApplyChanges", hr);
  62. return hr;
  63. }
  64. static const CHAR c_szaDfsCheck[] = "DfsCheckForOldDfsService";
  65. static const CHAR c_szaDfsSetupDfs[] = "DfsSetupDfs";
  66. static const WCHAR c_szDfsSetupDll[] = L"dfssetup.dll";
  67. typedef BOOLEAN (APIENTRY *PDFSCHECKFOROLDDFSSERVICE)(void);
  68. typedef DWORD (APIENTRY *PDFSSETUPDFS)(DWORD, PSTR, PSTR *);
  69. //+---------------------------------------------------------------------------
  70. //
  71. // Function: HrInstallDfs
  72. //
  73. // Purpose: Take care of installation of DFS components
  74. //
  75. // Arguments:
  76. // (none)
  77. //
  78. // Returns: Win32 HRESULT if failure.
  79. //
  80. // Author: danielwe 23 Jul 1997
  81. //
  82. // Notes: Shortcut creation is handled by this function and not
  83. // the netmscli.inf file because it is conditional on whether
  84. // the DFS components are installed.
  85. //
  86. HRESULT HrInstallDfs()
  87. {
  88. HRESULT hr = S_OK;
  89. PRODUCT_FLAVOR pf; // Server/Workstation
  90. // Get the product flavor (PF_WORKSTATION or PF_SERVER). Use this
  91. // to decide whether or not we need to install DFS.
  92. //
  93. GetProductFlavor(NULL, &pf);
  94. if (PF_SERVER == pf)
  95. {
  96. PDFSCHECKFOROLDDFSSERVICE pfnDfsCheckForOldDfsService = NULL;
  97. HMODULE hMod = NULL;
  98. TraceTag(ttidMSCliCfg, "Attempting to install DFS, since we're in a "
  99. "server install");
  100. hr = HrLoadLibAndGetProc(c_szDfsSetupDll, c_szaDfsCheck, &hMod,
  101. reinterpret_cast<FARPROC *>(&pfnDfsCheckForOldDfsService));
  102. if (SUCCEEDED(hr))
  103. {
  104. NC_TRY
  105. {
  106. AssertSz(hMod, "Module handle cannot be NULL!");
  107. BOOL fDFSInstalled = pfnDfsCheckForOldDfsService();
  108. // If DFS is not installed, go ahead and install it now.
  109. if (!fDFSInstalled)
  110. {
  111. PDFSSETUPDFS pfnDfsSetupDfs = NULL;
  112. hr = HrGetProcAddress(hMod, c_szaDfsSetupDfs,
  113. reinterpret_cast<FARPROC *>(&pfnDfsSetupDfs));
  114. if (SUCCEEDED(hr))
  115. {
  116. PSTR szResult = NULL;
  117. if (!pfnDfsSetupDfs(0, NULL, &szResult))
  118. {
  119. // DFS setup failed!
  120. hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
  121. TraceError("HrInstallDfs - pfnDfsSetupDfs", hr);
  122. }
  123. }
  124. }
  125. }
  126. NC_CATCH_ALL
  127. {
  128. TraceTag(ttidError, "Caught an exception from %S. Would "
  129. "the owner kindly keep it from crashing?",
  130. c_szDfsSetupDll);
  131. }
  132. FreeLibrary(hMod);
  133. }
  134. }
  135. else
  136. {
  137. TraceTag(ttidMSCliCfg, "Not attempting to install DFS, since we're in a "
  138. "workstation install");
  139. }
  140. TraceError("HrInstallDfs", hr);
  141. return hr;
  142. }
  143. //+---------------------------------------------------------------------------
  144. //
  145. // Function: HrEnableBrowserService
  146. //
  147. // Purpose: Enables the 'Browser' service
  148. //
  149. // Arguments:
  150. // (none)
  151. //
  152. // Returns: S_OK if success, WIN32 error if not
  153. //
  154. // Author: danielwe 9 Sep 1998
  155. //
  156. // Notes:
  157. //
  158. HRESULT HrEnableBrowserService()
  159. {
  160. HRESULT hr;
  161. CServiceManager sm;
  162. CService srv;
  163. hr = sm.HrOpenService(&srv, L"Browser");
  164. if (SUCCEEDED(hr))
  165. {
  166. DWORD dwStartType;
  167. hr = srv.HrQueryStartType(&dwStartType);
  168. if (SUCCEEDED(hr) && (dwStartType != SERVICE_DISABLED))
  169. {
  170. // Change the Browser StartType registry setting back to auto start
  171. hr = srv.HrSetStartType(SERVICE_AUTO_START);
  172. }
  173. }
  174. TraceError("HrEnableBrowserService",hr);
  175. return hr;
  176. }
  177. //+---------------------------------------------------------------------------
  178. //
  179. // Function: HrDisableBrowserService
  180. //
  181. // Purpose: Disables the 'Browser' service
  182. //
  183. // Arguments:
  184. // (none)
  185. //
  186. // Returns: S_OK if success, WIN32 error if not
  187. //
  188. // Author: danielwe 9 Sep 1998
  189. //
  190. // Notes:
  191. //
  192. HRESULT HrDisableBrowserService()
  193. {
  194. HRESULT hr;
  195. CServiceManager sm;
  196. CService srv;
  197. hr = sm.HrOpenService(&srv, L"Browser");
  198. if (SUCCEEDED(hr))
  199. {
  200. DWORD dwStartType;
  201. hr = srv.HrQueryStartType(&dwStartType);
  202. if (SUCCEEDED(hr) && (dwStartType != SERVICE_DISABLED))
  203. {
  204. // Change the Browser StartType registry setting to demand start
  205. hr = srv.HrSetStartType(SERVICE_DEMAND_START);
  206. if (SUCCEEDED(hr))
  207. {
  208. hr = sm.HrStopServiceNoWait(L"Browser");
  209. }
  210. }
  211. }
  212. TraceError("CNbfObj::HrDisableNetBEUI",hr);
  213. return hr;
  214. }