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.

214 lines
5.0 KiB

  1. // Copyright (c) 2000 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& commandLine,
  13. unsigned launchFailureResId,
  14. unsigned failureResId,
  15. unsigned successResId)
  16. {
  17. LOG_FUNCTION2(LaunchWrapperWizardExe, commandLine);
  18. ASSERT(!commandLine.empty());
  19. ASSERT(launchFailureResId);
  20. ASSERT(failureResId);
  21. ASSERT(successResId);
  22. String result;
  23. do
  24. {
  25. DWORD exitCode = 0;
  26. HRESULT hr = CreateAndWaitForProcess(commandLine, exitCode);
  27. if (FAILED(hr))
  28. {
  29. result = String::load(launchFailureResId);
  30. break;
  31. }
  32. // the exit codes from the wrapper wizards are HRESULTs.
  33. if (SUCCEEDED(static_cast<HRESULT>(exitCode)))
  34. {
  35. result = String::load(successResId);
  36. break;
  37. }
  38. result = String::load(failureResId);
  39. }
  40. while (0);
  41. LOG(result);
  42. return result;
  43. }
  44. String
  45. LaunchPrintWizardExe(
  46. const String& commandLine,
  47. unsigned launchFailureResId,
  48. unsigned failureResId,
  49. unsigned successResId)
  50. {
  51. LOG_FUNCTION2(LaunchPrintWizardExe, commandLine);
  52. ASSERT(!commandLine.empty());
  53. ASSERT(launchFailureResId);
  54. ASSERT(failureResId);
  55. ASSERT(successResId);
  56. String result;
  57. do
  58. {
  59. HINSTANCE printui = 0;
  60. HRESULT hr = Win::LoadLibrary(L"printui.dll", printui);
  61. if (SUCCEEDED(hr))
  62. {
  63. FARPROC proc = 0;
  64. hr = Win::GetProcAddress(printui, L"PrintUIEntryW", proc);
  65. if (SUCCEEDED(hr))
  66. {
  67. typedef DWORD (*PrintUIEntryW)(HWND, HINSTANCE, PCTSTR, UINT);
  68. PrintUIEntryW uiproc = reinterpret_cast<PrintUIEntryW>(proc);
  69. DWORD err =
  70. uiproc(
  71. Win::GetActiveWindow(),
  72. Win::GetModuleHandle(),
  73. commandLine.c_str(),
  74. TRUE);
  75. hr = Win32ToHresult(err);
  76. }
  77. else
  78. {
  79. LOG(L"unable to locate PrintUIEntryW proc address");
  80. }
  81. HRESULT unused = Win::FreeLibrary(printui);
  82. ASSERT(SUCCEEDED(unused));
  83. }
  84. if (SUCCEEDED(hr))
  85. {
  86. result = String::load(successResId);
  87. break;
  88. }
  89. result = String::format(failureResId, GetErrorMessage(hr).c_str());
  90. }
  91. while (0);
  92. LOG(result);
  93. return result;
  94. }
  95. bool ExecuteWizard(
  96. PCWSTR serviceName,
  97. String& resultText)
  98. {
  99. LOG_FUNCTION2(
  100. ExecuteWizard,
  101. serviceName ? serviceName : L"(empty)");
  102. bool result = true;
  103. do
  104. {
  105. if (!serviceName)
  106. {
  107. ASSERT(serviceName);
  108. break;
  109. }
  110. String service(serviceName);
  111. if (service.icompare(CYS_DNS_SERVICE_NAME) == 0)
  112. {
  113. // launch wrapper exe
  114. resultText =
  115. LaunchWrapperWizardExe(
  116. String::format(
  117. IDS_LAUNCH_DNS_WIZARD_COMMAND_LINE,
  118. Win::GetSystemDirectory().c_str()),
  119. IDS_LAUNCH_DNS_WIZARD_FAILED,
  120. IDS_DNS_WIZARD_FAILED,
  121. IDS_DNS_WIZARD_SUCCEEDED);
  122. }
  123. else if (service.icompare(CYS_DHCP_SERVICE_NAME) == 0)
  124. {
  125. // launch wrapper exe
  126. resultText =
  127. LaunchWrapperWizardExe(
  128. String::format(
  129. IDS_LAUNCH_DHCP_WIZARD_COMMAND_LINE,
  130. Win::GetSystemDirectory().c_str()),
  131. IDS_LAUNCH_DHCP_WIZARD_FAILED,
  132. IDS_DHCP_WIZARD_FAILED,
  133. IDS_DHCP_WIZARD_SUCCEEDED);
  134. }
  135. else if (service.icompare(CYS_RRAS_SERVICE_NAME) == 0)
  136. {
  137. // launch wrapper exe
  138. resultText =
  139. LaunchWrapperWizardExe(
  140. String::format(
  141. IDS_LAUNCH_RRAS_WIZARD_COMMAND_LINE,
  142. Win::GetSystemDirectory().c_str()),
  143. IDS_LAUNCH_RRAS_WIZARD_FAILED,
  144. IDS_RRAS_WIZARD_FAILED,
  145. IDS_RRAS_WIZARD_SUCCEEDED);
  146. }
  147. else if (service.icompare(CYS_PRINTER_WIZARD_NAME) == 0)
  148. {
  149. resultText =
  150. LaunchPrintWizardExe(
  151. L"/il /Wr",
  152. IDS_LAUNCH_PRINTER_WIZARD_FAILED,
  153. IDS_PRINTER_WIZARD_FAILED,
  154. IDS_PRINTER_WIZARD_SUCCEEDED);
  155. }
  156. else if (service.icompare(CYS_PRINTER_DRIVER_WIZARD_NAME) == 0)
  157. {
  158. resultText =
  159. LaunchPrintWizardExe(
  160. L"/id /Wr",
  161. IDS_LAUNCH_PRINTER_DRIVER_WIZARD_FAILED,
  162. IDS_PRINTER_DRIVER_WIZARD_FAILED,
  163. IDS_PRINTER_DRIVER_WIZARD_SUCCEEDED);
  164. }
  165. else
  166. {
  167. LOG(String::format(
  168. L"Unknown wizard name: %1",
  169. service.c_str()));
  170. ASSERT(FALSE);
  171. result = false;
  172. }
  173. } while (false);
  174. LOG(resultText);
  175. LOG_BOOL(result);
  176. return result;
  177. }