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.

1211 lines
36 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. provprop.cpp
  5. Abstract:
  6. Implementation of the trace providers general property page.
  7. --*/
  8. #include "stdafx.h"
  9. #include <pdh.h> // For xxx_TIME_VALUE
  10. #include "smlogs.h"
  11. #include "smcfgmsg.h"
  12. #include "provdlg.h"
  13. #include "warndlg.h"
  14. #include "enabldlg.h"
  15. #include "provprop.h"
  16. #include <pdhp.h>
  17. #include "dialogs.h"
  18. #include "smlogres.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. USE_HANDLE_MACROS("SMLOGCFG(provprop.cpp)");
  25. static ULONG
  26. s_aulHelpIds[] =
  27. {
  28. IDC_PROV_FILENAME_DISPLAY, IDH_PROV_FILENAME_DISPLAY,
  29. IDC_PROV_PROVIDER_LIST, IDH_PROV_PROVIDER_LIST,
  30. IDC_PROV_ADD_BTN, IDH_PROV_ADD_BTN,
  31. IDC_PROV_REMOVE_BTN, IDH_PROV_REMOVE_BTN,
  32. IDC_PROV_KERNEL_BTN, IDH_PROV_KERNEL_BTN,
  33. IDC_PROV_OTHER_BTN, IDH_PROV_OTHER_BTN,
  34. IDC_PROV_K_PROCESS_CHK, IDH_PROV_K_PROCESS_CHK,
  35. IDC_PROV_K_THREAD_CHK, IDH_PROV_K_THREAD_CHK,
  36. IDC_PROV_K_DISK_IO_CHK, IDH_PROV_K_DISK_IO_CHK,
  37. IDC_PROV_K_NETWORK_CHK, IDH_PROV_K_NETWORK_CHK,
  38. IDC_PROV_K_SOFT_PF_CHK, IDH_PROV_K_SOFT_PF_CHK,
  39. IDC_PROV_K_FILE_IO_CHK, IDH_PROV_K_FILE_IO_CHK,
  40. IDC_PROV_SHOW_PROVIDERS_BTN, IDH_PROV_SHOW_PROVIDERS_BTN,
  41. IDC_RUNAS_EDIT, IDH_RUNAS_EDIT,
  42. IDC_SETPWD_BTN, IDH_SETPWD_BTN,
  43. 0,0
  44. };
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CProvidersProperty property page
  47. IMPLEMENT_DYNCREATE(CProvidersProperty, CSmPropertyPage)
  48. CProvidersProperty::CProvidersProperty(MMC_COOKIE lCookie, LONG_PTR hConsole)
  49. : CSmPropertyPage ( CProvidersProperty::IDD, hConsole )
  50. // lCookie is really the pointer to the Log Query object
  51. {
  52. // ::OutputDebugStringA("\nCProvidersProperty::CProvidersProperty");
  53. // save pointers from arg list
  54. m_pTraceLogQuery = reinterpret_cast <CSmTraceLogQuery *>(lCookie);
  55. m_dwMaxHorizListExtent = 0;
  56. m_dwTraceMode = eTraceModeApplication;
  57. // EnableAutomation();
  58. //{{AFX_DATA_INIT(CProvidersProperty)
  59. m_bNonsystemProvidersExist = TRUE;
  60. m_bEnableProcessTrace = FALSE;
  61. m_bEnableThreadTrace = FALSE;
  62. m_bEnableDiskIoTrace = FALSE;
  63. m_bEnableNetworkTcpipTrace = FALSE;
  64. m_bEnableMemMgmtTrace = FALSE;
  65. m_bEnableFileIoTrace = FALSE;
  66. //}}AFX_DATA_INIT
  67. }
  68. CProvidersProperty::CProvidersProperty() : CSmPropertyPage(CProvidersProperty::IDD)
  69. {
  70. ASSERT (FALSE); // the constructor w/ args should be used instead
  71. EnableAutomation();
  72. //{{AFX_DATA_INIT(CProvidersProperty)
  73. m_bNonsystemProvidersExist = TRUE;
  74. m_bEnableProcessTrace = FALSE;
  75. m_bEnableThreadTrace = FALSE;
  76. m_bEnableDiskIoTrace = FALSE;
  77. m_bEnableNetworkTcpipTrace = FALSE;
  78. m_bEnableMemMgmtTrace = FALSE;
  79. m_bEnableFileIoTrace = FALSE;
  80. //}}AFX_DATA_INIT
  81. m_pTraceLogQuery = NULL;
  82. }
  83. CProvidersProperty::~CProvidersProperty()
  84. {
  85. // ::OutputDebugStringA("\nCProvidersProperty::~CProvidersProperty");
  86. }
  87. void CProvidersProperty::OnFinalRelease()
  88. {
  89. // When the last reference for an automation object is released
  90. // OnFinalRelease is called. The base class will automatically
  91. // deletes the object. Add additional cleanup required for your
  92. // object before calling the base class.
  93. CPropertyPage::OnFinalRelease();
  94. }
  95. void CProvidersProperty::DoDataExchange(CDataExchange* pDX)
  96. {
  97. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  98. DoProvidersDataExchange ( pDX );
  99. TraceModeRadioExchange ( pDX );
  100. CPropertyPage::DoDataExchange(pDX);
  101. //{{AFX_DATA_MAP(CProvidersProperty)
  102. DDX_Text(pDX, IDC_PROV_LOG_SCHED_TEXT, m_strStartText);
  103. DDX_Text(pDX, IDC_RUNAS_EDIT, m_strUserDisplay );
  104. DDX_Check(pDX, IDC_PROV_K_PROCESS_CHK, m_bEnableProcessTrace);
  105. DDX_Check(pDX, IDC_PROV_K_THREAD_CHK, m_bEnableThreadTrace);
  106. DDX_Check(pDX, IDC_PROV_K_DISK_IO_CHK, m_bEnableDiskIoTrace);
  107. DDX_Check(pDX, IDC_PROV_K_NETWORK_CHK, m_bEnableNetworkTcpipTrace);
  108. DDX_Check(pDX, IDC_PROV_K_SOFT_PF_CHK, m_bEnableMemMgmtTrace);
  109. DDX_Check(pDX, IDC_PROV_K_FILE_IO_CHK, m_bEnableFileIoTrace);
  110. //}}AFX_DATA_MAP
  111. }
  112. BEGIN_MESSAGE_MAP(CProvidersProperty, CSmPropertyPage)
  113. //{{AFX_MSG_MAP(CProvidersProperty)
  114. ON_BN_CLICKED(IDC_PROV_KERNEL_BTN, OnProvTraceModeRdo)
  115. ON_BN_CLICKED(IDC_PROV_OTHER_BTN, OnProvTraceModeRdo)
  116. ON_BN_CLICKED(IDC_PROV_SHOW_PROVIDERS_BTN, OnProvShowProvBtn)
  117. ON_BN_CLICKED(IDC_PROV_ADD_BTN, OnProvAddBtn)
  118. ON_BN_CLICKED(IDC_PROV_REMOVE_BTN, OnProvRemoveBtn)
  119. ON_LBN_DBLCLK(IDC_PROV_PROVIDER_LIST, OnDblclkProvProviderList)
  120. ON_LBN_SELCANCEL(IDC_PROV_PROVIDER_LIST, OnSelcancelProvProviderList)
  121. ON_LBN_SELCHANGE(IDC_PROV_PROVIDER_LIST, OnSelchangeProvProviderList)
  122. ON_BN_CLICKED(IDC_PROV_K_PROCESS_CHK, OnProvKernelEnableCheck)
  123. ON_BN_CLICKED(IDC_PROV_K_THREAD_CHK, OnProvKernelEnableCheck)
  124. ON_EN_CHANGE( IDC_RUNAS_EDIT, OnChangeUser )
  125. ON_BN_CLICKED(IDC_PROV_K_DISK_IO_CHK, OnProvKernelEnableCheck)
  126. ON_BN_CLICKED(IDC_PROV_K_NETWORK_CHK, OnProvKernelEnableCheck)
  127. ON_BN_CLICKED(IDC_PROV_K_FILE_IO_CHK, OnProvKernelEnableCheck)
  128. ON_BN_CLICKED(IDC_PROV_K_SOFT_PF_CHK, OnProvKernelEnableCheck)
  129. ON_BN_CLICKED(IDC_SETPWD_BTN, OnPwdBtn)
  130. ON_WM_DESTROY()
  131. //}}AFX_MSG_MAP
  132. END_MESSAGE_MAP()
  133. BEGIN_DISPATCH_MAP(CProvidersProperty, CSmPropertyPage)
  134. //{{AFX_DISPATCH_MAP(CProvidersProperty)
  135. // NOTE - the ClassWizard will add and remove mapping macros here.
  136. //}}AFX_DISPATCH_MAP
  137. END_DISPATCH_MAP()
  138. // Note: we add support for IID_IProvidersProperty to support typesafe binding
  139. // from VBA. This IID must match the GUID that is attached to the
  140. // dispinterface in the .ODL file.
  141. // {65154EA9-BDBE-11D1-BF99-00C04F94A83A}
  142. static const IID IID_IProvidersProperty =
  143. { 0x65154ea9, 0xbdbe, 0x11d1, { 0xbf, 0x99, 0x0, 0xc0, 0x4f, 0x94, 0xa8, 0x3a } };
  144. BEGIN_INTERFACE_MAP(CProvidersProperty, CSmPropertyPage)
  145. INTERFACE_PART(CProvidersProperty, IID_IProvidersProperty, Dispatch)
  146. END_INTERFACE_MAP()
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CProvidersProperty message handlers
  149. void
  150. CProvidersProperty::OnChangeUser()
  151. {
  152. //
  153. // If you can not access remote WBEM, you can not modify RunAs info,
  154. // changing the user name is not allowed.
  155. //
  156. if (m_bCanAccessRemoteWbem) {
  157. // When the user hits OK in the password dialog,
  158. // the user name might not have changed.
  159. UpdateData ( TRUE );
  160. m_strUserDisplay.TrimLeft();
  161. m_strUserDisplay.TrimRight();
  162. if ( 0 != m_strUserSaved.Compare ( m_strUserDisplay ) ) {
  163. m_pTraceLogQuery->m_fDirtyPassword = PASSWORD_DIRTY;
  164. SetModifiedPage(TRUE);
  165. }
  166. else {
  167. m_pTraceLogQuery->m_fDirtyPassword &= ~PASSWORD_DIRTY;
  168. }
  169. //
  170. // If default user is typed, never need to set password
  171. //
  172. if (m_strUserDisplay.IsEmpty() || m_strUserDisplay.GetAt(0) == L'<') {
  173. if (m_bPwdButtonEnabled) {
  174. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(FALSE);
  175. m_bPwdButtonEnabled = FALSE;
  176. }
  177. }
  178. else {
  179. if (!m_bPwdButtonEnabled) {
  180. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(TRUE);
  181. m_bPwdButtonEnabled = TRUE;
  182. }
  183. }
  184. }
  185. else {
  186. //
  187. // We can not modify the RunAs info, then display
  188. // an error message and retore the original user name in RunAs
  189. //
  190. UpdateData(TRUE);
  191. if (ConnectRemoteWbemFail(m_pTraceLogQuery, FALSE)) {
  192. GetDlgItem(IDC_RUNAS_EDIT)->SetWindowText(m_strUserSaved);
  193. }
  194. }
  195. }
  196. void CProvidersProperty::OnPwdBtn()
  197. {
  198. CString strTempUser;
  199. UpdateData();
  200. if (!m_bCanAccessRemoteWbem) {
  201. ConnectRemoteWbemFail(m_pTraceLogQuery, TRUE);
  202. return;
  203. }
  204. MFC_TRY
  205. strTempUser = m_strUserDisplay;
  206. m_strUserDisplay.TrimLeft();
  207. m_strUserDisplay.TrimRight();
  208. m_pTraceLogQuery->m_strUser = m_strUserDisplay;
  209. SetRunAs(m_pTraceLogQuery);
  210. m_strUserDisplay = m_pTraceLogQuery->m_strUser;
  211. if ( 0 != strTempUser.CompareNoCase ( m_strUserDisplay ) ) {
  212. SetDlgItemText ( IDC_RUNAS_EDIT, m_strUserDisplay );
  213. }
  214. MFC_CATCH_MINIMUM;
  215. }
  216. void CProvidersProperty::OnProvAddBtn()
  217. {
  218. ImplementAdd();
  219. }
  220. void CProvidersProperty::OnProvRemoveBtn()
  221. {
  222. CListBox *plbProviderList;
  223. LONG lThisItem;
  224. BOOL bDone;
  225. LONG lOrigCaret;
  226. LONG lItemStatus;
  227. LONG lItemCount;
  228. BOOL bChanged = FALSE;
  229. DWORD dwItemExtent;
  230. CString strItemText;
  231. plbProviderList = (CListBox *)GetDlgItem(IDC_PROV_PROVIDER_LIST);
  232. // delete all selected items in the list box and
  233. // set the cursor to the item above the original caret position
  234. // or the first or last if that is out of the new range
  235. lOrigCaret = plbProviderList->GetCaretIndex();
  236. lThisItem = 0;
  237. bDone = FALSE;
  238. // clear the max extent
  239. m_dwMaxHorizListExtent = 0;
  240. // clear the value
  241. do {
  242. lItemStatus = plbProviderList->GetSel(lThisItem);
  243. if (lItemStatus > 0) {
  244. // then it's selected so delete it
  245. INT iProvIndex = (INT)plbProviderList->GetItemData ( lThisItem );
  246. m_arrGenProviders[iProvIndex] = CSmTraceLogQuery::eNotInQuery;
  247. plbProviderList->DeleteString ( lThisItem );
  248. bChanged = TRUE;
  249. } else if (lItemStatus == 0) {
  250. // get the text length of this item since it will stay
  251. plbProviderList->GetText(lThisItem, strItemText);
  252. dwItemExtent = (DWORD)((plbProviderList->GetDC())->GetTextExtent(strItemText)).cx;
  253. if (dwItemExtent > m_dwMaxHorizListExtent) {
  254. m_dwMaxHorizListExtent = dwItemExtent;
  255. }
  256. // then it's not selected so go to the next one
  257. lThisItem++;
  258. } else {
  259. // we've run out so exit
  260. bDone = TRUE;
  261. }
  262. } while (!bDone);
  263. // update the text extent of the list box
  264. plbProviderList->SetHorizontalExtent(m_dwMaxHorizListExtent);
  265. // see how many entries are left and update the
  266. // caret position and the remove button state
  267. lItemCount = plbProviderList->GetCount();
  268. if (lItemCount > 0) {
  269. // the update the caret
  270. if (lOrigCaret >= lItemCount) {
  271. lOrigCaret = lItemCount-1;
  272. } else {
  273. // caret should be within the list
  274. }
  275. plbProviderList->SetSel(lOrigCaret);
  276. plbProviderList->SetCaretIndex(lOrigCaret);
  277. } else {
  278. // the list is empty so remove caret, selection
  279. plbProviderList->SetSel(-1);
  280. if ( eTraceModeApplication == m_dwTraceMode )
  281. GetDlgItem(IDC_PROV_ADD_BTN)->SetFocus();
  282. }
  283. SetTraceModeState();
  284. SetModifiedPage(bChanged);
  285. }
  286. void CProvidersProperty::OnDblclkProvProviderList()
  287. {
  288. ImplementAdd();
  289. }
  290. void CProvidersProperty::OnSelcancelProvProviderList()
  291. {
  292. SetAddRemoveBtnState();
  293. }
  294. void CProvidersProperty::OnSelchangeProvProviderList()
  295. {
  296. SetAddRemoveBtnState();
  297. }
  298. void
  299. CProvidersProperty::DoProvidersDataExchange ( CDataExchange* pDX)
  300. {
  301. CListBox * plbInQueryProviders = (CListBox *)GetDlgItem(IDC_PROV_PROVIDER_LIST);
  302. long lNumProviders;
  303. if ( m_bNonsystemProvidersExist ) {
  304. if ( TRUE == pDX->m_bSaveAndValidate ) {
  305. // update the provider array based on list box contents.
  306. lNumProviders = plbInQueryProviders->GetCount();
  307. if (lNumProviders != LB_ERR) {
  308. long lThisProvider;
  309. INT iProvIndex;
  310. // Reset InQuery array, retaining state for eInactive providers.
  311. m_pTraceLogQuery->GetInQueryProviders ( m_arrGenProviders );
  312. // Reset eInQuery to eNotInQuery, in case some were removed from the query.
  313. for ( iProvIndex = 0; iProvIndex < m_arrGenProviders.GetSize(); iProvIndex++ ) {
  314. if ( CSmTraceLogQuery::eInQuery == m_arrGenProviders[iProvIndex] )
  315. m_arrGenProviders[iProvIndex] = CSmTraceLogQuery::eNotInQuery;
  316. }
  317. lThisProvider = 0;
  318. while (lThisProvider < lNumProviders) {
  319. iProvIndex = (INT)plbInQueryProviders->GetItemData( lThisProvider );
  320. m_arrGenProviders[iProvIndex] = CSmTraceLogQuery::eInQuery;
  321. lThisProvider++;
  322. }
  323. }
  324. } else {
  325. // Reset the list box.
  326. CString strProviderName;
  327. INT iProvIndex;
  328. DWORD dwItemExtent;
  329. ASSERT( NULL != m_pTraceLogQuery );
  330. //load nonsystem provider list box from string in provider list
  331. plbInQueryProviders->ResetContent();
  332. for ( iProvIndex = 0; iProvIndex < m_arrGenProviders.GetSize(); iProvIndex++ ) {
  333. if ( CSmTraceLogQuery::eInQuery == m_arrGenProviders[iProvIndex] ) {
  334. INT iAddIndex;
  335. GetProviderDescription( iProvIndex, strProviderName );
  336. iAddIndex = plbInQueryProviders->AddString ( strProviderName );
  337. plbInQueryProviders->SetItemData ( iAddIndex, ( DWORD ) iProvIndex );
  338. // update list box extent
  339. dwItemExtent = (DWORD)((plbInQueryProviders->GetDC())->GetTextExtent (strProviderName)).cx;
  340. if (dwItemExtent > m_dwMaxHorizListExtent) {
  341. m_dwMaxHorizListExtent = dwItemExtent;
  342. plbInQueryProviders->SetHorizontalExtent(dwItemExtent);
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. BOOL
  350. CProvidersProperty::IsValidLocalData( )
  351. {
  352. BOOL bIsValid = TRUE;
  353. ResourceStateManager rsm;
  354. if ( eTraceModeKernel == m_dwTraceMode ) {
  355. DWORD dwKernelFlags = 0;
  356. // Ensure that the user has enabled at least one of the 4 basic Kernel traces.
  357. if ( m_bEnableProcessTrace ) {
  358. dwKernelFlags |= SLQ_TLI_ENABLE_PROCESS_TRACE;
  359. }
  360. if ( m_bEnableThreadTrace ) {
  361. dwKernelFlags |= SLQ_TLI_ENABLE_THREAD_TRACE;
  362. }
  363. if ( m_bEnableDiskIoTrace ) {
  364. dwKernelFlags |= SLQ_TLI_ENABLE_DISKIO_TRACE;
  365. }
  366. if ( m_bEnableNetworkTcpipTrace ) {
  367. dwKernelFlags |= SLQ_TLI_ENABLE_NETWORK_TCPIP_TRACE;
  368. }
  369. if ( 0 == dwKernelFlags ) {
  370. CString strMsg;
  371. strMsg.LoadString ( IDS_KERNEL_PROVIDERS_REQUIRED );
  372. MessageBox ( strMsg, m_pTraceLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  373. GetDlgItem ( IDC_PROV_KERNEL_BTN )->SetFocus();
  374. bIsValid = FALSE;
  375. }
  376. } else {
  377. CListBox * plbInQueryProviders = (CListBox *)GetDlgItem(IDC_PROV_PROVIDER_LIST);
  378. if ( !m_bNonsystemProvidersExist || 0 == plbInQueryProviders->GetCount() ) {
  379. CString strMsg;
  380. strMsg.LoadString ( IDS_APP_PROVIDERS_REQUIRED );
  381. MessageBox ( strMsg, m_pTraceLogQuery->GetLogName(), MB_OK | MB_ICONERROR);
  382. GetDlgItem ( IDC_PROV_ADD_BTN )->SetFocus();
  383. bIsValid = FALSE;
  384. }
  385. }
  386. return bIsValid;
  387. }
  388. void
  389. CProvidersProperty::OnProvTraceModeRdo()
  390. {
  391. UpdateData ( TRUE );
  392. SetModifiedPage ( TRUE );
  393. }
  394. void
  395. CProvidersProperty::OnCancel()
  396. {
  397. m_pTraceLogQuery->SyncPropPageSharedData(); // clear memory shared between property pages.
  398. }
  399. BOOL
  400. CProvidersProperty::OnApply()
  401. {
  402. BOOL bContinue = TRUE;
  403. bContinue = UpdateData ( TRUE );
  404. if ( bContinue ) {
  405. bContinue = IsValidData(m_pTraceLogQuery, VALIDATE_APPLY );
  406. }
  407. // Write the data to the query.
  408. if ( bContinue ) {
  409. if ( eTraceModeKernel == m_dwTraceMode ) {
  410. DWORD dwKernelFlags = 0;
  411. INT iProvIndex;
  412. if ( m_bEnableProcessTrace ) {
  413. dwKernelFlags |= SLQ_TLI_ENABLE_PROCESS_TRACE;
  414. }
  415. if ( m_bEnableThreadTrace ) {
  416. dwKernelFlags |= SLQ_TLI_ENABLE_THREAD_TRACE;
  417. }
  418. if ( m_bEnableDiskIoTrace ) {
  419. dwKernelFlags |= SLQ_TLI_ENABLE_DISKIO_TRACE;
  420. }
  421. if ( m_bEnableNetworkTcpipTrace ) {
  422. dwKernelFlags |= SLQ_TLI_ENABLE_NETWORK_TCPIP_TRACE;
  423. }
  424. // Ensure that the user has enabled at least one of the 4 basic Kernel traces.
  425. ASSERT ( 0 != dwKernelFlags );
  426. if ( m_bEnableMemMgmtTrace ) {
  427. dwKernelFlags |= SLQ_TLI_ENABLE_MEMMAN_TRACE;
  428. }
  429. if ( m_bEnableFileIoTrace ) {
  430. dwKernelFlags |= SLQ_TLI_ENABLE_FILEIO_TRACE;
  431. }
  432. m_pTraceLogQuery->SetKernelFlags (dwKernelFlags);
  433. // Erase all InQuery providers.
  434. for ( iProvIndex = 0; iProvIndex < m_arrGenProviders.GetSize(); iProvIndex++ ) {
  435. if ( CSmTraceLogQuery::eInQuery == m_arrGenProviders[iProvIndex] )
  436. m_arrGenProviders[iProvIndex] = CSmTraceLogQuery::eNotInQuery;
  437. }
  438. m_pTraceLogQuery->SetInQueryProviders ( m_arrGenProviders );
  439. } else {
  440. CListBox * plbInQueryProviders = (CListBox *)GetDlgItem(IDC_PROV_PROVIDER_LIST);
  441. ASSERT ( 0 < plbInQueryProviders->GetCount() );
  442. m_pTraceLogQuery->SetInQueryProviders ( m_arrGenProviders );
  443. // Reset kernel flags
  444. m_pTraceLogQuery->SetKernelFlags (0);
  445. }
  446. }
  447. if ( bContinue ) {
  448. bContinue = Apply(m_pTraceLogQuery);
  449. }
  450. if ( bContinue ){
  451. bContinue = CPropertyPage::OnApply();
  452. }
  453. if ( bContinue ) {
  454. // Save property page shared data.
  455. m_pTraceLogQuery->UpdatePropPageSharedData();
  456. bContinue = UpdateService ( m_pTraceLogQuery, TRUE );
  457. }
  458. return bContinue;
  459. }
  460. BOOL CProvidersProperty::OnInitDialog()
  461. {
  462. DWORD dwStatus;
  463. DWORD dwKernelFlags;
  464. CListBox * plbInQueryProviders;
  465. BOOL bDeleteInactiveProviders = FALSE;
  466. INT iIndex;
  467. ResourceStateManager rsm;
  468. //
  469. // Here m_pTraceLogQuery should not be NULL, if it is,
  470. // There must be something wrong.
  471. //
  472. if ( NULL == m_pTraceLogQuery ) {
  473. return TRUE;
  474. }
  475. m_bCanAccessRemoteWbem = m_pTraceLogQuery->GetLogService()->CanAccessWbemRemote();
  476. m_pTraceLogQuery->SetActivePropertyPage( this );
  477. dwStatus = m_pTraceLogQuery->InitGenProvidersArray();
  478. if ( SMCFG_INACTIVE_PROVIDER == dwStatus ) {
  479. CString strMessage;
  480. CString strSysMessage;
  481. INT_PTR iResult;
  482. FormatSmLogCfgMessage (
  483. strMessage,
  484. m_hModule,
  485. SMCFG_INACTIVE_PROVIDER,
  486. m_pTraceLogQuery->GetLogName() );
  487. iIndex = m_pTraceLogQuery->GetFirstInactiveIndex();
  488. while ( -1 != iIndex ) {
  489. CString strNextName;
  490. GetProviderDescription( iIndex, strNextName );
  491. strMessage += _T("\n ");
  492. strMessage += strNextName;
  493. iIndex = m_pTraceLogQuery->GetNextInactiveIndex();
  494. }
  495. iResult = MessageBox(
  496. (LPCWSTR)strMessage,
  497. m_pTraceLogQuery->GetLogName(),
  498. MB_YESNO | MB_ICONWARNING
  499. );
  500. if ( IDYES == iResult ) {
  501. bDeleteInactiveProviders = TRUE;
  502. }
  503. }
  504. // Continue even if no active providers exist.
  505. plbInQueryProviders = (CListBox *)GetDlgItem(IDC_PROV_PROVIDER_LIST);
  506. // Initialize from model.
  507. dwStatus = m_pTraceLogQuery->GetInQueryProviders ( m_arrGenProviders );
  508. if ( bDeleteInactiveProviders ) {
  509. // Delete all inactive providers
  510. iIndex = m_pTraceLogQuery->GetFirstInactiveIndex();
  511. while ( -1 != iIndex ) {
  512. m_arrGenProviders[iIndex] = CSmTraceLogQuery::eNotInQuery;
  513. iIndex = m_pTraceLogQuery->GetNextInactiveIndex();
  514. }
  515. }
  516. m_bNonsystemProvidersExist = FALSE;
  517. for ( iIndex = 0; iIndex < m_arrGenProviders.GetSize(); iIndex++ ) {
  518. if ( m_pTraceLogQuery->IsActiveProvider ( iIndex ) ) {
  519. m_bNonsystemProvidersExist = TRUE;
  520. break;
  521. }
  522. }
  523. m_pTraceLogQuery->GetKernelFlags (dwKernelFlags);
  524. if ( (dwKernelFlags & SLQ_TLI_ENABLE_KERNEL_TRACE) != 0) {
  525. // NT5 Beta2 Kernel trace flag in use to cover all four basic trace.
  526. m_bEnableProcessTrace = TRUE;
  527. m_bEnableThreadTrace = TRUE;
  528. m_bEnableDiskIoTrace = TRUE;
  529. m_bEnableNetworkTcpipTrace = TRUE;
  530. } else {
  531. m_bEnableProcessTrace = (BOOL)((dwKernelFlags & SLQ_TLI_ENABLE_PROCESS_TRACE) != 0);
  532. m_bEnableThreadTrace = (BOOL)((dwKernelFlags & SLQ_TLI_ENABLE_THREAD_TRACE) != 0);
  533. m_bEnableDiskIoTrace = (BOOL)((dwKernelFlags & SLQ_TLI_ENABLE_DISKIO_TRACE) != 0);
  534. m_bEnableNetworkTcpipTrace = (BOOL)((dwKernelFlags & SLQ_TLI_ENABLE_NETWORK_TCPIP_TRACE) != 0);
  535. }
  536. m_bEnableMemMgmtTrace = (BOOL)((dwKernelFlags & SLQ_TLI_ENABLE_MEMMAN_TRACE) != 0);
  537. m_bEnableFileIoTrace = (BOOL)((dwKernelFlags & SLQ_TLI_ENABLE_FILEIO_TRACE) != 0);
  538. m_dwTraceMode = ( 0 != dwKernelFlags ) ? eTraceModeKernel : eTraceModeApplication;
  539. if ( eTraceModeApplication == m_dwTraceMode ) {
  540. // If initial mode is set to Application, initialize the Kernel
  541. // trace events to the default.
  542. m_bEnableProcessTrace = TRUE;
  543. m_bEnableThreadTrace = TRUE;
  544. m_bEnableDiskIoTrace = TRUE;
  545. m_bEnableNetworkTcpipTrace = TRUE;
  546. }
  547. CSmPropertyPage::OnInitDialog();
  548. SetHelpIds ( (DWORD*)&s_aulHelpIds );
  549. Initialize( m_pTraceLogQuery );
  550. m_strUserDisplay = m_pTraceLogQuery->m_strUser;
  551. m_strUserSaved = m_strUserDisplay;
  552. SetDetailsGroupBoxMode();
  553. SetTraceModeState();
  554. if ( m_bNonsystemProvidersExist ) {
  555. if ( 0 < plbInQueryProviders->GetCount() ) {
  556. // select first entry
  557. plbInQueryProviders->SetSel (0, TRUE);
  558. plbInQueryProviders->SetCaretIndex (0, TRUE);
  559. } else {
  560. plbInQueryProviders->SetSel (-1, TRUE);
  561. GetDlgItem(IDC_PROV_ADD_BTN)->SetFocus();
  562. }
  563. } else {
  564. CString strNoProviders;
  565. strNoProviders.LoadString( IDS_PROV_NO_PROVIDERS );
  566. plbInQueryProviders->AddString( strNoProviders );
  567. plbInQueryProviders->EnableWindow(FALSE);
  568. GetDlgItem(IDC_PROV_REMOVE_BTN)->EnableWindow(FALSE);
  569. GetDlgItem(IDC_PROV_ADD_BTN)->EnableWindow(FALSE);
  570. }
  571. if (m_pTraceLogQuery->GetLogService()->IsWindows2000Server()) {
  572. CWnd* pRunAsStatic;
  573. //
  574. // Get the static "Run As" window, you can only call this function
  575. // when "Run As" really exists
  576. //
  577. pRunAsStatic = GetRunAsWindow();
  578. if (pRunAsStatic) {
  579. pRunAsStatic->EnableWindow(FALSE);
  580. }
  581. GetDlgItem(IDC_RUNAS_EDIT)->EnableWindow(FALSE);
  582. }
  583. if (m_pTraceLogQuery->GetLogService()->IsWindows2000Server() ||
  584. m_strUserDisplay.IsEmpty() || m_strUserDisplay.GetAt(0) == L'<') {
  585. GetDlgItem(IDC_SETPWD_BTN)->EnableWindow(FALSE);
  586. m_bPwdButtonEnabled = FALSE;
  587. }
  588. return TRUE; // return TRUE unless you set the focus to a control
  589. // EXCEPTION: OCX Property Pages should return FALSE
  590. }
  591. void CProvidersProperty::PostNcDestroy()
  592. {
  593. // delete this;
  594. if ( NULL != m_pTraceLogQuery ) {
  595. m_pTraceLogQuery->SetActivePropertyPage( NULL );
  596. }
  597. CPropertyPage::PostNcDestroy();
  598. }
  599. //
  600. // Helper functions.
  601. //
  602. void
  603. CProvidersProperty::SetAddRemoveBtnState ( void )
  604. {
  605. if ( m_bNonsystemProvidersExist ) {
  606. if ( eTraceModeKernel == m_dwTraceMode ) {
  607. GetDlgItem(IDC_PROV_REMOVE_BTN)->EnableWindow(FALSE);
  608. GetDlgItem(IDC_PROV_ADD_BTN)->EnableWindow(FALSE);
  609. } else {
  610. CListBox * plbInQueryProviders = (CListBox *)GetDlgItem(IDC_PROV_PROVIDER_LIST);
  611. INT iTotalCount;
  612. iTotalCount = plbInQueryProviders->GetCount();
  613. if ( 0 < plbInQueryProviders->GetSelCount() ) {
  614. GetDlgItem(IDC_PROV_REMOVE_BTN)->EnableWindow(TRUE);
  615. } else {
  616. GetDlgItem(IDC_PROV_REMOVE_BTN)->EnableWindow(FALSE);
  617. }
  618. if ( iTotalCount < m_arrGenProviders.GetSize() ) {
  619. GetDlgItem(IDC_PROV_ADD_BTN)->EnableWindow(TRUE);
  620. } else {
  621. GetDlgItem(IDC_PROV_ADD_BTN)->EnableWindow(FALSE);
  622. }
  623. if ( 0 == iTotalCount ) {
  624. plbInQueryProviders->SetSel(-1);
  625. }
  626. }
  627. }
  628. }
  629. //
  630. // Return the description for the trace provider specified by
  631. // InQuery array index.
  632. //
  633. DWORD
  634. CProvidersProperty::GetProviderDescription ( INT iProvIndex, CString& rstrDesc )
  635. {
  636. ASSERT ( NULL != m_pTraceLogQuery );
  637. rstrDesc = m_pTraceLogQuery->GetProviderDescription ( iProvIndex );
  638. // If the description is empty, build name from guid.
  639. if ( rstrDesc.IsEmpty() ) {
  640. CString strGuid;
  641. ASSERT( !m_pTraceLogQuery->IsActiveProvider( iProvIndex) );
  642. strGuid = m_pTraceLogQuery->GetProviderGuid( iProvIndex );
  643. rstrDesc.Format ( IDS_PROV_UNKNOWN, strGuid );
  644. }
  645. return ERROR_SUCCESS;
  646. }
  647. BOOL
  648. CProvidersProperty::IsEnabledProvider( INT iIndex )
  649. {
  650. ASSERT ( NULL != m_pTraceLogQuery );
  651. return ( m_pTraceLogQuery->IsEnabledProvider ( iIndex ) );
  652. }
  653. BOOL
  654. CProvidersProperty::IsActiveProvider( INT iIndex )
  655. {
  656. ASSERT ( NULL != m_pTraceLogQuery );
  657. return ( m_pTraceLogQuery->IsActiveProvider ( iIndex ) );
  658. }
  659. LPCTSTR
  660. CProvidersProperty::GetKernelProviderDescription( void )
  661. {
  662. ASSERT ( NULL != m_pTraceLogQuery );
  663. return ( m_pTraceLogQuery->GetKernelProviderDescription ( ) );
  664. }
  665. BOOL
  666. CProvidersProperty::GetKernelProviderEnabled( void )
  667. {
  668. ASSERT ( NULL != m_pTraceLogQuery );
  669. return ( m_pTraceLogQuery->GetKernelProviderEnabled ( ) );
  670. }
  671. //
  672. // Update the provided InQuery array to match the stored version.
  673. //
  674. DWORD
  675. CProvidersProperty::GetInQueryProviders( CArray<CSmTraceLogQuery::eProviderState, CSmTraceLogQuery::eProviderState&>& rarrOut )
  676. {
  677. DWORD dwStatus = ERROR_SUCCESS;
  678. int iIndex;
  679. rarrOut.RemoveAll();
  680. rarrOut.SetSize( m_arrGenProviders.GetSize() );
  681. for ( iIndex = 0; iIndex < rarrOut.GetSize(); iIndex++ ) {
  682. rarrOut[iIndex] = m_arrGenProviders[iIndex];
  683. }
  684. return dwStatus;
  685. }
  686. //
  687. // Load the stored InQuery providers array
  688. // based on the provided version.
  689. //
  690. DWORD
  691. CProvidersProperty::SetInQueryProviders( CArray<CSmTraceLogQuery::eProviderState, CSmTraceLogQuery::eProviderState&>& rarrIn )
  692. {
  693. DWORD dwStatus = ERROR_SUCCESS;
  694. int iProvIndex;
  695. m_arrGenProviders.RemoveAll();
  696. m_arrGenProviders.SetSize( rarrIn.GetSize() );
  697. for ( iProvIndex = 0; iProvIndex < m_arrGenProviders.GetSize(); iProvIndex++ ) {
  698. m_arrGenProviders[iProvIndex] = rarrIn[iProvIndex];
  699. }
  700. return dwStatus;
  701. }
  702. void
  703. CProvidersProperty::ImplementAdd( void )
  704. {
  705. INT_PTR iReturn = IDCANCEL;
  706. {
  707. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  708. CProviderListDlg dlgAddProviders(this);
  709. // Workaround for popup to store pointer to this page.
  710. dlgAddProviders.SetProvidersPage( this );
  711. iReturn = dlgAddProviders.DoModal();
  712. }
  713. if ( IDOK == iReturn ) {
  714. LONG lBeforeCount;
  715. LONG lAfterCount;
  716. CListBox *plbProviderList;
  717. plbProviderList = (CListBox *)GetDlgItem(IDC_PROV_PROVIDER_LIST);
  718. // Providers array is modified by the add dialog OnOK procedure.
  719. lBeforeCount = plbProviderList->GetCount();
  720. UpdateData ( FALSE );
  721. lAfterCount = plbProviderList->GetCount();
  722. SetAddRemoveBtnState();
  723. if ( lAfterCount > lBeforeCount ) {
  724. SetModifiedPage ( TRUE );
  725. }
  726. }
  727. }
  728. void
  729. CProvidersProperty::UpdateLogStartString ()
  730. {
  731. eStartType eCurrentStartType;
  732. int nResId = 0;
  733. ResourceStateManager rsm;
  734. eCurrentStartType = DetermineCurrentStartType();
  735. if ( eStartManually == eCurrentStartType ) {
  736. nResId = IDS_LOG_START_MANUALLY;
  737. } else if ( eStartImmediately == eCurrentStartType ) {
  738. nResId = IDS_LOG_START_IMMED;
  739. } else if ( eStartSched == eCurrentStartType ) {
  740. nResId = IDS_LOG_START_SCHED;
  741. }
  742. if ( 0 != nResId ) {
  743. m_strStartText.LoadString(nResId);
  744. } else {
  745. m_strStartText.Empty();
  746. }
  747. return;
  748. }
  749. void
  750. CProvidersProperty::UpdateFileNameString ()
  751. {
  752. m_strFileNameDisplay.Empty();
  753. CreateSampleFileName (
  754. m_pTraceLogQuery->GetLogName(),
  755. m_pTraceLogQuery->GetLogService()->GetMachineName(),
  756. m_SharedData.strFolderName,
  757. m_SharedData.strFileBaseName,
  758. m_SharedData.strSqlName,
  759. m_SharedData.dwSuffix,
  760. m_SharedData.dwLogFileType,
  761. m_SharedData.dwSerialNumber,
  762. m_strFileNameDisplay);
  763. SetDlgItemText( IDC_PROV_FILENAME_DISPLAY, m_strFileNameDisplay );
  764. // Clear the selection
  765. ((CEdit*)GetDlgItem( IDC_PROV_FILENAME_DISPLAY ))->SetSel ( -1, 0 );
  766. return;
  767. }
  768. BOOL
  769. CProvidersProperty::OnSetActive()
  770. {
  771. BOOL bReturn;
  772. bReturn = CSmPropertyPage::OnSetActive();
  773. if (!bReturn) return FALSE;
  774. ResourceStateManager rsm;
  775. m_pTraceLogQuery->GetPropPageSharedData ( &m_SharedData );
  776. UpdateFileNameString();
  777. UpdateLogStartString();
  778. m_strUserDisplay = m_pTraceLogQuery->m_strUser;
  779. UpdateData(FALSE); //to load the edit & combo box
  780. return TRUE;
  781. }
  782. BOOL
  783. CProvidersProperty::OnKillActive()
  784. {
  785. BOOL bContinue = TRUE;
  786. bContinue = CPropertyPage::OnKillActive();
  787. if ( bContinue ) {
  788. m_pTraceLogQuery->m_strUser = m_strUserDisplay;
  789. bContinue = IsValidData(m_pTraceLogQuery, VALIDATE_FOCUS );
  790. }
  791. // The providers page does not modify shared data, so no reason to update it.
  792. if ( bContinue ) {
  793. SetIsActive ( FALSE );
  794. }
  795. return bContinue;
  796. }
  797. void
  798. CProvidersProperty::OnProvKernelEnableCheck()
  799. {
  800. BOOL bMemFlag = m_bEnableMemMgmtTrace;
  801. BOOL bFileFlag = m_bEnableFileIoTrace;
  802. UpdateData(TRUE);
  803. SetModifiedPage(TRUE);
  804. bMemFlag = (!bMemFlag && m_bEnableMemMgmtTrace);
  805. bFileFlag = (!bFileFlag && m_bEnableFileIoTrace);
  806. if (bMemFlag || bFileFlag) {
  807. long nErr;
  808. HKEY hKey;
  809. DWORD dwWarnFlag;
  810. DWORD dwDataType;
  811. DWORD dwDataSize;
  812. DWORD dwDisposition;
  813. // User has checked expensive file io flag
  814. // check registry setting to see if we need to pop up warning dialog
  815. nErr = RegOpenKey( HKEY_CURRENT_USER,
  816. _T("Software\\Microsoft\\PerformanceLogsandAlerts"),
  817. &hKey
  818. );
  819. dwWarnFlag = 0;
  820. if( nErr == ERROR_SUCCESS ) {
  821. dwDataSize = sizeof(DWORD);
  822. nErr = RegQueryValueExW(
  823. hKey,
  824. (bMemFlag ? _T("NoWarnPageFault") : _T("NoWarnFileIo")),
  825. NULL,
  826. &dwDataType,
  827. (LPBYTE) &dwWarnFlag,
  828. (LPDWORD) &dwDataSize
  829. );
  830. if ( (dwDataType != REG_DWORD) || (dwDataSize != sizeof(DWORD)))
  831. dwWarnFlag = 0;
  832. nErr = RegCloseKey( hKey );
  833. if( ERROR_SUCCESS != nErr )
  834. DisplayError( GetLastError(), _T("Close PerfLog user Key Failed") );
  835. }
  836. if (!dwWarnFlag || nErr != ERROR_SUCCESS) {
  837. // Pop a dialog here. Need to do a RegQuerySetValue dialog is checked to keep quiet
  838. // bMemFlag & bFileFlag gives a clue about what it is doing
  839. CWarnDlg WarnDlg;
  840. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  841. WarnDlg.SetProvidersPage( this );
  842. if (IDOK == WarnDlg.DoModal()){
  843. if (WarnDlg.m_CheckNoMore){
  844. dwWarnFlag = WarnDlg.m_CheckNoMore;
  845. nErr = RegCreateKeyEx( HKEY_CURRENT_USER,
  846. _T("Software\\Microsoft\\PerformanceLogsAndAlerts"),
  847. 0,
  848. _T("REG_DWORD"),
  849. REG_OPTION_NON_VOLATILE,
  850. KEY_ALL_ACCESS,
  851. NULL,
  852. &hKey,
  853. &dwDisposition);
  854. if(ERROR_SUCCESS == nErr){
  855. if (dwDisposition == REG_CREATED_NEW_KEY){
  856. //just in case I need this
  857. }else if (dwDisposition == REG_OPENED_EXISTING_KEY){
  858. //Just in case I need this
  859. }
  860. }
  861. if( nErr == ERROR_SUCCESS ) {
  862. dwDataSize = sizeof(DWORD);
  863. nErr = RegSetValueEx(hKey,
  864. (bMemFlag ? _T("NoWarnPageFault") : _T("NoWarnFileIo") ),
  865. NULL,
  866. REG_DWORD,
  867. (LPBYTE) &dwWarnFlag,
  868. dwDataSize
  869. );
  870. if( ERROR_SUCCESS != nErr )
  871. DisplayError( GetLastError(), _T("Close PerfLog User Key failed") );
  872. }
  873. }
  874. }
  875. }
  876. }
  877. }
  878. void
  879. CProvidersProperty::OnProvShowProvBtn()
  880. {
  881. CActiveProviderDlg ProvLstDlg;
  882. AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
  883. ProvLstDlg.SetProvidersPage( this );
  884. ProvLstDlg.DoModal();
  885. }
  886. /*
  887. void
  888. CProvidersProperty::OnProvDetailsBtn()
  889. {
  890. SetDetailsGroupBoxMode();
  891. }
  892. */
  893. BOOL
  894. CProvidersProperty::SetDetailsGroupBoxMode()
  895. {
  896. UINT nWindowState;
  897. ResourceStateManager rsm;
  898. nWindowState = SW_SHOW;
  899. GetDlgItem(IDC_PROV_K_PROCESS_CHK)->ShowWindow(nWindowState);
  900. GetDlgItem(IDC_PROV_K_THREAD_CHK)->ShowWindow(nWindowState);
  901. GetDlgItem(IDC_PROV_K_DISK_IO_CHK)->ShowWindow(nWindowState);
  902. GetDlgItem(IDC_PROV_K_NETWORK_CHK)->ShowWindow(nWindowState);
  903. GetDlgItem(IDC_PROV_K_SOFT_PF_CHK)->ShowWindow(nWindowState);
  904. GetDlgItem(IDC_PROV_K_FILE_IO_CHK)->ShowWindow(nWindowState);
  905. return TRUE;
  906. }
  907. void
  908. CProvidersProperty::TraceModeRadioExchange(CDataExchange* pDX)
  909. {
  910. if ( !pDX->m_bSaveAndValidate ) {
  911. // Load control value from data
  912. switch ( m_dwTraceMode ) {
  913. case eTraceModeKernel:
  914. m_nTraceModeRdo = 0;
  915. break;
  916. case eTraceModeApplication:
  917. m_nTraceModeRdo = 1;
  918. break;
  919. default:
  920. ;
  921. break;
  922. }
  923. }
  924. DDX_Radio(pDX, IDC_PROV_KERNEL_BTN, m_nTraceModeRdo);
  925. if ( pDX->m_bSaveAndValidate ) {
  926. switch ( m_nTraceModeRdo ) {
  927. case 0:
  928. m_dwTraceMode = eTraceModeKernel;
  929. break;
  930. case 1:
  931. m_dwTraceMode = eTraceModeApplication;
  932. break;
  933. default:
  934. ;
  935. break;
  936. }
  937. SetTraceModeState();
  938. }
  939. }
  940. void
  941. CProvidersProperty::SetTraceModeState ( void )
  942. {
  943. BOOL bEnable;
  944. bEnable = (eTraceModeKernel == m_dwTraceMode) ? TRUE : FALSE;
  945. // Kernel trace controls
  946. // GetDlgItem(IDC_PROV_SHOW_ADV_BTN)->EnableWindow(bEnable);
  947. GetDlgItem(IDC_PROV_K_PROCESS_CHK)->EnableWindow(bEnable);
  948. GetDlgItem(IDC_PROV_K_THREAD_CHK)->EnableWindow(bEnable);
  949. GetDlgItem(IDC_PROV_K_DISK_IO_CHK)->EnableWindow(bEnable);
  950. GetDlgItem(IDC_PROV_K_NETWORK_CHK)->EnableWindow(bEnable);
  951. GetDlgItem(IDC_PROV_K_SOFT_PF_CHK)->EnableWindow(bEnable);
  952. GetDlgItem(IDC_PROV_K_FILE_IO_CHK)->EnableWindow(bEnable);
  953. if ( m_bNonsystemProvidersExist ) {
  954. bEnable = !bEnable;
  955. // Application trace controls
  956. GetDlgItem(IDC_PROV_PROVIDER_LIST)->EnableWindow(bEnable);
  957. SetAddRemoveBtnState();
  958. }
  959. }
  960. DWORD
  961. CProvidersProperty::GetGenProviderCount ( INT& iCount )
  962. {
  963. return m_pTraceLogQuery->GetGenProviderCount( iCount );
  964. }
  965. void CProvidersProperty::GetMachineDisplayName ( CString& rstrMachineName )
  966. {
  967. m_pTraceLogQuery->GetMachineDisplayName( rstrMachineName );
  968. return;
  969. }
  970. CSmTraceLogQuery*
  971. CProvidersProperty::GetTraceQuery ( void )
  972. {
  973. return m_pTraceLogQuery;
  974. }