Leaked source code of windows server 2003
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.

287 lines
7.3 KiB

  1. // Copyright (c) 2001-2001 Microsoft Corporation
  2. //
  3. // Implementation of ExecuteWizard
  4. //
  5. // 30 Mar 2000 sburns
  6. // 05 Fed 2001 jeffjon copied and modified to work with
  7. // a Win32 version of CYS
  8. #include "pch.h"
  9. #include "resource.h"
  10. String
  11. LaunchWrapperWizardExe(
  12. const String& fullPath,
  13. String& commandLine,
  14. unsigned launchFailureResId,
  15. unsigned failureResId,
  16. unsigned successResId)
  17. {
  18. LOG_FUNCTION2(LaunchWrapperWizardExe, fullPath);
  19. LOG(String::format(
  20. L"commandLine = %1",
  21. commandLine.c_str()));
  22. ASSERT(!fullPath.empty());
  23. ASSERT(launchFailureResId);
  24. ASSERT(failureResId);
  25. ASSERT(successResId);
  26. String result;
  27. do
  28. {
  29. DWORD exitCode = 0;
  30. HRESULT hr = CreateAndWaitForProcess(fullPath, commandLine, exitCode);
  31. if (FAILED(hr))
  32. {
  33. result = String::load(launchFailureResId);
  34. break;
  35. }
  36. // the exit codes from the wrapper wizards are HRESULTs.
  37. if (SUCCEEDED(static_cast<HRESULT>(exitCode)))
  38. {
  39. result = String::load(successResId);
  40. break;
  41. }
  42. result = String::load(failureResId);
  43. }
  44. while (0);
  45. LOG(result);
  46. return result;
  47. }
  48. // On success, returns the empty string.
  49. // On failure, returns a failure message string for the CYS log.
  50. String
  51. LaunchPrintWizardExe(
  52. HWND parent,
  53. const String& commandLine,
  54. unsigned launchFailureResId,
  55. unsigned failureResId,
  56. unsigned executeFailureResId,
  57. HRESULT& hr)
  58. {
  59. LOG_FUNCTION2(LaunchPrintWizardExe, commandLine);
  60. ASSERT(Win::IsWindow(parent));
  61. ASSERT(!commandLine.empty());
  62. ASSERT(launchFailureResId);
  63. ASSERT(failureResId);
  64. ASSERT(executeFailureResId);
  65. String result;
  66. HINSTANCE printui = 0;
  67. do
  68. {
  69. hr = Win::LoadLibrary(L"printui.dll", printui);
  70. if (FAILED(hr))
  71. {
  72. LOG("LoadLibrary Failed");
  73. result =
  74. String::format(
  75. failureResId,
  76. String::load(launchFailureResId).c_str(),
  77. hr,
  78. GetErrorMessage(hr).c_str());
  79. break;
  80. }
  81. FARPROC proc = 0;
  82. hr = Win::GetProcAddress(printui, L"PrintUIEntryW", proc);
  83. if (FAILED(hr))
  84. {
  85. LOG("GetProcAddress Failed");
  86. result =
  87. String::format(
  88. failureResId,
  89. String::load(launchFailureResId).c_str(),
  90. hr,
  91. GetErrorMessage(hr).c_str());
  92. break;
  93. }
  94. typedef DWORD (*PrintUIEntryW)(HWND, HINSTANCE, PCTSTR, UINT);
  95. PrintUIEntryW uiproc = reinterpret_cast<PrintUIEntryW>(proc);
  96. DWORD err =
  97. uiproc(
  98. parent,
  99. Win::GetModuleHandle(),
  100. commandLine.c_str(),
  101. TRUE);
  102. hr = Win32ToHresult(err);
  103. if (FAILED(hr))
  104. {
  105. result =
  106. String::format(
  107. failureResId,
  108. String::load(executeFailureResId).c_str(),
  109. hr,
  110. GetErrorMessage(hr).c_str());
  111. }
  112. }
  113. while (0);
  114. if (printui)
  115. {
  116. HRESULT unused = Win::FreeLibrary(printui);
  117. ASSERT(SUCCEEDED(unused));
  118. }
  119. LOG_HRESULT(hr);
  120. LOG(result);
  121. return result;
  122. }
  123. // Return : True if the wizard was run, false if the serviceName was unknown
  124. // Other errors are propogated out through the hr parameter. These
  125. // errors originate as exit codes from the wizards which are being
  126. // called
  127. bool ExecuteWizard(
  128. HWND parent,
  129. PCWSTR serviceName,
  130. String& resultText,
  131. HRESULT& hr)
  132. {
  133. LOG_FUNCTION2(
  134. ExecuteWizard,
  135. serviceName ? serviceName : L"(empty)");
  136. // some wizards, namely the printer wizard, like to have a parent window so
  137. // that they can run modally.
  138. // NTRAID#NTBUG9-706913-2002/09/23-sburns
  139. ASSERT(Win::IsWindow(parent));
  140. resultText.erase();
  141. bool result = true;
  142. // This is ignored by most of the Installation Units
  143. // but can be used for determining success or cancellation by others
  144. hr = S_OK;
  145. do
  146. {
  147. if (!serviceName)
  148. {
  149. ASSERT(serviceName);
  150. break;
  151. }
  152. String service(serviceName);
  153. if (service.icompare(CYS_DNS_SERVICE_NAME) == 0)
  154. {
  155. // launch wrapper exe
  156. resultText =
  157. LaunchWrapperWizardExe(
  158. String::format(
  159. IDS_LAUNCH_DNS_WIZARD_COMMAND_LINE,
  160. Win::GetSystemDirectory().c_str()),
  161. String(),
  162. IDS_LAUNCH_DNS_WIZARD_FAILED,
  163. IDS_DNS_WIZARD_FAILED,
  164. IDS_DNS_WIZARD_SUCCEEDED);
  165. }
  166. else if (service.icompare(CYS_DHCP_SERVICE_NAME) == 0)
  167. {
  168. // launch wrapper exe
  169. resultText =
  170. LaunchWrapperWizardExe(
  171. String::format(
  172. IDS_LAUNCH_DHCP_WIZARD_COMMAND_LINE,
  173. Win::GetSystemDirectory().c_str()),
  174. String(),
  175. IDS_LAUNCH_DHCP_WIZARD_FAILED,
  176. IDS_DHCP_WIZARD_FAILED,
  177. IDS_DHCP_WIZARD_SUCCEEDED);
  178. }
  179. else if (service.icompare(CYS_RRAS_SERVICE_NAME) == 0)
  180. {
  181. // launch wrapper exe
  182. resultText =
  183. LaunchWrapperWizardExe(
  184. String::format(
  185. IDS_LAUNCH_RRAS_WIZARD_COMMAND_LINE,
  186. Win::GetSystemDirectory().c_str()),
  187. String(),
  188. IDS_LAUNCH_RRAS_WIZARD_FAILED,
  189. IDS_RRAS_WIZARD_FAILED,
  190. IDS_RRAS_WIZARD_SUCCEEDED);
  191. }
  192. else if (service.icompare(CYS_RRAS_UNINSTALL) == 0)
  193. {
  194. // launch wrapper exe
  195. resultText =
  196. LaunchWrapperWizardExe(
  197. String::format(
  198. IDS_LAUNCH_RRAS_WIZARD_COMMAND_LINE,
  199. Win::GetSystemDirectory().c_str()),
  200. String(L"/u"),
  201. IDS_LAUNCH_RRAS_WIZARD_FAILED,
  202. IDS_RRAS_WIZARD_FAILED,
  203. IDS_RRAS_WIZARD_SUCCEEDED);
  204. }
  205. else if (service.icompare(CYS_PRINTER_WIZARD_NAME) == 0)
  206. {
  207. resultText =
  208. LaunchPrintWizardExe(
  209. parent,
  210. L"/il /Wr",
  211. IDS_LAUNCH_PRINTER_WIZARD_FAILED,
  212. IDS_PRINTER_WIZARD_FAILED,
  213. IDS_EXECUTE_PRINTER_WIZARD_FAILED,
  214. hr);
  215. }
  216. else if (service.icompare(CYS_PRINTER_DRIVER_WIZARD_NAME) == 0)
  217. {
  218. resultText =
  219. LaunchPrintWizardExe(
  220. parent,
  221. L"/id /Wr",
  222. IDS_LAUNCH_PRINTER_DRIVER_WIZARD_FAILED,
  223. IDS_PRINTER_DRIVER_WIZARD_FAILED,
  224. IDS_EXECUTE_PRINTER_DRIVER_WIZARD_FAILED,
  225. hr);
  226. }
  227. else
  228. {
  229. LOG(String::format(
  230. L"Unknown wizard name: %1",
  231. service.c_str()));
  232. ASSERT(FALSE);
  233. result = false;
  234. }
  235. } while (false);
  236. LOG(resultText);
  237. LOG_HRESULT(hr);
  238. LOG_BOOL(result);
  239. return result;
  240. }