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.

162 lines
3.8 KiB

  1. // WMIFilterManager.cpp : Implementation of CWMIFilterManager
  2. #include "stdafx.h"
  3. #include <wbemidl.h>
  4. #include "resource.h"
  5. #include "defines.h"
  6. #include "ntdmutils.h"
  7. #include "SchemaManager.h"
  8. #include "WMIFilterManager.h"
  9. #include "WMIFilterMgrDlg.h"
  10. extern CWMIFilterManagerDlg * g_pFilterManagerDlg;
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CWMIFilterManager
  13. CWMIFilterManager::CWMIFilterManager()
  14. {
  15. m_pIWbemServices = NULL;
  16. m_hWnd = NULL;
  17. }
  18. //---------------------------------------------------------------------------
  19. CWMIFilterManager::~CWMIFilterManager()
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. STDMETHODIMP CWMIFilterManager::ConnectToWMI()
  24. {
  25. HRESULT hr;
  26. CComPtr<IWbemLocator>pIWbemLocator;
  27. CComBSTR bstrRootPolicy( L"root\\policy" );
  28. if ( bstrRootPolicy.m_str == NULL )
  29. {
  30. return E_OUTOFMEMORY;
  31. }
  32. NTDM_BEGIN_METHOD()
  33. m_pIWbemServices = NULL;
  34. // create the webm locator
  35. NTDM_ERR_MSG_IF_FAIL(CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER,
  36. IID_IWbemLocator, (LPVOID *) &pIWbemLocator));
  37. NTDM_ERR_MSG_IF_FAIL(pIWbemLocator->ConnectServer( bstrRootPolicy,
  38. NULL,
  39. NULL,
  40. NULL,
  41. 0,
  42. NULL,
  43. NULL,
  44. &m_pIWbemServices));
  45. NTDM_ERR_MSG_IF_FAIL(CoSetProxyBlanket(m_pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
  46. RPC_C_AUTHN_LEVEL_CONNECT, RPC_C_IMP_LEVEL_IMPERSONATE ,
  47. NULL, EOAC_NONE));
  48. NTDM_END_METHOD()
  49. // cleanup
  50. return hr;
  51. }
  52. //---------------------------------------------------------------------------
  53. STDMETHODIMP CWMIFilterManager::RunManager(HWND hwndParent, BSTR bstrDomain, VARIANT *vSelection)
  54. {
  55. HRESULT hr;
  56. g_pFilterManagerDlg = NULL;
  57. NTDM_BEGIN_METHOD()
  58. m_hWnd = hwndParent;
  59. NTDM_ERR_IF_FAIL(ConnectToWMI());
  60. g_pFilterManagerDlg = new CWMIFilterManagerDlg(this, false, bstrDomain);
  61. NTDM_ERRID_IF_NULL(g_pFilterManagerDlg, E_OUTOFMEMORY);
  62. if(IDOK == DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_WMI_FILTER_MANAGER), (HWND)hwndParent, WMIFilterManagerDlgProc))
  63. {
  64. if(g_pFilterManagerDlg->m_pIWbemClassObject)
  65. {
  66. VariantClear(vSelection);
  67. V_VT(vSelection) = VT_UNKNOWN;
  68. NTDM_ERR_MSG_IF_FAIL(g_pFilterManagerDlg->m_pIWbemClassObject->QueryInterface(IID_IUnknown, (void **)&(V_UNKNOWN(vSelection))));
  69. }
  70. else
  71. hr = S_FALSE;
  72. }
  73. else
  74. {
  75. hr = S_FALSE;
  76. }
  77. NTDM_END_METHOD()
  78. // cleanup
  79. NTDM_DELETE_OBJECT(g_pFilterManagerDlg);
  80. return hr;
  81. }
  82. //---------------------------------------------------------------------------
  83. STDMETHODIMP CWMIFilterManager::RunBrowser(HWND hwndParent, BSTR bstrDomain, VARIANT *vSelection)
  84. {
  85. HRESULT hr;
  86. g_pFilterManagerDlg = NULL;
  87. NTDM_BEGIN_METHOD()
  88. m_hWnd = hwndParent;
  89. NTDM_ERR_IF_FAIL(ConnectToWMI());
  90. //brijeshb: wrap with macro for bug 228812 prefix bug.
  91. NTDM_ERR_IF_NULL((g_pFilterManagerDlg = new CWMIFilterManagerDlg(this, true, bstrDomain)));
  92. if(IDOK == DialogBox(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDD_WMI_FILTER_BROWSER), (HWND)hwndParent, WMIFilterManagerDlgProc))
  93. {
  94. if(g_pFilterManagerDlg->m_pIWbemClassObject)
  95. {
  96. VariantClear(vSelection);
  97. V_VT(vSelection) = VT_UNKNOWN;
  98. NTDM_ERR_MSG_IF_FAIL(g_pFilterManagerDlg->m_pIWbemClassObject->QueryInterface(IID_IUnknown, (void **)&(V_UNKNOWN(vSelection))));
  99. }
  100. else
  101. hr = S_FALSE;
  102. }
  103. else
  104. {
  105. hr = S_FALSE;
  106. }
  107. NTDM_END_METHOD()
  108. // cleanup
  109. NTDM_DELETE_OBJECT(g_pFilterManagerDlg);
  110. return hr;
  111. }
  112. //--------------------------------------------------------------------------
  113. STDMETHODIMP CWMIFilterManager::SetMultiSelection(VARIANT_BOOL vbValue)
  114. {
  115. // TODO: Add your implementation code here
  116. return S_OK;
  117. }