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.

165 lines
4.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. //
  9. // This is the language independent menu ID of the Configure a DNS Wizard
  10. //
  11. #define DNS_CONFIGE_WIZARD_MENU_ID L"_DNS_CONFIGURETOP"
  12. HINSTANCE hResourceModuleHandle = 0;
  13. HRESULT
  14. getContextMenu(const SmartInterface<View>& view, ContextMenu** dumbMenu)
  15. {
  16. HRESULT hr = S_OK;
  17. _variant_t missingParam2(DISP_E_PARAMNOTFOUND, VT_ERROR);
  18. hr = view->get_ScopeNodeContextMenu(missingParam2, dumbMenu);
  19. return hr;
  20. }
  21. HRESULT
  22. doIt()
  23. {
  24. HRESULT hr = S_OK;
  25. SmartInterface<Document> doc(0);
  26. do
  27. {
  28. hr = ::CoInitialize(0);
  29. BREAK_ON_FAILED_HRESULT(hr, L"CoInitialize failed.");
  30. SmartInterface<_Application> app(0);
  31. hr =
  32. app.AcquireViaCreateInstance(
  33. CLSID_Application,
  34. 0,
  35. // we expect the object is out-of-proc, local server, but
  36. // we really don't care, so we'll take any implementation
  37. // available.
  38. CLSCTX_ALL);
  39. BREAK_ON_FAILED_HRESULT(hr, L"CoCreateInstance failed.");
  40. Document* dumbDoc = 0;
  41. hr = app->get_Document(&dumbDoc);
  42. BREAK_ON_FAILED_HRESULT(hr, L"get_Document failed.");
  43. doc.Acquire(dumbDoc);
  44. SmartInterface<SnapIns> snapIns(0);
  45. SnapIns* dumbSnapIns = 0;
  46. hr = doc->get_SnapIns(&dumbSnapIns);
  47. BREAK_ON_FAILED_HRESULT(hr, L"get_SnapIns failed.");
  48. snapIns.Acquire(dumbSnapIns);
  49. static const wchar_t* DNS_SNAPIN_CLSID =
  50. L"{2FAEBFA2-3F1A-11D0-8C65-00C04FD8FECB}";
  51. SmartInterface<SnapIn> snapIn(0);
  52. SnapIn* dumbSnapIn = 0;
  53. _variant_t missingParam(DISP_E_PARAMNOTFOUND, VT_ERROR);
  54. _variant_t missingParam2(DISP_E_PARAMNOTFOUND, VT_ERROR);
  55. hr =
  56. snapIns->Add(AutoBstr(DNS_SNAPIN_CLSID), missingParam, missingParam2, &dumbSnapIn);
  57. BREAK_ON_FAILED_HRESULT(hr, L"SnapIns::Add failed. Is DNS installed?");
  58. snapIn.Acquire(dumbSnapIn);
  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. // navigate thru the scope node namespace to find the node
  70. // for the computer
  71. SmartInterface<ScopeNamespace> sn(0);
  72. ScopeNamespace* dumbSn = 0;
  73. hr = doc->get_ScopeNamespace(&dumbSn);
  74. BREAK_ON_FAILED_HRESULT(hr, L"get_ScopeNamespace failed.");
  75. sn.Acquire(dumbSn);
  76. SmartInterface<Node> rootnode(0);
  77. Node* dumbNode = 0;
  78. hr = sn->GetRoot(&dumbNode);
  79. BREAK_ON_FAILED_HRESULT(hr, L"GetRoot failed.");
  80. rootnode.Acquire(dumbNode);
  81. SmartInterface<Node> child1(0);
  82. hr = sn->GetChild(rootnode, &dumbNode);
  83. BREAK_ON_FAILED_HRESULT(hr, L"GetChild failed.");
  84. child1.Acquire(dumbNode);
  85. hr = view->put_ActiveScopeNode(child1);
  86. BREAK_ON_FAILED_HRESULT(hr, L"put_ActiveScopeNode failed.");
  87. // have to read back the child node we just put...
  88. hr = view->get_ActiveScopeNode(&dumbNode);
  89. BREAK_ON_FAILED_HRESULT(hr, L"GetActiveScopeNode failed.");
  90. child1 = dumbNode;
  91. dumbNode->Release();
  92. dumbNode = 0;
  93. SmartInterface<Node> child2(0);
  94. hr = sn->GetChild(child1, &dumbNode);
  95. BREAK_ON_FAILED_HRESULT(hr, L"GetChild failed.");
  96. child2.Acquire(dumbNode);
  97. hr = view->put_ActiveScopeNode(child2);
  98. BREAK_ON_FAILED_HRESULT(hr, L"put_ActiveScopeNode failed.");
  99. _variant_t missingParam3(DISP_E_PARAMNOTFOUND, VT_ERROR);
  100. hr =
  101. view->ExecuteScopeNodeMenuItem(
  102. AutoBstr(DNS_CONFIGE_WIZARD_MENU_ID),
  103. missingParam3);
  104. BREAK_ON_FAILED_HRESULT(
  105. hr,
  106. L"ExecuteScopeNodeMenuItem " DNS_CONFIGE_WIZARD_MENU_ID L" failed");
  107. }
  108. while (0);
  109. // don't save the console file.
  110. if (doc)
  111. {
  112. doc->Close(FALSE);
  113. }
  114. return hr;
  115. }
  116. int WINAPI
  117. WinMain(
  118. HINSTANCE hInstance,
  119. HINSTANCE /* hPrevInstance */ ,
  120. LPSTR /* lpszCmdLine */ ,
  121. int /* nCmdShow */ )
  122. {
  123. hResourceModuleHandle = hInstance;
  124. int exitCode = static_cast<int>(doIt());
  125. return exitCode;
  126. }