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.

252 lines
7.8 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 2000.
  5. //
  6. // File: prec.cpp
  7. //
  8. // Contents: precedence property pane (RSOP mode only)
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 02-16-2000 stevebl Created
  15. //
  16. //---------------------------------------------------------------------------
  17. #include "precomp.hxx"
  18. #include <wbemcli.h>
  19. #include "rsoputil.h"
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CPrecedence property page
  22. IMPLEMENT_DYNCREATE(CPrecedence, CPropertyPage)
  23. CPrecedence::CPrecedence() : CPropertyPage(CPrecedence::IDD)
  24. {
  25. //{{AFX_DATA_INIT(CPrecedence)
  26. m_szTitle = _T("");
  27. //}}AFX_DATA_INIT
  28. m_hConsoleHandle = NULL;
  29. }
  30. CPrecedence::~CPrecedence()
  31. {
  32. *m_ppThis = NULL;
  33. }
  34. void CPrecedence::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CPropertyPage::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CPrecedence)
  38. DDX_Control(pDX, IDC_LIST1, m_list);
  39. DDX_Text(pDX, IDC_TITLE, m_szTitle);
  40. //}}AFX_DATA_MAP
  41. }
  42. int CALLBACK ComparePrecedenceItems(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  43. {
  44. CListCtrl * pList = (CListCtrl *)lParamSort;
  45. DWORD dw1, dw2;
  46. return lParam1 - lParam2;
  47. }
  48. BEGIN_MESSAGE_MAP(CPrecedence, CPropertyPage)
  49. //{{AFX_MSG_MAP(CPrecedence)
  50. ON_WM_CONTEXTMENU()
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CPrecedence message handlers
  55. LRESULT CPrecedence::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  56. {
  57. // TODO: Add your specialized code here and/or call the base class
  58. switch (message )
  59. {
  60. case WM_HELP:
  61. StandardHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, IDD, TRUE);
  62. return 0;
  63. }
  64. return CPropertyPage::WindowProc(message, wParam, lParam);
  65. }
  66. BOOL CPrecedence::OnInitDialog()
  67. {
  68. CPropertyPage::OnInitDialog();
  69. // TODO: Add extra initialization here
  70. RECT rect;
  71. m_list.GetClientRect(&rect);
  72. // add columns to the precedence pane
  73. CString szTemp;
  74. szTemp.LoadString(IDS_PRECEDENCE_COL1);
  75. m_list.InsertColumn(0, szTemp, LVCFMT_LEFT, (rect.right - rect.left) * 0.125);
  76. szTemp.LoadString(IDS_PRECEDENCE_COL2);
  77. m_list.InsertColumn(1, szTemp, LVCFMT_LEFT, (rect.right - rect.left) * 0.29);
  78. szTemp.LoadString(IDS_PRECEDENCE_COL3);
  79. m_list.InsertColumn(2, szTemp, LVCFMT_LEFT, (rect.right - rect.left) * 0.29);
  80. szTemp.LoadString(IDS_PRECEDENCE_COL4);
  81. m_list.InsertColumn(3, szTemp, LVCFMT_LEFT, (rect.right - rect.left) * 0.29);
  82. int i = 0;
  83. HRESULT hr = S_OK;
  84. IWbemLocator * pLocator = NULL;
  85. IWbemServices * pNamespace = NULL;
  86. IWbemClassObject * pObj = NULL;
  87. IEnumWbemClassObject * pEnum = NULL;
  88. BSTR strQueryLanguage = SysAllocString(TEXT("WQL"));
  89. szTemp = TEXT("SELECT * FROM RSOP_ApplicationManagementPolicySetting WHERE Id=\"")
  90. + m_pData->m_szDeploymentGroupID + TEXT("\"");
  91. switch (m_iViewState)
  92. {
  93. case IDM_WINNER:
  94. szTemp += TEXT(" AND EntryType=1");
  95. break;
  96. case IDM_FAILED:
  97. szTemp += TEXT(" AND EntryType=4");
  98. break;
  99. case IDM_REMOVED:
  100. szTemp += TEXT(" AND EntryType=2");
  101. break;
  102. case IDM_ARP:
  103. szTemp += TEXT(" AND EntryType=3");
  104. break;
  105. }
  106. BSTR strQuery = SysAllocString(szTemp);
  107. BSTR strNamespace = SysAllocString(m_szRSOPNamespace);
  108. ULONG n = 0;
  109. hr = CoCreateInstance(CLSID_WbemLocator,
  110. 0,
  111. CLSCTX_INPROC_SERVER,
  112. IID_IWbemLocator,
  113. (LPVOID *) & pLocator);
  114. if (FAILED(hr))
  115. {
  116. goto cleanup;
  117. }
  118. hr = pLocator->ConnectServer(strNamespace,
  119. NULL,
  120. NULL,
  121. NULL,
  122. 0,
  123. NULL,
  124. NULL,
  125. &pNamespace);
  126. if (FAILED(hr))
  127. {
  128. goto cleanup;
  129. }
  130. hr = pNamespace->ExecQuery(strQueryLanguage,
  131. strQuery,
  132. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  133. NULL,
  134. &pEnum);
  135. if (FAILED(hr))
  136. {
  137. goto cleanup;
  138. }
  139. do
  140. {
  141. hr = pEnum->Next(WBEM_INFINITE, 1, &pObj, &n);
  142. if (FAILED(hr))
  143. {
  144. goto cleanup;
  145. }
  146. if (n > 0)
  147. {
  148. // prepare the data entry and populate all the fields
  149. CString szPackageName;
  150. CString szGPOID;
  151. CString szGPOName;
  152. CString szCreation;
  153. BSTR bstrCreation = NULL;
  154. ULONG ulPrecedence;
  155. hr = GetParameter(pObj,
  156. TEXT("precedence"),
  157. ulPrecedence);
  158. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetParameter(\"precedence\") failed with 0x%x"), hr));
  159. hr = GetParameter(pObj,
  160. TEXT("Name"),
  161. szPackageName);
  162. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetParameter(\"Name\") failed with 0x%x"), hr));
  163. hr = GetParameter(pObj,
  164. TEXT("GPOID"),
  165. szGPOID);
  166. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetParameter(\"GPOID\") failed with 0x%x"), hr));
  167. hr = GetParameterBSTR(pObj,
  168. TEXT("creationtime"),
  169. bstrCreation);
  170. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetParameterBSTR(\"creationtime\") failed with 0x%x"), hr));
  171. hr = CStringFromWBEMTime(szCreation, bstrCreation, TRUE);
  172. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: CStringFromWBEMTime failed with 0x%x"), hr));
  173. LPTSTR pszGPOName = NULL;
  174. hr = GetGPOFriendlyName(pNamespace,
  175. (LPTSTR)((LPCTSTR) szGPOID),
  176. strQueryLanguage,
  177. &pszGPOName);
  178. DebugReportFailure(hr, (DM_WARNING, TEXT("CPrecedence::OnInitDialog: GetGPOFriendlyName failed with 0x%x"), hr));
  179. if (SUCCEEDED(hr))
  180. {
  181. szGPOName = pszGPOName;
  182. OLESAFE_DELETE(pszGPOName);
  183. }
  184. // insert the entry in the list
  185. CString szPrecedence;
  186. szPrecedence.Format(TEXT("%lu"), ulPrecedence);
  187. i = m_list.InsertItem(i, szPrecedence);
  188. m_list.SetItemText(i, 1, szPackageName);
  189. m_list.SetItemText(i, 2, szGPOName);
  190. m_list.SetItemText(i, 3, szCreation);
  191. m_list.SetItemData(i, ulPrecedence);
  192. ulPrecedence = m_list.GetItemData(i);
  193. i++;
  194. if (bstrCreation)
  195. {
  196. SysFreeString(bstrCreation);
  197. }
  198. }
  199. } while (n > 0);
  200. m_list.SortItems(ComparePrecedenceItems, (LPARAM)&m_list);
  201. cleanup:
  202. SysFreeString(strQuery);
  203. SysFreeString(strQueryLanguage);
  204. SysFreeString(strNamespace);
  205. if (pObj)
  206. {
  207. pObj->Release();
  208. }
  209. if (pEnum)
  210. {
  211. pEnum->Release();
  212. }
  213. if (pNamespace)
  214. {
  215. pNamespace->Release();
  216. }
  217. if (pLocator)
  218. {
  219. pLocator->Release();
  220. }
  221. return TRUE; // return TRUE unless you set the focus to a control
  222. // EXCEPTION: OCX Property Pages should return FALSE
  223. }
  224. void CPrecedence::OnContextMenu(CWnd* pWnd, CPoint point)
  225. {
  226. StandardContextMenu(pWnd->m_hWnd, IDD_PRECEDENCE, TRUE);
  227. }