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.

206 lines
5.4 KiB

  1. // Copyright (c) 2000 Microsoft Corp.
  2. //
  3. // launches dns wizard from the dhcp snapin using mmc automation
  4. #include "headers.hxx"
  5. #include "resource.h"
  6. #include "smartptr.hpp"
  7. #include "misc.hpp"
  8. HINSTANCE hResourceModuleHandle = 0;
  9. HRESULT
  10. getContextMenu(const SmartInterface<View>& view, ContextMenu** dumbMenu)
  11. {
  12. HRESULT hr = S_OK;
  13. _variant_t missingParam2(DISP_E_PARAMNOTFOUND, VT_ERROR);
  14. hr = view->get_ScopeNodeContextMenu(missingParam2, dumbMenu);
  15. return hr;
  16. }
  17. inline
  18. void
  19. SafeStrncat(wchar_t* dest, const wchar_t* src, size_t bufmax)
  20. {
  21. ASSERT(dest && src);
  22. if (dest && src)
  23. {
  24. wcsncat(dest, src, bufmax - wcslen(dest) - 1);
  25. }
  26. }
  27. HRESULT
  28. doIt(bool install = true)
  29. {
  30. HRESULT hr = S_OK;
  31. do
  32. {
  33. hr = ::CoInitialize(0);
  34. BREAK_ON_FAILED_HRESULT(hr, L"CoInitialize failed.");
  35. SmartInterface<_Application> app(0);
  36. hr =
  37. app.AcquireViaCreateInstance(
  38. CLSID_Application,
  39. 0,
  40. // we expect the object is out-of-proc, local server, but
  41. // we really don't care, so we'll take any implementation
  42. // available.
  43. CLSCTX_ALL);
  44. BREAK_ON_FAILED_HRESULT(hr, L"CoCreateInstance failed.");
  45. wchar_t buf[MAX_PATH + 1];
  46. memset(buf, 0, (MAX_PATH + 1) * sizeof(wchar_t));
  47. UINT result = ::GetSystemDirectory(buf, MAX_PATH);
  48. ASSERT(result != 0 && result <= MAX_PATH);
  49. wchar_t mscPath[MAX_PATH + 1] = L"";
  50. SafeStrncat(mscPath, buf, MAX_PATH);
  51. SafeStrncat(mscPath, L"\\rrasmgmt.msc", MAX_PATH);
  52. hr = app->Load(AutoBstr(mscPath));
  53. BREAK_ON_FAILED_HRESULT(hr, L"Load failed.");
  54. SmartInterface<Document> doc(0);
  55. Document* dumbDoc = 0;
  56. hr = app->get_Document(&dumbDoc);
  57. BREAK_ON_FAILED_HRESULT(hr, L"get_Document failed.");
  58. doc.Acquire(dumbDoc);
  59. SmartInterface<Views> views(0);
  60. Views* dumbViews = 0;
  61. hr = doc->get_Views(&dumbViews);
  62. BREAK_ON_FAILED_HRESULT(hr, L"get_Views failed.");
  63. views.Acquire(dumbViews);
  64. SmartInterface<View> view(0);
  65. View* dumbView = 0;
  66. hr = views->Item(1, &dumbView);
  67. BREAK_ON_FAILED_HRESULT(hr, L"Views::Item failed.");
  68. view.Acquire(dumbView);
  69. SmartInterface<ScopeNamespace> sn(0);
  70. ScopeNamespace* dumbSn = 0;
  71. hr = doc->get_ScopeNamespace(&dumbSn);
  72. BREAK_ON_FAILED_HRESULT(hr, L"get_ScopeNamespace failed.");
  73. sn.Acquire(dumbSn);
  74. SmartInterface<Node> rootnode(0);
  75. Node* dumbNode = 0;
  76. hr = sn->GetRoot(&dumbNode);
  77. BREAK_ON_FAILED_HRESULT(hr, L"GetRoot failed.");
  78. rootnode.Acquire(dumbNode);
  79. SmartInterface<Node> child1(0);
  80. hr = sn->GetChild(rootnode, &dumbNode);
  81. BREAK_ON_FAILED_HRESULT(hr, L"GetChild failed.");
  82. child1.Acquire(dumbNode);
  83. hr = view->put_ActiveScopeNode(child1);
  84. BREAK_ON_FAILED_HRESULT(hr, L"put_ActiveScopeNode failed.");
  85. // have to read back the child node we just put...
  86. hr = view->get_ActiveScopeNode(&dumbNode);
  87. BREAK_ON_FAILED_HRESULT(hr, L"GetActiveScopeNode failed.");
  88. child1 = dumbNode;
  89. dumbNode->Release();
  90. dumbNode = 0;
  91. SmartInterface<Node> child2(0);
  92. hr = sn->GetChild(child1, &dumbNode);
  93. BREAK_ON_FAILED_HRESULT(hr, L"GetChild failed.");
  94. child2.Acquire(dumbNode);
  95. hr = view->put_ActiveScopeNode(child2);
  96. BREAK_ON_FAILED_HRESULT(hr, L"put_ActiveScopeNode failed.");
  97. // have to read back the child node we just put...
  98. hr = view->get_ActiveScopeNode(&dumbNode);
  99. BREAK_ON_FAILED_HRESULT(hr, L"GetActiveScopeNode failed.");
  100. child2 = dumbNode;
  101. dumbNode->Release();
  102. dumbNode = 0;
  103. SmartInterface<Node> next(0);
  104. hr = sn->GetNext(child2, &dumbNode);
  105. BREAK_ON_FAILED_HRESULT(hr, L"GetNext failed.");
  106. next.Acquire(dumbNode);
  107. hr = view->put_ActiveScopeNode(next);
  108. BREAK_ON_FAILED_HRESULT(hr, L"put_ActiveScopeNode failed.");
  109. // excute configure server wizard menu item
  110. _variant_t missingParam2(DISP_E_PARAMNOTFOUND, VT_ERROR);
  111. if (install)
  112. {
  113. hr = view->ExecuteScopeNodeMenuItem((BSTR)AutoBstr(L"_CONFIGURE_RRAS_WIZARD_"), missingParam2);
  114. BREAK_ON_FAILED_HRESULT(hr, L"ExecuteScopeNodeMenuItem FIGURE_RRAS_WIZARD_ failed");
  115. }
  116. else
  117. {
  118. hr = view->ExecuteScopeNodeMenuItem((BSTR)AutoBstr(L"_DISABLE_RRAS_"), missingParam2);
  119. BREAK_ON_FAILED_HRESULT(hr, L"ExecuteScopeNodeMenuItem FIGURE_RRAS_WIZARD_ failed");
  120. }
  121. hr = doc->Close(FALSE);
  122. BREAK_ON_FAILED_HRESULT(hr, L"Close failed.");
  123. }
  124. while (0);
  125. return hr;
  126. }
  127. int WINAPI
  128. WinMain(
  129. HINSTANCE hInstance,
  130. HINSTANCE /* hPrevInstance */ ,
  131. LPSTR /*lpszCmdLine*/,
  132. int /* nCmdShow */ )
  133. {
  134. hResourceModuleHandle = hInstance;
  135. bool install = true;
  136. int numArgs = 0;
  137. PWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &numArgs);
  138. if (argv &&
  139. numArgs > 1)
  140. {
  141. for (int index = 0; index < numArgs; ++index)
  142. {
  143. if (argv[index] &&
  144. _wcsicmp(argv[index], L"/u") == 0)
  145. {
  146. install = false;
  147. }
  148. }
  149. GlobalFree(argv);
  150. }
  151. int exitCode = static_cast<int>(doIt(install));
  152. return exitCode;
  153. }