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.

919 lines
26 KiB

  1. /*++
  2. Copyright (C) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. smproppg.cpp
  5. Abstract:
  6. Implementation of the property page base class.
  7. --*/
  8. #include "stdafx.h"
  9. #include <wbemidl.h>
  10. #include "smcfgmsg.h"
  11. #include "smlogs.h"
  12. #include "smproppg.h"
  13. #include "dialogs.h"
  14. #include <pdhp.h>
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. USE_HANDLE_MACROS("SMLOGCFG(smproppg.cpp)");
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CSmPropertyPage property page
  23. IMPLEMENT_DYNCREATE ( CSmPropertyPage, CPropertyPage )
  24. CSmPropertyPage::CSmPropertyPage (
  25. UINT nIDTemplate,
  26. LONG_PTR hConsole,
  27. LPDATAOBJECT pDataObject )
  28. : CPropertyPage ( nIDTemplate ),
  29. m_bIsActive ( FALSE ),
  30. m_bIsModifiedPage ( FALSE ),
  31. m_pdwHelpIds ( NULL ),
  32. m_hConsole (hConsole ),
  33. m_pDataObject ( pDataObject ),
  34. m_bCanAccessRemoteWbem ( FALSE ),
  35. m_bPwdButtonEnabled ( TRUE )
  36. {
  37. //::OutputDebugStringA("\nCSmProperty::CSmPropertyPage");
  38. // Need to save the original callback pointer because we are replacing
  39. // it with our own
  40. m_pfnOriginalCallback = m_psp.pfnCallback;
  41. // This makes sure the MFC module states will work correctly
  42. MMCPropPageCallback( &m_psp );
  43. // EnableAutomation();
  44. //{{AFX_DATA_INIT(CSmPropertyPage)
  45. //}}AFX_DATA_INIT
  46. m_hModule = (HINSTANCE)GetModuleHandleW (_CONFIG_DLL_NAME_W_);
  47. }
  48. CSmPropertyPage::CSmPropertyPage() : CPropertyPage(0xfff) // Unused template IDD
  49. {
  50. ASSERT (FALSE); // the constructor w/ args should be used instead
  51. // //{{AFX_DATA_INIT(CSmPropertyPage)
  52. // //}}AFX_DATA_INIT
  53. }
  54. CSmPropertyPage::~CSmPropertyPage()
  55. {
  56. }
  57. BEGIN_MESSAGE_MAP(CSmPropertyPage, CPropertyPage)
  58. //{{AFX_MSG_MAP(CSmPropertyPage)
  59. ON_WM_HELPINFO()
  60. ON_WM_CONTEXTMENU()
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CSmPropertyPage message handlers
  65. UINT CALLBACK CSmPropertyPage::PropSheetPageProc
  66. (
  67. HWND hWnd, // [in] Window handle - always null
  68. UINT uMsg, // [in,out] Either the create or delete message
  69. LPPROPSHEETPAGE pPsp // [in,out] Pointer to the property sheet struct
  70. )
  71. {
  72. ASSERT( NULL != pPsp );
  73. // We need to recover a pointer to the current instance. We can't just use
  74. // "this" because we are in a static function
  75. CSmPropertyPage* pMe = reinterpret_cast<CSmPropertyPage*>(pPsp->lParam);
  76. ASSERT( NULL != pMe );
  77. if (!pMe) return 0;
  78. switch( uMsg )
  79. {
  80. case PSPCB_CREATE:
  81. break;
  82. case PSPCB_RELEASE:
  83. // Since we are deleting ourselves, save a callback on the stack
  84. // so we can callback the base class
  85. //LPFNPSPCALLBACK pfnOrig = pMe->m_pfnOriginalCallback;
  86. delete pMe;
  87. return 1; //(pfnOrig)(hWnd, uMsg, pPsp);
  88. }
  89. // Must call the base class callback function or none of the MFC
  90. // message map stuff will work
  91. return (pMe->m_pfnOriginalCallback)(hWnd, uMsg, pPsp);
  92. } // end PropSheetPageProc()
  93. BOOL
  94. CSmPropertyPage::Initialize(CSmLogQuery* pQuery)
  95. {
  96. HRESULT hr;
  97. PPDH_PLA_INFO pInfo = NULL;
  98. DWORD dwInfoSize = 0;
  99. CString strMachineName;
  100. LPCWSTR pszMachineName = NULL;
  101. if ( NULL != pQuery ) {
  102. if (!pQuery->GetLogService()->IsLocalMachine()) {
  103. pszMachineName = pQuery->GetLogService()->GetMachineName();
  104. }
  105. hr = PdhPlaGetInfoW( (LPWSTR)(LPCWSTR)pQuery->GetLogName(),
  106. (LPWSTR)pszMachineName,
  107. &dwInfoSize,
  108. pInfo );
  109. if( ERROR_SUCCESS == hr && 0 != dwInfoSize ){
  110. pInfo = (PPDH_PLA_INFO)malloc(dwInfoSize);
  111. if( NULL != pInfo ) {
  112. if ( sizeof(PDH_PLA_INFO) <= dwInfoSize ) {
  113. pInfo->dwMask = PLA_INFO_FLAG_USER;
  114. hr = PdhPlaGetInfoW( (LPWSTR)(LPCWSTR)pQuery->GetLogName(),
  115. (LPWSTR)pszMachineName,
  116. &dwInfoSize,
  117. pInfo );
  118. if( ERROR_SUCCESS == hr ){
  119. pQuery->m_strUser = pInfo->strUser;
  120. }
  121. }
  122. free( pInfo );
  123. }
  124. pQuery->m_fDirtyPassword = PASSWORD_CLEAN;
  125. }
  126. }
  127. return TRUE;
  128. }
  129. BOOL
  130. CSmPropertyPage::OnInitDialog()
  131. {
  132. DWORD dwExStyle = 0;
  133. CWnd* pwndPropSheet;
  134. pwndPropSheet = GetParentOwner();
  135. if ( NULL != pwndPropSheet ) {
  136. dwExStyle = pwndPropSheet->GetExStyle();
  137. pwndPropSheet->ModifyStyleEx ( NULL, WS_EX_CONTEXTHELP );
  138. }
  139. return CPropertyPage::OnInitDialog();
  140. }
  141. BOOL
  142. CSmPropertyPage::OnSetActive()
  143. {
  144. m_bIsActive = TRUE;
  145. return CPropertyPage::OnSetActive();
  146. }
  147. BOOL
  148. CSmPropertyPage::OnHelpInfo(HELPINFO* pHelpInfo)
  149. {
  150. ASSERT ( NULL != m_pdwHelpIds );
  151. if ( NULL != pHelpInfo ) {
  152. if ( pHelpInfo->iCtrlId >= GetFirstHelpCtrlId() ) {
  153. InvokeWinHelp(
  154. WM_HELP,
  155. NULL,
  156. (LPARAM)pHelpInfo,
  157. GetContextHelpFilePath(),
  158. m_pdwHelpIds ); //s_aulHelpIds);
  159. }
  160. } else {
  161. ASSERT ( FALSE );
  162. }
  163. return TRUE;
  164. }
  165. void
  166. CSmPropertyPage::OnContextMenu(CWnd* pWnd, CPoint /* point */)
  167. {
  168. ASSERT ( NULL != m_pdwHelpIds );
  169. if ( NULL != pWnd ) {
  170. InvokeWinHelp (
  171. WM_CONTEXTMENU,
  172. (WPARAM)(pWnd->m_hWnd),
  173. NULL,
  174. GetContextHelpFilePath(),
  175. m_pdwHelpIds );
  176. }
  177. return;
  178. }
  179. /////////////////////////////////////////////////////////////////////////////
  180. // CSmPropertyPage helper methods
  181. BOOL
  182. CSmPropertyPage::UpdateService( CSmLogQuery* pQuery, BOOL bSyncSerial )
  183. {
  184. DWORD dwStatus = ERROR_SUCCESS;
  185. BOOL bIsValid = FALSE;
  186. BOOL bRegistryUpdated;
  187. CString strMessage;
  188. CString strMachineName;
  189. CString strSysMessage;
  190. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  191. if ( NULL != pQuery ) {
  192. {
  193. CWaitCursor WaitCursor;
  194. // Update the service with changes.
  195. // Sync changes made by service to properties not modified by this page.
  196. if ( bSyncSerial ) {
  197. dwStatus = pQuery->SyncSerialNumberWithRegistry();
  198. }
  199. if ( ERROR_SUCCESS == dwStatus ) {
  200. dwStatus = pQuery->UpdateService ( bRegistryUpdated );
  201. }
  202. }
  203. if ( ERROR_SUCCESS == dwStatus ) {
  204. bIsValid = TRUE;
  205. } else {
  206. bIsValid = FALSE;
  207. if ( ERROR_KEY_DELETED == dwStatus ) {
  208. strMessage.LoadString( IDS_ERRMSG_QUERY_DELETED );
  209. } else if ( ERROR_ACCESS_DENIED == dwStatus ) {
  210. pQuery->GetMachineDisplayName( strMachineName );
  211. FormatSmLogCfgMessage (
  212. strMessage,
  213. m_hModule,
  214. SMCFG_NO_MODIFY_ACCESS,
  215. (LPCTSTR)strMachineName);
  216. } else {
  217. FormatMessage (
  218. FORMAT_MESSAGE_FROM_SYSTEM,
  219. NULL,
  220. dwStatus,
  221. 0,
  222. strSysMessage.GetBufferSetLength( MAX_PATH ),
  223. MAX_PATH,
  224. NULL );
  225. strSysMessage.ReleaseBuffer();
  226. if ( strSysMessage.IsEmpty() ) {
  227. strSysMessage.Format ( _T("0x%08lX"), dwStatus );
  228. }
  229. strMessage.Format( IDS_ERRMSG_SERVICE_ERROR, pQuery->GetLogName() );
  230. strMessage += strSysMessage;
  231. }
  232. MessageBox ( strMessage, pQuery->GetLogName(), MB_OK | MB_ICONERROR );
  233. }
  234. } else {
  235. ASSERT ( FALSE );
  236. }
  237. return bIsValid;
  238. }
  239. void
  240. CSmPropertyPage::ValidateTextEdit (
  241. CDataExchange* pDX,
  242. int nIDC,
  243. int nMaxChars,
  244. DWORD* pValue,
  245. DWORD /* minValue */,
  246. DWORD /* maxValue */)
  247. {
  248. HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
  249. LONG currentValue = INVALID_DWORD;
  250. TCHAR szT[MAXSTR];
  251. CString strTemp;
  252. if ( NULL != pDX && NULL != pValue ) {
  253. if (pDX->m_bSaveAndValidate) {
  254. *pValue = (DWORD) currentValue;
  255. ::GetWindowText(hWndCtrl, szT, MAXSTR);
  256. strTemp = szT;
  257. DDV_MaxChars(pDX, strTemp, nMaxChars);
  258. if (szT[0] >= _T('0') && szT[0] <= _T('9'))
  259. {
  260. currentValue = _wtol(szT);
  261. *pValue = (DWORD) currentValue;
  262. }
  263. } else {
  264. if ( INVALID_DWORD != *pValue ) {
  265. wsprintf(szT, _T("%lu"), *pValue);
  266. } else {
  267. szT[0] = _T('\0');
  268. }
  269. GetDlgItem(nIDC)->SetWindowText(szT);
  270. }
  271. } else {
  272. ASSERT ( FALSE );
  273. }
  274. }
  275. BOOL
  276. CSmPropertyPage::ValidateDWordInterval(
  277. int nIDC,
  278. LPCWSTR strLogName,
  279. long lValue,
  280. DWORD minValue,
  281. DWORD maxValue )
  282. {
  283. CString strMsg;
  284. BOOL bResult = (lValue >= (long) minValue)
  285. && (lValue <= (long) maxValue);
  286. if (! bResult)
  287. {
  288. strMsg.Format ( IDS_ERRMSG_INVALIDDWORD, minValue, maxValue );
  289. MessageBox(strMsg, strLogName, MB_OK | MB_ICONERROR);
  290. GetDlgItem(nIDC)->SetFocus();
  291. strMsg.Empty();
  292. }
  293. return (bResult);
  294. }
  295. void
  296. CSmPropertyPage::OnDeltaposSpin(
  297. NMHDR *pNMHDR,
  298. LRESULT *pResult,
  299. DWORD *pValue,
  300. DWORD dMinValue,
  301. DWORD dMaxValue)
  302. {
  303. NM_UPDOWN* pNMUpDown;
  304. LONG lValue;
  305. BOOL bResult = TRUE;
  306. UpdateData(TRUE);
  307. ASSERT(dMinValue <= dMaxValue);
  308. if ( NULL != pNMHDR
  309. && NULL != pResult
  310. && NULL != pValue )
  311. {
  312. pNMUpDown = (NM_UPDOWN *) pNMHDR;
  313. lValue = (LONG) (*pValue);
  314. if (lValue == INVALID_DWORD) {
  315. lValue = (DWORD) dMinValue;
  316. }
  317. if ( ((lValue >= (LONG) dMinValue + 1) && (pNMUpDown->iDelta > 0))
  318. || ((lValue <= (LONG) dMaxValue - 1) && (pNMUpDown->iDelta < 0)))
  319. {
  320. lValue += (pNMUpDown->iDelta * -1);
  321. if (lValue > (LONG) dMaxValue) {
  322. lValue = (DWORD) dMaxValue;
  323. } else if (lValue < (LONG) dMinValue) {
  324. lValue = (DWORD) dMinValue;
  325. }
  326. } else if (lValue > (LONG) dMaxValue) {
  327. lValue = (DWORD) dMaxValue;
  328. } else if (lValue < (LONG) dMinValue) {
  329. lValue = (DWORD) dMinValue;
  330. } else {
  331. bResult = FALSE;
  332. }
  333. if (bResult) {
  334. *pValue = lValue;
  335. UpdateData(FALSE);
  336. SetModifiedPage(TRUE);
  337. }
  338. *pResult = 0;
  339. } else {
  340. ASSERT ( FALSE );
  341. }
  342. return;
  343. }
  344. BOOL
  345. CSmPropertyPage::SampleTimeIsLessThanSessionTime( CSmLogQuery* pQuery )
  346. {
  347. BOOL bIsValid = TRUE;
  348. SYSTEMTIME stLocalTime;
  349. LONGLONG llMaxStartTime;
  350. LONGLONG llSessionMilliseconds = 0;
  351. LONGLONG llSampleMilliseconds = 0;
  352. CString strMsg;
  353. ResourceStateManager rsm;
  354. if ( NULL != pQuery ) {
  355. if ( SLQ_TRACE_LOG != pQuery->GetLogType() ) {
  356. if ( SLQ_AUTO_MODE_AT == m_SharedData.stiStopTime.dwAutoMode ) {
  357. GetLocalTime (&stLocalTime);
  358. SystemTimeToFileTime (&stLocalTime, (FILETIME *)&llMaxStartTime);
  359. // For Manual Start mode, Now is used to determine session length.
  360. // For Start At mode, the later of Now vs. schedule start time
  361. // is used to determine session length.
  362. if ( SLQ_AUTO_MODE_AT == m_SharedData.stiStartTime.dwAutoMode ) {
  363. if ( m_SharedData.stiStartTime.llDateTime > llMaxStartTime ) {
  364. llMaxStartTime = m_SharedData.stiStartTime.llDateTime;
  365. }
  366. }
  367. // Calc and compare session seconds vs. sample seconds
  368. TimeInfoToMilliseconds ( &m_SharedData.stiSampleTime, &llSampleMilliseconds );
  369. llSessionMilliseconds = m_SharedData.stiStopTime.llDateTime - llMaxStartTime;
  370. llSessionMilliseconds /= FILETIME_TICS_PER_MILLISECOND;
  371. if ( llSessionMilliseconds < llSampleMilliseconds ) {
  372. strMsg.LoadString ( IDS_SCHED_SESSION_TOO_SHORT );
  373. MessageBox(strMsg, pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  374. strMsg.Empty();
  375. bIsValid = FALSE;
  376. }
  377. } else if ( SLQ_AUTO_MODE_AFTER == m_SharedData.stiStopTime.dwAutoMode ) {
  378. TimeInfoToMilliseconds ( &m_SharedData.stiStopTime, &llSessionMilliseconds );
  379. TimeInfoToMilliseconds ( &m_SharedData.stiSampleTime, &llSampleMilliseconds );
  380. if ( llSessionMilliseconds < llSampleMilliseconds ) {
  381. strMsg.LoadString ( IDS_SCHED_SESSION_TOO_SHORT );
  382. MessageBox(strMsg, pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  383. strMsg.Empty();
  384. bIsValid = FALSE;
  385. }
  386. }
  387. }
  388. } else {
  389. ASSERT ( FALSE );
  390. bIsValid = FALSE;
  391. }
  392. return bIsValid;
  393. }
  394. BOOL
  395. CSmPropertyPage::Apply( CSmLogQuery* pQuery )
  396. {
  397. DWORD dwStatus = ERROR_SUCCESS;
  398. TCHAR strComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  399. CString strComputer;
  400. DWORD dwSize = MAX_COMPUTERNAME_LENGTH + 1;
  401. BOOL bReturn = TRUE;
  402. HRESULT hr = NOERROR;
  403. if ( NULL != pQuery ) {
  404. if( pQuery->m_fDirtyPassword & (PASSWORD_DIRTY|PASSWORD_SET) ){
  405. pQuery->m_fDirtyPassword = PASSWORD_CLEAN;
  406. strComputer = pQuery->GetLogService()->GetMachineName();
  407. if( strComputer.IsEmpty() ){
  408. bReturn = GetComputerName( strComputerName, &dwSize );
  409. if ( !bReturn ) {
  410. dwStatus = GetLastError();
  411. } else {
  412. strComputer = strComputerName;
  413. }
  414. }
  415. pQuery->m_strUser.TrimLeft();
  416. pQuery->m_strUser.TrimRight();
  417. if( pQuery->m_strUser.GetLength() ) {
  418. dwStatus = PdhPlaSetRunAs(
  419. (LPTSTR)(LPCTSTR)pQuery->GetLogName(),
  420. (LPTSTR)(LPCTSTR)strComputer,
  421. (LPTSTR)(LPCTSTR)pQuery->m_strUser,
  422. (LPTSTR)(LPCTSTR)pQuery->m_strPassword
  423. );
  424. } else {
  425. dwStatus = PdhPlaSetRunAs(
  426. (LPTSTR)(LPCTSTR)pQuery->GetLogName(),
  427. (LPTSTR)(LPCTSTR)strComputer,
  428. _T(""),
  429. _T("")
  430. );
  431. }
  432. }
  433. if ( ERROR_SUCCESS == dwStatus
  434. && bReturn
  435. && NULL != m_hConsole
  436. && NULL != m_pDataObject) {
  437. // Only changes on the schedule page cause notification,
  438. // because only schedule changes cause a state change that is
  439. // visible in the result pane.
  440. hr = MMCPropertyChangeNotify (
  441. m_hConsole, // handle to a notification
  442. (LPARAM) m_pDataObject); // unique identifier
  443. }
  444. if ( ERROR_SUCCESS != dwStatus ) {
  445. bReturn = FALSE;
  446. }
  447. } else {
  448. ASSERT ( FALSE );
  449. bReturn = FALSE;
  450. }
  451. return bReturn;
  452. }
  453. void
  454. CSmPropertyPage::SetRunAs( CSmLogQuery* pQuery )
  455. {
  456. CPasswordDlg dlg;
  457. if ( NULL != pQuery ) {
  458. dlg.SetContextHelpFilePath( GetContextHelpFilePath() );
  459. pQuery->m_strUser.TrimLeft();
  460. pQuery->m_strUser.TrimRight();
  461. dlg.m_strUserName = pQuery->m_strUser;
  462. //
  463. // If we want to reset the RunAs information
  464. //
  465. if (pQuery->m_strUser.IsEmpty() || pQuery->m_strUser.GetAt(0) == L'<' ) {
  466. pQuery->m_strPassword = L"";
  467. pQuery->m_strUser = L"";
  468. pQuery->m_fDirtyPassword |= PASSWORD_SET;
  469. } else {
  470. if( dlg.DoModal() != IDCANCEL ){
  471. pQuery->m_strPassword = dlg.m_strPassword1;
  472. pQuery->m_strUser = dlg.m_strUserName;
  473. SetModifiedPage(TRUE);
  474. pQuery->m_fDirtyPassword |= PASSWORD_SET;
  475. }
  476. }
  477. } else {
  478. ASSERT ( FALSE );
  479. }
  480. }
  481. BOOL
  482. CSmPropertyPage::IsValidData( CSmLogQuery* pQuery, DWORD fReason )
  483. {
  484. BOOL bIsValid = TRUE;
  485. CString strTestFileName;
  486. INT iPrevLength = 0;
  487. if ( NULL != pQuery ) {
  488. if ( bIsValid ) {
  489. if ( !IsActive() ) {
  490. pQuery->GetPropPageSharedData ( &m_SharedData );
  491. }
  492. }
  493. if( bIsValid && (fReason & VALIDATE_APPLY ) ){
  494. bIsValid = IsWritableQuery( pQuery );
  495. }
  496. if( bIsValid ){
  497. bIsValid = IsValidLocalData();
  498. }
  499. if( bIsValid ){
  500. if( (pQuery->m_fDirtyPassword & PASSWORD_DIRTY) && !(pQuery->m_fDirtyPassword & PASSWORD_SET) ){
  501. // Note: Trimming can be moved to SetRunAs. Left outside
  502. // for clarity.
  503. iPrevLength = m_strUserDisplay.GetLength();
  504. m_strUserDisplay.TrimLeft();
  505. m_strUserDisplay.TrimRight();
  506. SetRunAs( pQuery );
  507. if ( iPrevLength != m_strUserDisplay.GetLength() ) {
  508. SetDlgItemText ( IDC_RUNAS_EDIT, m_strUserDisplay );
  509. }
  510. if( !(pQuery->m_fDirtyPassword & PASSWORD_SET) ){
  511. bIsValid = FALSE;
  512. }
  513. }
  514. }
  515. // Validate log file name and folder for filetypes
  516. if ( bIsValid
  517. && SLQ_ALERT != pQuery->GetLogType()
  518. && (fReason & VALIDATE_APPLY ) ) {
  519. if ( pQuery->GetLogService()->IsLocalMachine() ) {
  520. if ( SLF_SQL_LOG != m_SharedData.dwLogFileType ) {
  521. // bIsValid is returned as FALSE if the user cancels directory creation.
  522. ProcessDirPath (
  523. m_SharedData.strFolderName,
  524. pQuery->GetLogName(),
  525. this,
  526. bIsValid,
  527. FALSE );
  528. }
  529. }
  530. if ( bIsValid ) {
  531. CreateSampleFileName (
  532. pQuery->GetLogName(),
  533. pQuery->GetLogService()->GetMachineName(),
  534. m_SharedData.strFolderName,
  535. m_SharedData.strFileBaseName,
  536. m_SharedData.strSqlName,
  537. m_SharedData.dwSuffix,
  538. m_SharedData.dwLogFileType,
  539. m_SharedData.dwSerialNumber,
  540. strTestFileName);
  541. if ( MAX_PATH <= strTestFileName.GetLength() ) {
  542. CString strMessage;
  543. strMessage.LoadString ( IDS_FILENAMETOOLONG );
  544. MessageBox ( strMessage, pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  545. bIsValid = FALSE;
  546. }
  547. }
  548. }
  549. } else {
  550. ASSERT ( FALSE );
  551. bIsValid = FALSE;
  552. }
  553. return bIsValid;
  554. }
  555. BOOL
  556. CSmPropertyPage::IsWritableQuery( CSmLogQuery* pQuery )
  557. {
  558. BOOL bIsValid = FALSE;
  559. if ( NULL != pQuery ) {
  560. bIsValid = !pQuery->IsExecuteOnly() && !pQuery->IsReadOnly();
  561. if ( !bIsValid ) {
  562. CString strMessage;
  563. CString strMachineName;
  564. DWORD dwMessageId;
  565. pQuery->GetMachineDisplayName( strMachineName );
  566. dwMessageId = pQuery->IsExecuteOnly() ? SMCFG_NO_MODIFY_DEFAULT_LOG : SMCFG_NO_MODIFY_ACCESS;
  567. FormatSmLogCfgMessage (
  568. strMessage,
  569. m_hModule,
  570. dwMessageId,
  571. (LPCTSTR)strMachineName );
  572. MessageBox ( strMessage, pQuery->GetLogName(), MB_OK | MB_ICONERROR);
  573. }
  574. } else {
  575. ASSERT ( FALSE );
  576. }
  577. return bIsValid;
  578. }
  579. BOOL
  580. CSmPropertyPage::SampleIntervalIsInRange(
  581. SLQ_TIME_INFO& rstiSample,
  582. const CString& rstrQueryName )
  583. {
  584. LONGLONG llMillisecondSampleInt;
  585. BOOL bIsValid = TRUE;
  586. // 45 days in milliseconds = 1000*60*60*24*45
  587. #define FORTYFIVE_DAYS (0xE7BE2C00)
  588. TimeInfoToMilliseconds (&rstiSample, &llMillisecondSampleInt );
  589. bIsValid = ( FORTYFIVE_DAYS >= llMillisecondSampleInt );
  590. if ( !bIsValid ) {
  591. CString strMessage;
  592. strMessage.LoadString ( IDS_ERRMSG_SAMPLEINTTOOLARGE );
  593. MessageBox ( strMessage, rstrQueryName, MB_OK | MB_ICONERROR);
  594. }
  595. return bIsValid;
  596. }
  597. DWORD
  598. CSmPropertyPage::SetContextHelpFilePath( const CString& rstrPath )
  599. {
  600. DWORD dwStatus = ERROR_SUCCESS;
  601. MFC_TRY
  602. m_strContextHelpFilePath = rstrPath;
  603. MFC_CATCH_DWSTATUS
  604. return dwStatus;
  605. }
  606. void
  607. CSmPropertyPage::SetModifiedPage( const BOOL bModified )
  608. {
  609. m_bIsModifiedPage = bModified;
  610. SetModified ( bModified );
  611. return;
  612. }
  613. CSmPropertyPage::eStartType
  614. CSmPropertyPage::DetermineCurrentStartType( void )
  615. {
  616. eStartType eCurrentStartType;
  617. SLQ_TIME_INFO* pstiStart;
  618. SLQ_TIME_INFO* pstiStop;
  619. SYSTEMTIME stLocalTime;
  620. FILETIME ftLocalTime;
  621. LONGLONG llLocalTime;
  622. ResourceStateManager rsm;
  623. pstiStart = &m_SharedData.stiStartTime;
  624. ASSERT ( SLQ_TT_TTYPE_START == pstiStart->wTimeType );
  625. if ( SLQ_AUTO_MODE_NONE == pstiStart->dwAutoMode ) {
  626. if ( pstiStart->llDateTime != MIN_TIME_VALUE ) {
  627. eCurrentStartType = eStartManually;
  628. } else {
  629. eCurrentStartType = eStartImmediately;
  630. }
  631. } else {
  632. GetLocalTime (&stLocalTime);
  633. SystemTimeToFileTime (&stLocalTime, &ftLocalTime);
  634. llLocalTime = *((LONGLONG *)(&ftLocalTime));
  635. // Test current time to determine most appropriate text
  636. if (llLocalTime < pstiStart->llDateTime) {
  637. // then the start time is in the future
  638. eCurrentStartType = eStartSched;
  639. } else {
  640. // Start immediately, unless manual or scheduled stop time is already past.
  641. pstiStop = &m_SharedData.stiStopTime;
  642. if ( SLQ_AUTO_MODE_NONE == pstiStop->dwAutoMode
  643. && llLocalTime > pstiStop->llDateTime ) {
  644. eCurrentStartType = eStartManually;
  645. } else {
  646. eCurrentStartType = eStartImmediately;
  647. }
  648. }
  649. }
  650. return eCurrentStartType;
  651. }
  652. DWORD
  653. CSmPropertyPage::AllocInitCounterPath(
  654. const LPTSTR szCounterPath,
  655. PPDH_COUNTER_PATH_ELEMENTS* ppCounter )
  656. {
  657. DWORD dwStatus = ERROR_SUCCESS;
  658. PDH_STATUS pdhStatus = ERROR_SUCCESS;
  659. PPDH_COUNTER_PATH_ELEMENTS pLocalCounter = NULL;
  660. ULONG ulBufSize = 0;
  661. if ( NULL != szCounterPath && NULL != ppCounter ) {
  662. *ppCounter = NULL;
  663. pdhStatus = PdhParseCounterPath(
  664. szCounterPath,
  665. pLocalCounter,
  666. &ulBufSize,
  667. 0 );
  668. if ( 0 < ulBufSize ) {
  669. pLocalCounter = (PPDH_COUNTER_PATH_ELEMENTS) G_ALLOC( ulBufSize);
  670. ZeroMemory ( pLocalCounter, ulBufSize );
  671. if ( NULL != pLocalCounter ) {
  672. dwStatus = pdhStatus = PdhParseCounterPath(
  673. szCounterPath,
  674. pLocalCounter,
  675. &ulBufSize,
  676. 0);
  677. if ( ERROR_SUCCESS != pdhStatus ) {
  678. delete pLocalCounter;
  679. pLocalCounter = NULL;
  680. }
  681. } else {
  682. dwStatus = ERROR_OUTOFMEMORY;
  683. }
  684. }
  685. if ( ERROR_SUCCESS == dwStatus && NULL != pLocalCounter ) {
  686. *ppCounter = pLocalCounter;
  687. }
  688. } else {
  689. dwStatus = ERROR_INVALID_PARAMETER;
  690. ASSERT ( FALSE );
  691. }
  692. return dwStatus;
  693. }
  694. BOOL
  695. CSmPropertyPage::ConnectRemoteWbemFail(CSmLogQuery* pQuery, BOOL bNotTouchRunAs)
  696. /*++
  697. Routine Description:
  698. The function display an error message telling users they can not
  699. modify the RunAs information.
  700. Arguments:
  701. pQuery - Query structure
  702. bNotTouchRunAs - Don't check/restore RunAs after displaying dialog
  703. Return Value:
  704. Return TRUE if the RunAs need to be restored to its original one,
  705. otherwise return FALSE
  706. --*/
  707. {
  708. CString strMessage;
  709. CString strSysMessage;
  710. IWbemStatusCodeText * pStatus = NULL;
  711. HRESULT hr;
  712. //
  713. // If bNotTouchRunAs is TRUE, don't try to restore the RunAs info.
  714. //
  715. if (!bNotTouchRunAs) {
  716. if (m_strUserDisplay == m_strUserSaved) {
  717. return FALSE;
  718. }
  719. }
  720. FormatSmLogCfgMessage (
  721. strMessage,
  722. m_hModule,
  723. SMCFG_SYSTEM_MESSAGE,
  724. (LPCWSTR)pQuery->GetLogName());
  725. hr = CoCreateInstance(CLSID_WbemStatusCodeText,
  726. 0,
  727. CLSCTX_INPROC_SERVER,
  728. IID_IWbemStatusCodeText,
  729. (LPVOID *) &pStatus);
  730. if (hr == S_OK) {
  731. BSTR bstr = 0;
  732. hr = pStatus->GetErrorCodeText(pQuery->GetLogService()->m_hWbemAccessStatus, 0, 0, &bstr);
  733. if (hr == S_OK){
  734. strSysMessage = bstr;
  735. SysFreeString(bstr);
  736. bstr = 0;
  737. }
  738. pStatus->Release();
  739. }
  740. if ( strSysMessage.IsEmpty() ) {
  741. strSysMessage.Format ( L"0x%08lX", pQuery->GetLogService()->m_hWbemAccessStatus);
  742. }
  743. strMessage += strSysMessage;
  744. MessageBox( strMessage, pQuery->GetLogName(), MB_OK );
  745. return TRUE;
  746. }
  747. CWnd* CSmPropertyPage::GetRunAsWindow()
  748. {
  749. CWnd* pWnd;
  750. CWnd* pRunAs;
  751. pWnd = GetDlgItem(IDC_RUNAS_EDIT);
  752. if (pWnd) {
  753. pRunAs = pWnd->GetNextWindow(GW_HWNDPREV);
  754. return pRunAs;
  755. }
  756. return NULL;
  757. }